From d1e0940087db9cf006aa9ce7a3c6e47a02c048cb Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 6 Apr 2016 17:33:08 +0900 Subject: Add new definitions for coloring barcodes Change-Id: Ie25ef74b097c5cdcf291f28de9e92321ffc6a808 Signed-off-by: Tae-Young Chung --- include/mv_barcode_generate.h | 18 +++ media-vision-config.json | 10 ++ .../barcode_generator/include/BarcodeGenerator.h | 12 +- .../barcode_generator/src/BarcodeGenerator.cpp | 36 ++++- .../src/mv_barcode_generate_open.cpp | 150 +++++++++++++++++++-- packaging/capi-media-vision.spec | 2 +- test/testsuites/barcode/barcode_test_suite.c | 125 ++++++++++++++++- 7 files changed, 330 insertions(+), 23 deletions(-) diff --git a/include/mv_barcode_generate.h b/include/mv_barcode_generate.h index 134c824b..bb078fff 100644 --- a/include/mv_barcode_generate.h +++ b/include/mv_barcode_generate.h @@ -47,6 +47,24 @@ extern "C" { 0-invisible, 1-visible */ +/** + * @brief Defines MV_BARCODE_GENERATE_ATTR_COLOR_FRONT to set + Barcode's foreground color attribute of the engine configuration. + * + * @since_tizen 3.0 + * @remarks This attribute represents RGB color as a hex triplet with six digits. + */ +#define MV_BARCODE_GENERATE_ATTR_COLOR_FRONT "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT" + +/** + * @brief Defines MV_BARCODE_GENERATE_ATTR_COLOR_BACK to set + Barcode's background color attribute of the engine configuration. + * + * @since_tizen 3.0 + * @remarks This attribute represents RGB color as a hex triplet with six digits. + */ +#define MV_BARCODE_GENERATE_ATTR_COLOR_BACK "MV_BARCODE_GENERATE_ATTR_COLOR_BACK" + /** * @brief Enumeration to text attribute * diff --git a/media-vision-config.json b/media-vision-config.json index 2830a121..8a97a64e 100644 --- a/media-vision-config.json +++ b/media-vision-config.json @@ -41,6 +41,16 @@ "type" : "integer", "value" : 0 }, + { + "name" : "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", + "type" : "string", + "value" : "000000" + }, + { + "name" : "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", + "type" : "string", + "value" : "ffffff" + }, { "name" : "MV_BARCODE_DETECT_ATTR_TARGET", "type" : "integer", diff --git a/mv_barcode/barcode_generator/include/BarcodeGenerator.h b/mv_barcode/barcode_generator/include/BarcodeGenerator.h index 7e135325..1625dd66 100644 --- a/mv_barcode/barcode_generator/include/BarcodeGenerator.h +++ b/mv_barcode/barcode_generator/include/BarcodeGenerator.h @@ -50,6 +50,8 @@ public: * @param [in] correctionLevel Error correction level (for QR codes only) * @param [in] qrVersion QR code version (1 ~ 40, 0 for 1D barcodes) * @param [in] showText Show text or not + * @param [in] fgcolour Foreground colour of barcode + * @param [in] bgcolour Background colour of barcode * @return BARCODE_ERROR_NONE from BarcodeError which is 0 if success, * BarcodeError value otherwise */ @@ -63,7 +65,9 @@ public: BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE, BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE, int qrVersion = 0, - int showText = 0); + int showText = 0, + char *fgcolour = NULL, + char *bgcolur = NULL); /** * @brief This method generates Barcodes image buffer according to options. @@ -79,6 +83,8 @@ public: * @param [in] correctionLevel Error correction level (for QR codes only) * @param [in] qrVersion QR code version (1 ~ 40, 0 for 1D barcodes) * @param [in] showText Show text or not + * @param [in] fgcolour Foreground colour of barcode + * @param [in] bgcolour Background colour of barcode * @return BARCODE_ERROR_NONE from BarcodeError which is 0 if success, * BarcodeError value otherwise */ @@ -92,7 +98,9 @@ public: BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE, BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE, int qrVersion = 0, - int showText = 0); + int showText = 0, + char *fgcolour = NULL, + char *bgcolur = NULL); }; } /* Barcode */ diff --git a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp index 522f65f0..09d33a35 100644 --- a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp +++ b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp @@ -70,6 +70,8 @@ int createBarcode( BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText, + char *fgcolour, + char *bgcolour, zint_symbol *symbol) { /* set input values */ @@ -81,8 +83,26 @@ int createBarcode( symbol->show_hrt = showText; /* set default values */ - std::strncpy(symbol->fgcolour, "000000", 10); - std::strncpy(symbol->bgcolour, "ffffff", 10); + if (fgcolour) { + std::strncpy(symbol->fgcolour, fgcolour, 10); + if (strlen(fgcolour) > 9) { + symbol->fgcolour[9] = '\0'; + } + } else { + std::strncpy(symbol->fgcolour, "000000", 10); + } + + if (bgcolour) { + std::strncpy(symbol->bgcolour, bgcolour, 10); + if (strlen(fgcolour) > 9) { + symbol->fgcolour[9] = '\0'; + } + } else { + std::strncpy(symbol->bgcolour, "ffffff", 10); + } + + LOGI("Check colors: front %s, back %s", symbol->fgcolour, symbol->bgcolour); + symbol->border_width = 1; symbol->height = 50; @@ -190,7 +210,9 @@ int BarcodeGenerator::generateBarcodeToImage( BarcodeQREncodingMode encodingMode, BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, - int showText) + int showText, + char *fgcolour, + char *bgcolour) { zint_symbol *symbol = ZBarcode_Create(); @@ -206,6 +228,8 @@ int BarcodeGenerator::generateBarcodeToImage( correctionLevel, qrVersion, showText, + fgcolour, + bgcolour, symbol); if (error != BARCODE_ERROR_NONE) { @@ -241,7 +265,9 @@ int BarcodeGenerator::generateBarcodeToBuffer( BarcodeQREncodingMode encodingMode, BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, - int showText) + int showText, + char *fgcolour, + char *bgcolour) { zint_symbol *symbol = ZBarcode_Create(); @@ -258,6 +284,8 @@ int BarcodeGenerator::generateBarcodeToBuffer( correctionLevel, qrVersion, showText, + fgcolour, + bgcolour, symbol); if (error != BARCODE_ERROR_NONE) { diff --git a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp index 444ceb3a..558300bd 100644 --- a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp +++ b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp @@ -221,17 +221,71 @@ int mv_barcode_generate_source_open( unsigned int imageChannels = 0u; int showText = 0; - error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); - if (error != MEDIA_VISION_ERROR_NONE) { - LOGW("mv_engine_config_get_int_attribute failed"); - return error; - } + char value; + char *fgcolour = NULL; + char *bgcolour = NULL; + + if (engine_cfg != NULL) { + error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); + if (error != MEDIA_VISION_ERROR_NONE) { + LOGW("mv_engine_config_get_int_attribute failed"); + return error; + } + + if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) { + LOGW("QR code generation with visible text is not supported"); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + /* set color value */ + error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", &fgcolour); + if (error != MEDIA_VISION_ERROR_NONE) { + if (fgcolour) { + delete [] fgcolour; + fgcolour = NULL; + } - if (showText == BARCODE_GEN_TEXT_VISIBLE && type == MV_BARCODE_QR) { - LOGW("QR code generation with visible text is not supported"); - return MEDIA_VISION_ERROR_INVALID_OPERATION; + LOGW("mv_engine_config_get_string_attribute failed"); + return error; + } + + error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", &bgcolour); + if (error != MEDIA_VISION_ERROR_NONE) { + if (bgcolour) { + delete [] bgcolour; + bgcolour = NULL; + } + + if (fgcolour) { + delete [] fgcolour; + fgcolour = NULL; + } + + LOGW("mv_engine_config_get_string_attribute failed"); + return error; + } } + /* + The input colorspace is RGB but the generators' is BGR. + Replace the value of R with that of B + */ + value = fgcolour[0]; + fgcolour[0] = fgcolour[4]; + fgcolour[4] = value; + + value = fgcolour[1]; + fgcolour[1] = fgcolour[5]; + fgcolour[5] = value; + + value = bgcolour[0]; + bgcolour[0] = bgcolour[4]; + bgcolour[4] = value; + + value = bgcolour[1]; + bgcolour[1] = bgcolour[5]; + bgcolour[5] = value; + error = BarcodeGenerator::generateBarcodeToBuffer( &imageBuffer, &imageWidth, @@ -242,7 +296,19 @@ int mv_barcode_generate_source_open( convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version, - showText); + showText, + fgcolour, + bgcolour); + + if (fgcolour != NULL) { + delete [] fgcolour; + fgcolour = NULL; + } + + if (bgcolour != NULL) { + delete [] bgcolour; + bgcolour = NULL; + } if (error != BARCODE_ERROR_NONE) { LOGE("Barcode generation to the buffer failed"); @@ -316,8 +382,12 @@ int mv_barcode_generate_image_open( } int showText = 0; + char value; + char *fgcolour = NULL; + char *bgcolour = NULL; if (engine_cfg != NULL) { + /* set visible text attribute */ error = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_TEXT", &showText); if (error != MEDIA_VISION_ERROR_NONE) { LOGW("mv_engine_config_get_int_attribute failed"); @@ -328,8 +398,56 @@ int mv_barcode_generate_image_open( LOGW("QR code generation with visible text is not supported"); return MEDIA_VISION_ERROR_INVALID_OPERATION; } + + /* set color value */ + error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", &fgcolour); + if (error != MEDIA_VISION_ERROR_NONE) { + if (fgcolour) { + delete [] fgcolour; + fgcolour = NULL; + } + + LOGW("mv_engine_config_get_string_attribute failed"); + return error; + } + + error = mv_engine_config_get_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", &bgcolour); + if (error != MEDIA_VISION_ERROR_NONE) { + if (bgcolour) { + delete [] bgcolour; + bgcolour = NULL; + } + + if (fgcolour) { + delete [] fgcolour; + fgcolour = NULL; + } + + LOGW("mv_engine_config_get_string_attribute failed"); + return error; + } } + /* + The input colorspace is RGB but the generators' is BGR. + Replace the value of R with that of B + */ + value = fgcolour[0]; + fgcolour[0] = fgcolour[4]; + fgcolour[4] = value; + + value = fgcolour[1]; + fgcolour[1] = fgcolour[5]; + fgcolour[5] = value; + + value = bgcolour[0]; + bgcolour[0] = bgcolour[4]; + bgcolour[4] = value; + + value = bgcolour[1]; + bgcolour[1] = bgcolour[5]; + bgcolour[5] = value; + error = BarcodeGenerator::generateBarcodeToImage( std::string(image_path), convertImageFormat(image_format), @@ -340,7 +458,19 @@ int mv_barcode_generate_image_open( convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version, - showText); + showText, + fgcolour, + bgcolour); + + if (fgcolour != NULL) { + delete [] fgcolour; + fgcolour = NULL; + } + + if (bgcolour != NULL) { + delete [] bgcolour; + bgcolour = NULL; + } if (error != BARCODE_ERROR_NONE) { LOGE("Barcode generation to the image file failed"); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index dab5a125..b659303c 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,6 +1,6 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.3.12 +Version: 0.3.13 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-2.0 diff --git a/test/testsuites/barcode/barcode_test_suite.c b/test/testsuites/barcode/barcode_test_suite.c index 13048062..9dacb103 100644 --- a/test/testsuites/barcode/barcode_test_suite.c +++ b/test/testsuites/barcode/barcode_test_suite.c @@ -32,6 +32,7 @@ typedef struct { mv_barcode_type_e type; mv_barcode_qr_ecc_e ecc; mv_barcode_qr_mode_e mode; + int is_hrt; int version; size_t width; size_t height; @@ -41,6 +42,8 @@ typedef struct { char *file_name; char *out_file_name; unsigned char *out_buffer_ptr; + char *front_color; + char *back_color; } barcode_model_s; typedef enum { @@ -400,13 +403,49 @@ int generate_barcode_to_image(barcode_model_s model) if (model.message == NULL || model.file_name == NULL) { MEDIA_VISION_FUNCTION_LEAVE(); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; } LOGI("Call the mv_barcode_generate_image() function"); - const int err = mv_barcode_generate_image( - NULL, + mv_engine_config_h mv_engine_config; + int err = mv_create_engine_config(&mv_engine_config); + + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during creating the media engine " + "config: %i\n", err); + MEDIA_VISION_FUNCTION_LEAVE(); + + return err; + } + + err = mv_engine_config_set_int_attribute(mv_engine_config, + MV_BARCODE_GENERATE_ATTR_TEXT, + model.is_hrt); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occured during set integer attribute to " + "media engine config: %i\n", err); + } + + err = mv_engine_config_set_string_attribute(mv_engine_config, + MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, + model.front_color); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occured during set string attribute to " + "media engine config: %i\n", err); + } + + err = mv_engine_config_set_string_attribute(mv_engine_config, + MV_BARCODE_GENERATE_ATTR_COLOR_BACK, + model.back_color); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occured during set string attribute to " + "media engine config: %i\n", err); + } + + err = mv_barcode_generate_image( + mv_engine_config, model.message, model.width, model.height, @@ -419,6 +458,12 @@ int generate_barcode_to_image(barcode_model_s model) MEDIA_VISION_FUNCTION_LEAVE(); + int err2 = mv_destroy_engine_config(mv_engine_config); + if (MEDIA_VISION_ERROR_NONE != err2) { + printf("ERROR: Errors were occurred during destroying the media engine " + "config: %i\n", err2); + } + return err; } @@ -441,9 +486,9 @@ int generate_barcode_to_source(barcode_model_s model) printf("ERROR: Error occurred when trying to create Media Vision " "source. Error code: %i\n", err); - MEDIA_VISION_FUNCTION_LEAVE(); + MEDIA_VISION_FUNCTION_LEAVE(); - return err; + return err; } LOGI("mv_source_h creation finished"); @@ -457,6 +502,22 @@ int generate_barcode_to_source(barcode_model_s model) "config: %i\n", err); } + err = mv_engine_config_set_string_attribute(mv_engine_config, + MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, + model.front_color); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occured during set string attribute to " + "media engine config: %i\n", err); + } + + err = mv_engine_config_set_string_attribute(mv_engine_config, + MV_BARCODE_GENERATE_ATTR_COLOR_BACK, + model.back_color); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occured during set string attribute to " + "media engine config: %i\n", err); + } + err = mv_barcode_generate_source( mv_engine_config, model.message, @@ -912,6 +973,35 @@ mv_barcode_qr_ecc_e select_ecc(void) return selected_ecc; } +int select_attribute_text(void) +{ + MEDIA_VISION_FUNCTION_ENTER(); + + int sel_opt = 0; + int selected_attr = 0; + const int options[2] = { 1, 2 }; + const char *names[2] = { "Invisible", "Visible" }; + + while (sel_opt == 0) { + sel_opt = show_menu("Select attribute text", options, names, 2); + switch (sel_opt) { + case 1: + selected_attr = 0; + break; + case 2: + selected_attr = 1; + break; + default: + sel_opt = 0; + break; + } + } + + MEDIA_VISION_FUNCTION_LEAVE(); + + return selected_attr; +} + int select_version(void) { MEDIA_VISION_FUNCTION_ENTER(); @@ -999,10 +1089,11 @@ int perform_detect() MV_BARCODE_UNDEFINED, MV_BARCODE_QR_ECC_UNAVAILABLE, MV_BARCODE_QR_MODE_UNAVAILABLE, + 0, 0, 0, 0, MV_BARCODE_IMAGE_FORMAT_PNG, MEDIA_VISION_COLORSPACE_INVALID, - NULL, NULL, NULL, NULL }; + NULL, NULL, NULL, NULL, NULL, NULL }; while (input_string("Input file name to be analyzed:", 1024, &(detect_model.file_name)) == -1) printf("Incorrect input! Try again.\n"); @@ -1080,10 +1171,11 @@ int perform_generate(void) MV_BARCODE_UNDEFINED, MV_BARCODE_QR_ECC_UNAVAILABLE, MV_BARCODE_QR_MODE_UNAVAILABLE, + 0, 0, 0, 0, MV_BARCODE_IMAGE_FORMAT_PNG, MEDIA_VISION_COLORSPACE_INVALID, - NULL, NULL, NULL, NULL }; + NULL, NULL, NULL, NULL, NULL, NULL }; generation_fcn_e gen_fcn = select_gen_function(); generate_model.type = select_type(); @@ -1098,6 +1190,11 @@ int perform_generate(void) LOGI("Barcode version has been selected"); } + if (generate_model.type != MV_BARCODE_QR) { + generate_model.is_hrt = select_attribute_text(); + LOGI("Barcode readable text attribute has been selected"); + } + if (gen_fcn == MV_TS_GENERATE_TO_IMAGE_FCN) { generate_model.out_image_format = select_file_format(); LOGI("Barcode output image format has been selected"); @@ -1113,6 +1210,16 @@ int perform_generate(void) LOGI("Barcode output file name has been specified"); + while (input_string("Input foreground color (ex:black is 000000):", 1024, &generate_model.front_color) == -1) + printf("Incorrect input! Try again.\n"); + + LOGI("Foreground color is %s", generate_model.front_color); + + while (input_string("Input background color (ex:white is ffffff):", 1024, &generate_model.back_color) == -1) + printf("Incorrect input! Try again.\n"); + + LOGI("Background color is %s", generate_model.back_color); + if (gen_fcn == MV_TS_GENERATE_TO_IMAGE_FCN) { while (input_size("Input image width:", 10000, &generate_model.width) == -1) printf("Incorrect input! Try again.\n"); @@ -1136,6 +1243,12 @@ int perform_generate(void) if (generate_model.file_name != NULL) free(generate_model.file_name); + if (generate_model.front_color != NULL) + free(generate_model.front_color); + + if (generate_model.back_color != NULL) + free(generate_model.back_color); + if (err != MEDIA_VISION_ERROR_NONE) { LOGE("Barcode generation failed with error code (0x%08x)", err); printf("ERROR: Errors were occurred during barcode generation!!!\n"); -- cgit v1.2.3