#define __MEDIA_VISION_BARCODE_GENERATOR_H__
#include "BarcodeOptions.h"
-
+#include <zint.h>
#include <string>
#include <EngineConfig.h>
#include <opencv2/core/mat.hpp>
+#include <mv_barcode_type.h>
/**
* @file BarcodeGenerator.h
{
namespace Barcode
{
-/**
- * @brief This class implements barcode generation.
- * @details 1D Barcodes and 2D QR codes are supported.
- *
- * @since_tizen 2.4
- */
-class BarcodeGenerator
-{
-public:
- /**
- * @brief This method generates Barcodes image according to options.
- *
- * @since_tizen 2.4
- * @param [in] imageFileName Image file name which will be generated
- * @param [in] imageFormat Image file format which will be generated
- * @param [in] imageWidth Image file width which will be generated
- * @param [in] imageHeight Image file height which will be generated
- * @param [in] message Input message to be encoded
- * @param [in] type Barcode type (1D barcode or 2D QR code)
- * @param [in] encodingMode Encoding mode (for QR codes only)
- * @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
- */
- static int generateBarcodeToImage(const std::string &imageFileName, BarcodeImageFormat imageFormat,
- const int imageWidth, const int imageHeight, 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, char *bgcolur = NULL);
+int createBarcode(const std::string &message, BarcodeType type, BarcodeQREncodingMode encodingMode,
+ BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText, char *fgcolour,
+ char *bgcolour, zint_symbol *symbol, Common::EngineConfig *engineCfg);
+
+int write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, mv_barcode_image_format_e image_format,
+ const int imageWidth, const int imageHeight, mv_engine_config_h engine_cfg);
- /**
- * @brief This method generates Barcodes image buffer according to options.
- *
- * @since_tizen 2.4
- * @param [in] message Input message to be encoded
- * @param [in] type Barcode type (1D barcode or 2D QR code)
- * @param [in] encodingMode Encoding mode (for QR codes only)
- * @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
- * @param [out] buf Opencv Mat image buffer to be generated
- * @return BARCODE_ERROR_NONE from BarcodeError which is 0 if success,
- * BarcodeError value otherwise
- */
- static int generateBarcodeMat(const std::string &message, BarcodeType type, Common::EngineConfig *engineCfg,
- BarcodeQREncodingMode encodingMode, BarcodeQRErrorCorrectionLevel correctionLevel,
- int qrVersion, int showText, char *fgcolour, char *bgcolur, cv::Mat &buf);
-};
+BarcodeImageFormat convertImageFormat(mv_barcode_image_format_e format);
} /* Barcode */
} /* MediaVision */
#define __MEDIA_VISION_BARCODE_GENERATE_OPEN_H__
#include "mv_barcode_generate.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+#include "BarcodeGenerator.h"
+#include <zint.h>
/**
* @file mv_barcode_generate_open.h
* @ref MV_BARCODE_QR_ECC_UNAVAILABLE)
* @param [in] qr_version QR code version (for 1D barcodes set this
* parameter to 0)
- * @param [in, out] image The media source handle which will be used to
- * fill by the buffer with generated image
+ * @param [out] symbol The media source handle which will be used to
+ * fill by the buffer with generated symbol
* @return @c 0 on success, otherwise a negative error value
* @retval #MEDIA_VISION_ERROR_NONE Successful
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
*
* @see mv_barcode_generate_image_open()
*/
-int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *message, mv_barcode_type_e type,
- mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version,
- mv_source_h image);
-
-/**
- * @brief Generates image file with barcode.
- *
- * @since_tizen 2.4
- * @param [in] engine_cfg The handle to the configuration of the engine
- * @param [in] message The message to be encoded in the barcode
- * @param [in] image_width The width of the generated image
- * @param [in] image_height The height of the generated image
- * @param [in] type Type of the barcode to be generated
- * @param [in] qr_enc_mode Encoding mode for the message (only for QR codes;
- * for 1D barcodes set this parameter to
- * @ref MV_BARCODE_QR_MODE_UNAVAILABLE)
- * @param [in] qr_ecc Error correction level (only for QR codes; for
- * 1D barcodes set this parameter to
- * @ref MV_BARCODE_QR_ECC_UNAVAILABLE)
- * @param [in] qr_version QR code version (for 1D barcodes set this
- * parameter to 0)
- * @param [in] image_path The path to the file that has to be generated
- * @param [in] image_format The format of the output image
- * @return @c 0 on success, otherwise a negative error value
- * @retval #MEDIA_VISION_ERROR_NONE Successful
- * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #MEDIA_VISION_ERROR_MSG_TOO_LONG Too long or short message
- * @retval #MEDIA_VISION_ERROR_PERMISSION_DENIED Permission denied
- * @retval #MEDIA_VISION_ERROR_INVALID_PATH Invalid path
- *
- * @see mv_barcode_generate_source_open()
- */
-int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *message, int image_width,
- int image_height, mv_barcode_type_e type, mv_barcode_qr_mode_e qr_enc_mode,
- mv_barcode_qr_ecc_e qr_ecc, int qr_version, const char *image_path,
- mv_barcode_image_format_e image_format);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+int mv_barcode_generate_symbol(mv_engine_config_h engine_cfg, const char *message, mv_barcode_type_e type,
+ mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version,
+ zint_symbol *symbol);
#endif /* __MEDIA_VISION_BARCODE_GENERATE_OPEN_H__ */
{
namespace Barcode
{
+BarcodeImageFormat convertImageFormat(mv_barcode_image_format_e format)
+{
+ BarcodeImageFormat imageFormat = BARCODE_IMAGE_PNG;
+
+ switch (format) {
+ case MV_BARCODE_IMAGE_FORMAT_JPG:
+ imageFormat = BARCODE_IMAGE_JPG;
+ break;
+ case MV_BARCODE_IMAGE_FORMAT_BMP:
+ imageFormat = BARCODE_IMAGE_BMP;
+ break;
+ default:
+ break;
+ }
+
+ LOGI("Media vision image format has been converted to "
+ "internal image format (%i -> %i)",
+ format, imageFormat);
+ return imageFormat;
+}
+
int getFormatEncodingInfo(BarcodeImageFormat imageFormat, std::vector<std::string> &extensions,
std::vector<int> &compressionParams)
{
return error;
}
-static int __write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, BarcodeImageFormat imageFormat,
- const int imageWidth, const int imageHeight, Common::EngineConfig *engineCfg)
+int write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, mv_barcode_image_format_e image_format,
+ const int imageWidth, const int imageHeight, mv_engine_config_h engine_cfg)
{
/* find directory */
std::string prefix_imageFileName = imageFileName.substr(0, imageFileName.find_last_of('/'));
/* check current extension */
std::vector<std::string> expectedExtensions;
std::vector<int> compressionParams;
-
+ auto imageFormat = convertImageFormat(image_format);
int error = getFormatEncodingInfo(imageFormat, expectedExtensions, compressionParams);
if (BARCODE_ERROR_NONE != error || expectedExtensions.empty()) {
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);
+ auto engineCfg = static_cast<Common::EngineConfig *>(engine_cfg);
if (engineCfg) {
error = __draw_logo(image, engineCfg);
if (error != MEDIA_VISION_ERROR_NONE) {
return error;
}
-
-int BarcodeGenerator::generateBarcodeToImage(const std::string &imageFileName, BarcodeImageFormat imageFormat,
- const int imageWidth, const int imageHeight, const std::string &message,
- BarcodeType type, Common::EngineConfig *engineCfg,
- BarcodeQREncodingMode encodingMode,
- BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText,
- char *fgcolour, char *bgcolour)
-{
- zint_symbol *symbol = ZBarcode_Create();
-
- if (symbol == NULL) {
- LOGE("ZBarcode creation failed");
- return BARCODE_ERROR_ENCODING_PROBLEM;
- }
-
- int error = createBarcode(message, type, encodingMode, correctionLevel, qrVersion, showText, fgcolour, bgcolour,
- symbol, engineCfg);
-
- if (error != BARCODE_ERROR_NONE) {
- LOGE("Barcode creation failed, clean memory");
- goto zbarcode_delete;
- }
-
- error = __write_buffer_to_img(symbol, imageFileName, imageFormat, imageWidth, imageHeight, engineCfg);
- 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;
-}
-
-int BarcodeGenerator::generateBarcodeMat(const std::string &message, BarcodeType type, Common::EngineConfig *engineCfg,
- BarcodeQREncodingMode encodingMode,
- BarcodeQRErrorCorrectionLevel correctionLevel, int qrVersion, int showText,
- char *fgcolour, char *bgcolour, cv::Mat &buf)
-{
- zint_symbol *symbol = ZBarcode_Create();
-
- if (symbol == NULL) {
- LOGE("ZBarcode creation failed");
-
- return BARCODE_ERROR_ENCODING_PROBLEM;
- }
-
- 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;
- }
-
- /* fill output buffer */
- buf = cv::Mat(symbol->bitmap_height, symbol->bitmap_width, CV_8UC3, symbol->bitmap).clone();
-
- LOGI("Barcode buffer has been successfully generated, clean memory");
- ZBarcode_Delete(symbol);
-
- return BARCODE_ERROR_NONE;
-}
-
} /* Barcode */
} /* MediaVision */
* limitations under the License.
*/
+#include <string>
#include <system_info.h>
-
+#include <zint.h>
#include "mv_private.h"
#include "mv_feature_key.h"
#include "mv_barcode_generate.h"
/* Include headers of open barcode generate module here. */
#include "mv_barcode_generate_open.h"
+using namespace std;
/**
* @file mv_barcode_generate.c
* @brief This file contains the porting layer for Media Vision barcode module.
MEDIA_VISION_INSTANCE_CHECK(image);
MEDIA_VISION_CHECK_ERR(__check_barcode_param(message, type, qr_enc_mode, qr_ecc, qr_version), "Invalid parameter");
- /* Use open barcode generate functionality here. */
- int ret = mv_barcode_generate_source_open(engine_cfg, message, type, qr_enc_mode, qr_ecc, qr_version, image);
+ zint_symbol *symbol = ZBarcode_Create();
+ if (symbol == NULL) {
+ LOGE("ZBarcode creation failed");
+ return MEDIA_VISION_ERROR_INTERNAL;
+ }
+
+ int ret = mv_barcode_generate_symbol(engine_cfg, message, type, qr_enc_mode, qr_ecc, qr_version, symbol);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ ZBarcode_Delete(symbol);
+ return ret;
+ }
+ ret = mv_source_fill_by_buffer(image, (unsigned char *) symbol->bitmap,
+ symbol->bitmap_width * symbol->bitmap_height * 3, symbol->bitmap_width,
+ symbol->bitmap_height, MEDIA_VISION_COLORSPACE_RGB888);
+ ZBarcode_Delete(symbol);
MEDIA_VISION_FUNCTION_LEAVE();
return ret;
}
return MEDIA_VISION_ERROR_INVALID_PARAMETER;
}
- /* Use open barcode generate functionality here. */
- int ret = mv_barcode_generate_image_open(engine_cfg, message, image_width, image_height, type, qr_enc_mode, qr_ecc,
- qr_version, image_path, image_format);
+ zint_symbol *symbol = ZBarcode_Create();
+ if (symbol == NULL) {
+ LOGE("ZBarcode creation failed");
+ return MEDIA_VISION_ERROR_INTERNAL;
+ }
+
+ int ret = mv_barcode_generate_symbol(engine_cfg, message, type, qr_enc_mode, qr_ecc, qr_version, symbol);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ ZBarcode_Delete(symbol);
+ return ret;
+ }
+
+ ret = MediaVision::Barcode::write_buffer_to_img(symbol, string(image_path), image_format, image_width, image_height,
+ engine_cfg);
+ ZBarcode_Delete(symbol);
MEDIA_VISION_FUNCTION_LEAVE();
return ret;
}
return mvError;
}
-BarcodeImageFormat convertImageFormat(mv_barcode_image_format_e format)
-{
- BarcodeImageFormat imageFormat = BARCODE_IMAGE_PNG;
-
- switch (format) {
- case MV_BARCODE_IMAGE_FORMAT_JPG:
- imageFormat = BARCODE_IMAGE_JPG;
- break;
- case MV_BARCODE_IMAGE_FORMAT_BMP:
- imageFormat = BARCODE_IMAGE_BMP;
- break;
- default:
- break;
- }
-
- LOGI("Media vision image format has been converted to "
- "internal image format (%i -> %i)",
- format, imageFormat);
- return imageFormat;
-}
-
static int prepareMessageToGenerate(const char *message, mv_barcode_type_e type, mv_barcode_qr_mode_e qr_enc_mode,
std::string &messageStr)
{
return MEDIA_VISION_ERROR_NONE;
}
-int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg, const char *message, mv_barcode_type_e type,
- mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version,
- mv_source_h image)
+int mv_barcode_generate_symbol(mv_engine_config_h engine_cfg, const char *message, mv_barcode_type_e type,
+ mv_barcode_qr_mode_e qr_enc_mode, mv_barcode_qr_ecc_e qr_ecc, int qr_version,
+ zint_symbol *symbol)
{
std::string messageStr;
int error = prepareMessageToGenerate(message, type, qr_enc_mode, messageStr);
LOGE("getColorFromEngine failed");
return error;
}
-
- cv::Mat buf;
- error = BarcodeGenerator::generateBarcodeMat(messageStr, convertBarcodeType(type), engineCfg,
- convertEncodingMode(qr_enc_mode), convertECC(qr_ecc), qr_version,
- showText, fgcolour, bgcolour, buf);
+ error = createBarcode(message, convertBarcodeType(type), convertEncodingMode(qr_enc_mode), convertECC(qr_ecc),
+ qr_version, showText, fgcolour, bgcolour, symbol, engineCfg);
free(fgcolour);
free(bgcolour);
-
if (error != BARCODE_ERROR_NONE) {
- LOGE("Barcode generation to the buffer failed");
- return convertBarcodeError(error);
+ 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, messageStr.c_str());
}
-
- LOGI("Barcode has been generated to the buffer: Buffer size = %ui x %ui; Channels = %ui; Message = %s", buf.cols,
- buf.rows, buf.channels(), messageStr.c_str());
-
- error = mv_source_fill_by_buffer(image, buf.data, buf.total() * buf.elemSize(), buf.cols, buf.rows,
- MEDIA_VISION_COLORSPACE_RGB888);
-
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Meidiavision source fill by generated buffer failed");
-
- return error;
-}
-
-int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *message, int image_width,
- int image_height, mv_barcode_type_e type, mv_barcode_qr_mode_e qr_enc_mode,
- mv_barcode_qr_ecc_e qr_ecc, int qr_version, const char *image_path,
- mv_barcode_image_format_e image_format)
-{
- std::string messageStr;
- int error = prepareMessageToGenerate(message, type, qr_enc_mode, messageStr);
- if (error != MEDIA_VISION_ERROR_NONE) {
- LOGE("prepareMessageToGenerate failed");
- return error;
- }
-
- int showText = 0;
- 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");
- return error;
- }
-
- error = BarcodeGenerator::generateBarcodeToImage(std::string(image_path), convertImageFormat(image_format),
- image_width, image_height, messageStr, convertBarcodeType(type),
- engineCfg, convertEncodingMode(qr_enc_mode), convertECC(qr_ecc),
- qr_version, showText, fgcolour, bgcolour);
-
- free(fgcolour);
- free(bgcolour);
-
- if (error != BARCODE_ERROR_NONE) {
- LOGE("Barcode generation to the image file failed");
- } else {
- LOGI("Barcode has been generated to the image: "
- "Image size = %ui x %ui; Message = %s",
- image_width, image_height, messageStr.c_str());
- }
-
return convertBarcodeError(error);
}