summaryrefslogtreecommitdiff
path: root/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mv_barcode/barcode_generator/src/BarcodeGenerator.cpp')
-rw-r--r--mv_barcode/barcode_generator/src/BarcodeGenerator.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
index 9b1e757a..28fd094d 100644
--- a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
+++ b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
@@ -149,8 +149,8 @@ int createBarcode(const std::string &message, BarcodeType type, BarcodeQREncodin
return error;
}
-int writeBufferToImageFile(zint_symbol *symbol, const std::string &imageFileName, BarcodeImageFormat imageFormat,
- const int imageWidth, const int imageHeight)
+static int __write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, BarcodeImageFormat imageFormat,
+ const int imageWidth, const int imageHeight, const std::string &logoPath)
{
if (imageWidth <= 0 || imageHeight <= 0) {
LOGE("Barcode image size is invalid: %i x %i. Terminate write to "
@@ -204,6 +204,12 @@ int writeBufferToImageFile(zint_symbol *symbol, const std::string &imageFileName
cv::Mat image(symbol->bitmap_height, symbol->bitmap_width, CV_8UC3, symbol->bitmap);
cv::resize(image, image, cv::Size(imageWidth, imageHeight), 0, 0, cv::INTER_AREA);
+ if (!logoPath.empty()) {
+ cv::Mat logo = cv::imread(logoPath.c_str(), cv::IMREAD_COLOR);
+ cv::resize(logo, logo, cv::Size(imageWidth / 5, imageHeight / 5), 0, 0, cv::INTER_AREA);
+ logo.copyTo(image(cv::Rect(2 * logo.cols, 2 * logo.rows, logo.cols, logo.rows)));
+ }
+
error = cv::imwrite(resultFilePath, image, compressionParams) ? BARCODE_ERROR_NONE : BARCODE_ERROR_INVALID_DATA;
if (BARCODE_ERROR_NONE != error) {
@@ -230,23 +236,31 @@ int BarcodeGenerator::generateBarcodeToImage(const std::string &imageFileName, B
return BARCODE_ERROR_ENCODING_PROBLEM;
}
+ std::string logoPath;
int error = createBarcode(message, type, encodingMode, correctionLevel, qrVersion, showText, fgcolour, bgcolour,
symbol, engineCfg);
if (error != BARCODE_ERROR_NONE) {
LOGE("Barcode creation failed, clean memory");
- ZBarcode_Delete(symbol);
- return error;
+ goto zbarcode_delete;
}
- error = writeBufferToImageFile(symbol, imageFileName, imageFormat, imageWidth, imageHeight);
+ if (engineCfg) {
+ error = engineCfg->getStringAttribute(std::string(MV_BARCODE_GENERATE_ATTR_EMBED_IMG_PATH), &logoPath);
+ if (error != BARCODE_ERROR_NONE) {
+ LOGE("getStringAttribute failed error : %d", error);
+ goto zbarcode_delete;
+ }
+ }
+
+ error = __write_buffer_to_img(symbol, imageFileName, imageFormat, imageWidth, imageHeight, logoPath);
if (error != BARCODE_ERROR_NONE)
LOGE("Barcode [%s] file write fail, clean memory", imageFileName.c_str());
else
LOGI("Barcode image [%s] is successfully generated, clean memory", imageFileName.c_str());
+zbarcode_delete:
ZBarcode_Delete(symbol);
-
return error;
}