Add Design QR header and test 45/289445/4
authorKwanghoon Son <k.son@samsung.com>
Thu, 2 Feb 2023 07:09:36 +0000 (16:09 +0900)
committerKwanghoon Son <k.son@samsung.com>
Thu, 9 Mar 2023 01:55:57 +0000 (10:55 +0900)
Design QR is for supporting various shape of finder and anchor pattern.
This patch includes
1. MV_BARCODE_GENERATE_ATTR_{DATA,FINDER}_SHAPE
2. header value of mv_barcode_generate_attr_shape_e
3. chain engineCfg parameter to createBarcode function because so many
parameters will increase without engineCfg

Change-Id: Ib931c15e97bbb8439f564fb1826bfa9ca38ebc8e
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
(cherry picked from commit c6656f06ce4315dc1eaffc4e57191bdde15bd234)

include/mv_barcode_generate.h
media-vision-config.json
mv_barcode/barcode_generator/include/BarcodeGenerator.h
mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp
test/testsuites/barcode/test_barcode.cpp

index 0654fdc..42e52f0 100644 (file)
@@ -67,6 +67,39 @@ extern "C" {
 #define MV_BARCODE_GENERATE_ATTR_COLOR_BACK "MV_BARCODE_GENERATE_ATTR_COLOR_BACK"
 
 /**
+ * @brief Defines MV_BARCODE_GENERATE_ATTR_DATA_SHAPE to set
+                 Barcode's data shape attribute of the engine configuration.
+ *
+ * @since_tizen 7.5
+ * @see mv_barcode_generate_attr_shape_e
+ */
+#define MV_BARCODE_GENERATE_ATTR_DATA_SHAPE "MV_BARCODE_GENERATE_ATTR_DATA_SHAPE"
+
+/**
+ * @brief Defines MV_BARCODE_GENERATE_ATTR_FINDER_SHAPE to set
+                 Barcode's finder shape attribute of the engine configuration.
+ *
+ * @since_tizen 7.5
+ * @see mv_barcode_generate_attr_shape_e
+ */
+#define MV_BARCODE_GENERATE_ATTR_FINDER_SHAPE "MV_BARCODE_GENERATE_ATTR_FINDER_SHAPE"
+
+/**
+ * @brief Enumeration to shape attribute.
+ * @details Using this enumeration, various data or finder patterns can be set in
+ * mv_engine_config_set_int_attribute. If the pattern is not supported, it will
+ * be simply ignored.
+ *
+ * @see mv_engine_config_set_int_attribute
+ * @since_tizen 7.5
+ */
+typedef enum {
+       MV_BARCODE_GENERATE_ATTR_SHAPE_RECT, /**< Rectangular */
+       MV_BARCODE_GENERATE_ATTR_SHAPE_ROUND_RECT, /**< Round rectangular */
+       MV_BARCODE_GENERATE_ATTR_SHAPE_CIRCLE, /**< Circle */
+} mv_barcode_generate_attr_shape_e;
+
+/**
  * @brief Enumeration to text attribute.
  *
  * @since_tizen @if MOBILE 2.4 @else 3.0 @endif
index abd55a3..1ae22ad 100644 (file)
             "name" : "MV_3D_POINTCLOUD_OUTPUT_FILE_PATH",
             "type"  : "string",
             "value" : "/opt/usr/home/owner/media/Images"
+        },
+        {
+            "name" : "MV_BARCODE_GENERATE_ATTR_DATA_SHAPE",
+            "type"  : "integer",
+            "value" : 0
         }
     ]
 }
index 9f7075d..6a3d413 100644 (file)
@@ -20,7 +20,7 @@
 #include "BarcodeOptions.h"
 
 #include <string>
-
+#include <EngineConfig.h>
 /**
  * @file BarcodeGenerator.h
  * @brief This file contains the BarcodeGenerator class.
@@ -60,7 +60,7 @@ public:
         */
        static int generateBarcodeToImage(const std::string &imageFileName, BarcodeImageFormat imageFormat,
                                                                          const int imageWidth, const int imageHeight, const std::string &message,
-                                                                         BarcodeType type,
+                                                                         BarcodeType type, Common::EngineConfig *engineCfg,
                                                                          BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
                                                                          BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
                                                                          int qrVersion = 0, int showText = 0, char *fgcolour = NULL, char *bgcolur = NULL);
@@ -86,6 +86,7 @@ public:
         */
        static int generateBarcodeToBuffer(unsigned char **imageBuffer, unsigned int *imageWidth, unsigned int *imageHeight,
                                                                           unsigned int *imageChannels, const std::string &message, BarcodeType type,
+                                                                          Common::EngineConfig *engineCfg,
                                                                           BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
                                                                           BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
                                                                           int qrVersion = 0, int showText = 0, char *fgcolour = NULL,
index 9798da0..92d2353 100644 (file)
@@ -28,6 +28,7 @@
 #include <cstring>
 #include <vector>
 #include <unistd.h>
+#include <mv_barcode_generate.h>
 
 #define ZINT_COLOUR_SIZE 10
 
@@ -68,7 +69,7 @@ int getFormatEncodingInfo(BarcodeImageFormat imageFormat, std::vector<std::strin
 
 int createBarcode(const std::string &message, BarcodeType type, BarcodeQREncodingMode encodingMode,
                                  BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText, char *fgcolour,
-                                 char *bgcolour, zint_symbol *symbol)
+                                 char *bgcolour, zint_symbol *symbol, Common::EngineConfig *engineCfg)
 {
        /* set input values */
        symbol->symbology = type;
@@ -102,6 +103,22 @@ int createBarcode(const std::string &message, BarcodeType type, BarcodeQREncodin
        symbol->border_width = 1;
        symbol->height = 50;
 
+       if (engineCfg) {
+               int value;
+               int ret = engineCfg->getIntegerAttribute(MV_BARCODE_GENERATE_ATTR_DATA_SHAPE, &value);
+
+               if (ret == MEDIA_VISION_ERROR_NONE) {
+                       switch (value) {
+                       case MV_BARCODE_GENERATE_ATTR_SHAPE_CIRCLE:
+                               symbol->output_options |= BARCODE_DATA_CIRCLE;
+                               break;
+
+                       default:
+                               break;
+                       }
+               }
+       }
+
        if (type == BARCODE_QR) {
                symbol->whitespace_width = 0;
        } else {
@@ -185,7 +202,8 @@ int writeBufferToImageFile(zint_symbol *symbol, const std::string &imageFileName
 
 int BarcodeGenerator::generateBarcodeToImage(const std::string &imageFileName, BarcodeImageFormat imageFormat,
                                                                                         const int imageWidth, const int imageHeight, const std::string &message,
-                                                                                        BarcodeType type, BarcodeQREncodingMode encodingMode,
+                                                                                        BarcodeType type, Common::EngineConfig *engineCfg,
+                                                                                        BarcodeQREncodingMode encodingMode,
                                                                                         BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText,
                                                                                         char *fgcolour, char *bgcolour)
 {
@@ -197,7 +215,7 @@ int BarcodeGenerator::generateBarcodeToImage(const std::string &imageFileName, B
        }
 
        int error = createBarcode(message, type, encodingMode, correctionLevel, qrVersion, showText, fgcolour, bgcolour,
-                                                         symbol);
+                                                         symbol, engineCfg);
 
        if (error != BARCODE_ERROR_NONE) {
                LOGE("Barcode creation failed, clean memory");
@@ -219,7 +237,7 @@ int BarcodeGenerator::generateBarcodeToImage(const std::string &imageFileName, B
 int BarcodeGenerator::generateBarcodeToBuffer(unsigned char **imageBuffer, unsigned int *imageWidth,
                                                                                          unsigned int *imageHeight, unsigned int *imageChannels,
                                                                                          const std::string &message, BarcodeType type,
-                                                                                         BarcodeQREncodingMode encodingMode,
+                                                                                         Common::EngineConfig *engineCfg, BarcodeQREncodingMode encodingMode,
                                                                                          BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion,
                                                                                          int showText, char *fgcolour, char *bgcolour)
 {
@@ -232,7 +250,7 @@ int BarcodeGenerator::generateBarcodeToBuffer(unsigned char **imageBuffer, unsig
        }
 
        int error = createBarcode(message, type, encodingMode, correctionLevel, qrVersion, showText, fgcolour, bgcolour,
-                                                         symbol);
+                                                         symbol, engineCfg);
 
        if (error != BARCODE_ERROR_NONE) {
                LOGE("Barcode creation failed, clean memory");
index d7e77c5..abf0177 100644 (file)
@@ -304,6 +304,8 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *m
        char *fgcolour = NULL;
        char *bgcolour = NULL;
 
+       auto engineCfg = static_cast<MediaVision::Common::EngineConfig *>(engine_cfg);
+
        error = getColorFromEngine(engine_cfg, type, showText, &fgcolour, &bgcolour);
        if (error != MEDIA_VISION_ERROR_NONE) {
                LOGE("getColorFromEngine failed");
@@ -316,7 +318,7 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *m
        unsigned int imageChannels = 0u;
 
        error = BarcodeGenerator::generateBarcodeToBuffer(&imageBuffer, &imageWidth, &imageHeight, &imageChannels,
-                                                                                                         messageStr, convertBarcodeType(type),
+                                                                                                         messageStr, convertBarcodeType(type), engineCfg,
                                                                                                          convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version,
                                                                                                          showText, fgcolour, bgcolour);
 
@@ -367,6 +369,8 @@ int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *me
        char *fgcolour = NULL;
        char *bgcolour = NULL;
 
+       auto engineCfg = static_cast<MediaVision::Common::EngineConfig *>(engine_cfg);
+
        error = getColorFromEngine(engine_cfg, type, showText, &fgcolour, &bgcolour);
        if (error != MEDIA_VISION_ERROR_NONE) {
                LOGE("getColorFromEngine failed");
@@ -375,8 +379,8 @@ int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *me
 
        error = BarcodeGenerator::generateBarcodeToImage(std::string(image_path), convertImageFormat(image_format),
                                                                                                         image_width, image_height, messageStr, convertBarcodeType(type),
-                                                                                                        convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version,
-                                                                                                        showText, fgcolour, bgcolour);
+                                                                                                        engineCfg, convertEncodingMode(qr_enc_mode), convertECC(qr_ecc),
+                                                                                                        qr_version, showText, fgcolour, bgcolour);
 
        free(fgcolour);
        free(bgcolour);
index 92b0bc1..beaf2eb 100644 (file)
@@ -145,3 +145,17 @@ TEST_F(TestBarcodeGen, ColorPositiveQR)
                          MEDIA_VISION_ERROR_NONE);
        ASSERT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE);
 }
+
+TEST_F(TestBarcodeGen, DataCirclePositiveQR)
+{
+       ASSERT_EQ(mv_create_engine_config(&engine_cfg), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_string_attribute(engine_cfg, MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, "3366ff"),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_BARCODE_GENERATE_ATTR_DATA_SHAPE,
+                                                                                                MV_BARCODE_GENERATE_ATTR_SHAPE_CIRCLE),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_barcode_generate_image(engine_cfg, "https://samsung.com/", 512, 512, type, qr_enc_mode, qr_ecc,
+                                                                               qr_version, test_file.c_str(), image_format),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE);
+}
\ No newline at end of file