Support logo in mv_barcode_generate_source 88/315088/3
authorKwanghoon Son <k.son@samsung.com>
Thu, 25 Jul 2024 00:23:26 +0000 (09:23 +0900)
committerKwanghoon Son <k.son@samsung.com>
Fri, 26 Jul 2024 08:04:26 +0000 (17:04 +0900)
The reason why the logo was not used in mv_barcode_generate_source before is
that the logo does not look normal if the buffer size is too small.
However in the case of design QR, the buffer size is increased (x16),
so the logo quality will not be a problem.

Change-Id: Idfff0a049e5c5fbaeb7eaed018f06f2a15f87619
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_barcode/barcode_generator/src/BarcodeGenerator.cpp

index 0512ad42d784d6c4c78d7142489b0d7bd1226825..22d1a3a7ba7a8d2e611cb8774058f80e2587e513 100644 (file)
@@ -289,12 +289,15 @@ cv::Scalar convert_to_scalar(const std::string &bgr)
        return cv::Scalar((color_decimal >> 16) & 0xff, (color_decimal >> 8) & 0xff, color_decimal & 0xff);
 }
 
-/*
- * Use only for mv_barcode_generate_image because,
- * QR code size is maximum 177x177, then logo will be (35x35).
- * mv_barcode_generate_image support user-defined resize, so user can set size detail.
- */
-static void __draw_logo(cv::Mat &image, const BarcodeConfig &config)
+static cv::Size makeEven(cv::Size orgSize)
+{
+       cv::Size size(orgSize);
+       size.width += size.width & 1;
+       size.height += size.height & 1;
+       return size;
+}
+
+static void drawLogo(cv::Mat &image, const BarcodeConfig &config)
 {
        if (config.logo_path.empty() || config.type != MV_BARCODE_QR)
                return;
@@ -304,8 +307,8 @@ static void __draw_logo(cv::Mat &image, const BarcodeConfig &config)
        auto color_frame = convert_to_scalar(config.bgcolor);
        auto color_white = cv::Scalar(255, 255, 255);
 
-       auto logoSize = image.size() / 5;
-       auto logoFrameSize = logoSize + logoSize / 10;
+       auto logoSize = makeEven(image.size() / 5);
+       auto logoFrameSize = makeEven(logoSize + logoSize / 10);
 
        cv::resize(logo, logo, logoSize);
        cv::Mat maskMat = cv::Mat::zeros(image.size(), image.type());
@@ -381,8 +384,6 @@ static int write_buffer_to_img(const cv::Mat &buf, const BarcodeConfig &config)
 
        cv::Mat image;
        cv::resize(buf, image, cv::Size(config.image_width, config.image_height), 0, 0, cv::INTER_AREA);
-       __draw_logo(image, config);
-
        error = cv::imwrite(resultFilePath, image, compressionParams) ? BARCODE_ERROR_NONE : BARCODE_ERROR_INVALID_DATA;
 
        if (BARCODE_ERROR_NONE != error) {
@@ -619,6 +620,8 @@ static int symbol_to_buf(zint_symbol *symbol, const BarcodeConfig &config, cv::M
        try {
                drawDesignQR(buf, config);
                changeColor(buf, config);
+               drawLogo(buf, config);
+
        } catch (const std::exception &e) {
                LOGE("Exception: %s", e.what());
                return MEDIA_VISION_ERROR_INTERNAL;