Fix log condition
authorKwanghoon Son <k.son@samsung.com>
Mon, 15 Jul 2024 05:22:00 +0000 (14:22 +0900)
committerKwanghoon Son <k.son@samsung.com>
Fri, 26 Jul 2024 03:49:18 +0000 (12:49 +0900)
- fix wrong log print
- refactoring for convert

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

index 9a3d1f3e1ed20c4bfbbaf78b8ac2679313a0ca01..c4710f53300cc4cfe2a0209e4f0bab6f3a13b78a 100644 (file)
@@ -287,7 +287,7 @@ static int mv_barcode_generate_symbol(zint_symbol *symbol, const BarcodeConfig &
 {
        int error = createBarcode(symbol, config);
 
-       if (error != BARCODE_ERROR_NONE) {
+       if (error == BARCODE_ERROR_NONE) {
                const auto channel = 3;
                LOGI("Barcode has been generated to the buffer: Buffer size = %ui x %ui; Channels = %ui; Message = %s",
                         symbol->bitmap_width, symbol->bitmap_height, channel, config.message.c_str());
@@ -307,6 +307,12 @@ static void __round_rect(cv::Mat &inOutImg, cv::Rect &rect, cv::Scalar &color)
        cv::circle(inOutImg, cv::Point(rect.x + 3 * gapW, rect.y + 3 * gapH), gapW, color, -1);
 }
 
+cv::Scalar convert_to_scalar(const std::string &bgr)
+{
+       int color_decimal = strtol(bgr.c_str(), nullptr, 16);
+       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).
@@ -319,14 +325,7 @@ static void __draw_logo(cv::Mat &image, const BarcodeConfig &config)
 
        auto logo = cv::imread(config.logo_path.c_str(), cv::IMREAD_COLOR);
 
-       int color_decimal = strtol(config.bgcolor.c_str(), nullptr, 16);
-       int R = color_decimal % 256;
-       color_decimal /= 256;
-       int G = color_decimal % 256;
-       color_decimal /= 256;
-       int B = color_decimal;
-
-       auto color_frame = cv::Scalar(B, G, R);
+       auto color_frame = convert_to_scalar(config.bgcolor);
        auto color_white = cv::Scalar(255, 255, 255);
 
        auto logoSize = image.size() / 5;