diff options
author | Kwanghoon Son <k.son@samsung.com> | 2023-02-16 18:27:08 +0900 |
---|---|---|
committer | Kwanghoon Son <k.son@samsung.com> | 2023-03-03 17:11:58 +0900 |
commit | 492d1c848745d00bd959597089d5338791bb1387 (patch) | |
tree | ed023f4a8b16ca6f8d6ba3266eb0d17b50a3ac80 /mv_barcode | |
parent | db200c8ee9a8e82ae513bfb38b838181aaa8aa61 (diff) | |
download | mediavision-492d1c848745d00bd959597089d5338791bb1387.tar.gz mediavision-492d1c848745d00bd959597089d5338791bb1387.tar.bz2 mediavision-492d1c848745d00bd959597089d5338791bb1387.zip |
Add DesignQR embed logo image
QRcode generate MV_BARCODE_GENERATE_ATTR_EMBED_IMG_PATH and it's size
will be 1/5 of output image. This will 4% of total image size so ok with
qrcode ecc recovery.
Change-Id: I9bf902cada3d7a03d7dff424b676bb7344968b2a
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
Diffstat (limited to 'mv_barcode')
-rw-r--r-- | mv_barcode/barcode_generator/src/BarcodeGenerator.cpp | 26 |
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; } |