summaryrefslogtreecommitdiff
path: root/mv_barcode
diff options
context:
space:
mode:
authorTae-Young Chung <ty83.chung@samsung.com>2015-10-21 21:05:38 +0900
committerTae-Young Chung <ty83.chung@samsung.com>2015-10-21 21:05:43 +0900
commitb54972ca08e90f8c31dc86c6c59ae059d9010294 (patch)
tree621519421650f44d9bb2c9d371059203832be281 /mv_barcode
parentcd96fa4795772731a74030246c307a127dfe0eb6 (diff)
downloadmediavision-b54972ca08e90f8c31dc86c6c59ae059d9010294.tar.gz
mediavision-b54972ca08e90f8c31dc86c6c59ae059d9010294.tar.bz2
mediavision-b54972ca08e90f8c31dc86c6c59ae059d9010294.zip
Change-Id: Ifd9f6e2e312eea7735e17aaf3bd4c416c845fd91 Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
Diffstat (limited to 'mv_barcode')
-rw-r--r--mv_barcode/barcode_detector/include/Barcode.h90
-rw-r--r--mv_barcode/barcode_detector/include/BarcodeUtils.h11
-rw-r--r--mv_barcode/barcode_detector/include/mv_barcode_detect_open.h11
-rw-r--r--mv_barcode/barcode_detector/src/Barcode.cpp187
-rw-r--r--mv_barcode/barcode_detector/src/BarcodeUtils.cpp146
-rw-r--r--mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp235
-rw-r--r--mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h10
-rw-r--r--mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c12
-rw-r--r--mv_barcode/barcode_generator/include/BarcodeGenerator.h123
-rw-r--r--mv_barcode/barcode_generator/include/BarcodeOptions.h90
-rw-r--r--mv_barcode/barcode_generator/include/mv_barcode_generate_open.h32
-rw-r--r--mv_barcode/barcode_generator/src/BarcodeGenerator.cpp479
-rw-r--r--mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp605
-rw-r--r--mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h34
-rw-r--r--mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c39
15 files changed, 996 insertions, 1108 deletions
diff --git a/mv_barcode/barcode_detector/include/Barcode.h b/mv_barcode/barcode_detector/include/Barcode.h
index 6003fb1b..b47cacd2 100644
--- a/mv_barcode/barcode_detector/include/Barcode.h
+++ b/mv_barcode/barcode_detector/include/Barcode.h
@@ -22,64 +22,60 @@
#include <stddef.h>
#include <zbar.h>
-namespace MediaVision
-{
-namespace Barcode
-{
-
+namespace MediaVision {
+namespace Barcode {
/**
* @class Barcode
* @brief Handle to barcode object.
*/
-class Barcode
-{
+class Barcode {
public:
- /**
- * @brief Barcode constructor.
- *
- * @since_tizen 2.4
- * @remarks create copy of bar_obj
- * @param [in] barObj zbar barcode handle
- *
- */
- Barcode(const zbar::Symbol& barObj);
+ /**
+ * @brief Barcode constructor.
+ *
+ * @since_tizen 2.4
+ * @remarks create copy of bar_obj
+ * @param [in] barObj zbar barcode handle
+ *
+ */
+ Barcode(const zbar::Symbol& barObj);
- /**
- * @brief Barcode destructor.
- *
- * @since_tizen 2.4
- */
- ~Barcode();
+ /**
+ * @brief Barcode destructor.
+ *
+ * @since_tizen 2.4
+ */
+ ~Barcode();
- /**
- * @brief Gets encoded message from barcode object.
- *
- * @since_tizen 2.4
- * @return Encoded message
- */
- std::string getMessage(void) const;
+ /**
+ * @brief Gets encoded message from barcode object.
+ *
+ * @since_tizen 2.4
+ * @return Encoded message
+ */
+ std::string getMessage(void) const;
- /**
- * @brief Gets the type of the barcode.
- *
- * @since_tizen 2.4
- * @return Enumeration value corresponding to the barcode type
- */
- mv_barcode_type_e getType(void) const;
+ /**
+ * @brief Gets the type of the barcode.
+ *
+ * @since_tizen 2.4
+ * @return Enumeration value corresponding to the barcode type
+ */
+ mv_barcode_type_e getType(void) const;
- /**
- * @brief Calculates location of barcode handle from zbar.
- * location polygon.
- *
- * @since_tizen 2.4
- * @param [out] location Quadrangle that contains barcode on image
- * @return @c MEDIA_VISION_ERROR_NONE on success,
- * otherwise a negative error value
- */
- int calculateLocation(mv_quadrangle_s& location) const;
+ /**
+ * @brief Calculates location of barcode handle from zbar.
+ * location polygon.
+ *
+ * @since_tizen 2.4
+ * @param [out] location Quadrangle that contains barcode on image
+ * @return @c MEDIA_VISION_ERROR_NONE on success,
+ * otherwise a negative error value
+ */
+ int calculateLocation(mv_quadrangle_s& location) const;
private:
- const zbar::Symbol *m_pBarcodeObj; ///< Pointer to zbar barcode handle
+ const zbar::Symbol *m_pBarcodeObj; ///< Pointer to zbar barcode handle
};
} /* Barcode */
diff --git a/mv_barcode/barcode_detector/include/BarcodeUtils.h b/mv_barcode/barcode_detector/include/BarcodeUtils.h
index 4dea3653..d386cc08 100644
--- a/mv_barcode/barcode_detector/include/BarcodeUtils.h
+++ b/mv_barcode/barcode_detector/include/BarcodeUtils.h
@@ -19,15 +19,12 @@
#include "mv_common.h"
-namespace zbar
-{
- class Image;
+namespace zbar {
+class Image;
}
-namespace MediaVision
-{
-namespace Barcode
-{
+namespace MediaVision {
+namespace Barcode {
/**
* @brief This function converts media vision image handle to zbar image handle.
diff --git a/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h b/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h
index e13d8e7f..c6a34956 100644
--- a/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h
+++ b/mv_barcode/barcode_detector/include/mv_barcode_detect_open.h
@@ -53,12 +53,11 @@ extern "C" {
* @see mv_barcode_detected_cb()
*/
int mv_barcode_detect_open(
- mv_source_h source,
- mv_engine_config_h engine_cfg,
- mv_rectangle_s roi,
- mv_barcode_detected_cb detect_cb,
- void *user_data);
-
+ mv_source_h source,
+ mv_engine_config_h engine_cfg,
+ mv_rectangle_s roi,
+ mv_barcode_detected_cb detect_cb,
+ void *user_data);
#ifdef __cplusplus
}
diff --git a/mv_barcode/barcode_detector/src/Barcode.cpp b/mv_barcode/barcode_detector/src/Barcode.cpp
index a35f8bd1..33616102 100644
--- a/mv_barcode/barcode_detector/src/Barcode.cpp
+++ b/mv_barcode/barcode_detector/src/Barcode.cpp
@@ -18,130 +18,109 @@
#include <mv_private.h>
-namespace MediaVision
-{
-namespace Barcode
-{
+namespace MediaVision {
+namespace Barcode {
Barcode::Barcode(const zbar::Symbol& barObj):
- m_pBarcodeObj(new zbar::Symbol(barObj))
+ m_pBarcodeObj(new zbar::Symbol(barObj))
{
; /* NULL */
}
Barcode::~Barcode()
{
- LOGI("Delete ZBar object");
- delete m_pBarcodeObj;
+ LOGI("Delete ZBar object");
+ delete m_pBarcodeObj;
}
std::string Barcode::getMessage(void) const
{
- LOGI("Retrieve message data from ZBar object");
- return m_pBarcodeObj->get_data();
+ LOGI("Retrieve message data from ZBar object");
+ return m_pBarcodeObj->get_data();
}
mv_barcode_type_e Barcode::getType(void) const
{
- zbar::zbar_symbol_type_t barcodeType = m_pBarcodeObj->get_type();
-
- switch (barcodeType)
- {
- case zbar::ZBAR_QRCODE:
- return MV_BARCODE_QR;
-
- case zbar::ZBAR_UPCA:
- return MV_BARCODE_UPC_A;
-
- case zbar::ZBAR_UPCE:
- return MV_BARCODE_UPC_E;
-
- case zbar::ZBAR_EAN8:
- return MV_BARCODE_EAN_8;
-
- case zbar::ZBAR_EAN13:
- return MV_BARCODE_EAN_13;
-
- case zbar::ZBAR_CODE128:
- return MV_BARCODE_CODE128;
-
- case zbar::ZBAR_CODE39:
- return MV_BARCODE_CODE39;
-
- case zbar::ZBAR_I25:
- return MV_BARCODE_I2_5;
-
- default:
- LOGE("ZBar symbol colorspace is not supported by media vision");
- return MV_BARCODE_UNDEFINED;
- }
+ zbar::zbar_symbol_type_t barcodeType = m_pBarcodeObj->get_type();
+
+ switch (barcodeType) {
+ case zbar::ZBAR_QRCODE:
+ return MV_BARCODE_QR;
+ case zbar::ZBAR_UPCA:
+ return MV_BARCODE_UPC_A;
+ case zbar::ZBAR_UPCE:
+ return MV_BARCODE_UPC_E;
+ case zbar::ZBAR_EAN8:
+ return MV_BARCODE_EAN_8;
+ case zbar::ZBAR_EAN13:
+ return MV_BARCODE_EAN_13;
+ case zbar::ZBAR_CODE128:
+ return MV_BARCODE_CODE128;
+ case zbar::ZBAR_CODE39:
+ return MV_BARCODE_CODE39;
+ case zbar::ZBAR_I25:
+ return MV_BARCODE_I2_5;
+ default:
+ LOGE("ZBar symbol colorspace is not supported by media vision");
+ return MV_BARCODE_UNDEFINED;
+ }
}
int Barcode::calculateLocation(mv_quadrangle_s& location) const
{
- const int numberOfVertexes = 4;
-
- const int locationPolygonSize = m_pBarcodeObj->get_location_size();
-
- //polygon location should contain at least 4 points
- if (locationPolygonSize < numberOfVertexes)
- {
- LOGW("Can't compute location of the barcode by %i points (less then %i).", locationPolygonSize, numberOfVertexes);
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
-
- if (locationPolygonSize == numberOfVertexes)
- {
- for (int i = 0; i < numberOfVertexes; ++i)
- {
- location.points[i].x = m_pBarcodeObj->get_location_x(i);
- location.points[i].y = m_pBarcodeObj->get_location_y(i);
- }
-
- return MEDIA_VISION_ERROR_NONE;
- }
-
- //bounding quadrangle is computing by 4 marginal points
- mv_point_s first = {m_pBarcodeObj->get_location_x(0), m_pBarcodeObj->get_location_y(0)};
-
- int minX = first.x;
- int maxX = first.x;
- int minY = first.y;
- int maxY = first.y;
-
- for (int i = 0; i < locationPolygonSize; ++i)
- {
- mv_point_s current = {m_pBarcodeObj->get_location_x(i), m_pBarcodeObj->get_location_y(i)};
- if (current.x < minX)
- {
- minX = current.x;
- }
- else if (current.x > maxX)
- {
- maxX = current.x;
- }
-
- if (current.y < minY)
- {
- minY = current.y;
- }
- else if (current.y > maxY)
- {
- maxY = current.y;
- }
- }
-
- mv_point_s bottomLeft = {minX, maxY};
- mv_point_s bottomRight = {maxX, maxY};
- mv_point_s topRight = {maxX, minY};
- mv_point_s topLeft = {minX, minY};
-
- location.points[0] = topLeft;
- location.points[1] = topRight;
- location.points[2] = bottomRight;
- location.points[3] = bottomLeft;
-
- return MEDIA_VISION_ERROR_NONE;
+ const int numberOfVertexes = 4;
+
+ const int locationPolygonSize = m_pBarcodeObj->get_location_size();
+
+ /*polygon location should contain at least 4 points */
+ if (locationPolygonSize < numberOfVertexes) {
+ LOGW("Can't compute location of the barcode by %i points (less then %i).", locationPolygonSize, numberOfVertexes);
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ if (locationPolygonSize == numberOfVertexes) {
+ for (int i = 0; i < numberOfVertexes; ++i) {
+ location.points[i].x = m_pBarcodeObj->get_location_x(i);
+ location.points[i].y = m_pBarcodeObj->get_location_y(i);
+ }
+
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
+ /* bounding quadrangle is computing by 4 marginal points */
+ mv_point_s first = {m_pBarcodeObj->get_location_x(0), m_pBarcodeObj->get_location_y(0)};
+
+ int minX = first.x;
+ int maxX = first.x;
+ int minY = first.y;
+ int maxY = first.y;
+
+ for (int i = 0; i < locationPolygonSize; ++i) {
+ mv_point_s current = {m_pBarcodeObj->get_location_x(i), m_pBarcodeObj->get_location_y(i)};
+ if (current.x < minX) {
+ minX = current.x;
+ } else if (current.x > maxX) {
+ maxX = current.x;
+ }
+
+ if (current.y < minY) {
+ minY = current.y;
+ } else if (current.y > maxY) {
+ maxY = current.y;
+ }
+ }
+
+ mv_point_s bottomLeft = {minX, maxY};
+ mv_point_s bottomRight = {maxX, maxY};
+ mv_point_s topRight = {maxX, minY};
+ mv_point_s topLeft = {minX, minY};
+
+ location.points[0] = topLeft;
+ location.points[1] = topRight;
+ location.points[2] = bottomRight;
+ location.points[3] = bottomLeft;
+
+ return MEDIA_VISION_ERROR_NONE;
}
} /* Barcode */
diff --git a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp
index 57219eb6..a9da9230 100644
--- a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp
+++ b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp
@@ -21,92 +21,84 @@
#include <zbar.h>
-namespace MediaVision
-{
-namespace Barcode
-{
-
+namespace MediaVision {
+namespace Barcode {
int convertSourceMV2Zbar(mv_source_h mvSource, zbar::Image& zbarSource)
{
- int err = MEDIA_VISION_ERROR_NONE;
- unsigned char *buffer = NULL;
- unsigned int height = 0;
- unsigned int width = 0;
- unsigned int size = 0;
- mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ int err = MEDIA_VISION_ERROR_NONE;
+ unsigned char *buffer = NULL;
+ unsigned int height = 0;
+ unsigned int width = 0;
+ unsigned int size = 0;
+ mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
- err = mv_source_get_colorspace_c(mvSource, &colorspace);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("Can't determine mv_source_h colorspace to convert to ZBar colorspace. Conversion failed");
- return err;
- }
+ err = mv_source_get_colorspace_c(mvSource, &colorspace);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("Can't determine mv_source_h colorspace to convert to ZBar colorspace. Conversion failed");
+ return err;
+ }
- switch(colorspace)
- {
- case MEDIA_VISION_COLORSPACE_Y800:
- zbarSource.set_format("Y800");
- break;
- case MEDIA_VISION_COLORSPACE_I420:
- zbarSource.set_format("I420");
- break;
- case MEDIA_VISION_COLORSPACE_NV12:
- zbarSource.set_format("NV12");
- break;
- case MEDIA_VISION_COLORSPACE_YV12:
- zbarSource.set_format("YV12");
- break;
- case MEDIA_VISION_COLORSPACE_NV21:
- zbarSource.set_format("NV21");
- break;
- case MEDIA_VISION_COLORSPACE_YUYV:
- zbarSource.set_format("YUYV");
- break;
- case MEDIA_VISION_COLORSPACE_UYVY:
- zbarSource.set_format("UYVY");
- break;
- case MEDIA_VISION_COLORSPACE_422P:
- zbarSource.set_format("422P");
- break;
- case MEDIA_VISION_COLORSPACE_RGB565:
- zbarSource.set_format("RGBP");
- break;
- case MEDIA_VISION_COLORSPACE_RGB888:
- zbarSource.set_format("RGB3");
- break;
- case MEDIA_VISION_COLORSPACE_RGBA:
- zbarSource.set_format("RGB4");
- break;
- default:
- LOGE("Media vision colorspace is not supported by ZBar symbol");
- return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT;
- }
+ switch(colorspace) {
+ case MEDIA_VISION_COLORSPACE_Y800:
+ zbarSource.set_format("Y800");
+ break;
+ case MEDIA_VISION_COLORSPACE_I420:
+ zbarSource.set_format("I420");
+ break;
+ case MEDIA_VISION_COLORSPACE_NV12:
+ zbarSource.set_format("NV12");
+ break;
+ case MEDIA_VISION_COLORSPACE_YV12:
+ zbarSource.set_format("YV12");
+ break;
+ case MEDIA_VISION_COLORSPACE_NV21:
+ zbarSource.set_format("NV21");
+ break;
+ case MEDIA_VISION_COLORSPACE_YUYV:
+ zbarSource.set_format("YUYV");
+ break;
+ case MEDIA_VISION_COLORSPACE_UYVY:
+ zbarSource.set_format("UYVY");
+ break;
+ case MEDIA_VISION_COLORSPACE_422P:
+ zbarSource.set_format("422P");
+ break;
+ case MEDIA_VISION_COLORSPACE_RGB565:
+ zbarSource.set_format("RGBP");
+ break;
+ case MEDIA_VISION_COLORSPACE_RGB888:
+ zbarSource.set_format("RGB3");
+ break;
+ case MEDIA_VISION_COLORSPACE_RGBA:
+ zbarSource.set_format("RGB4");
+ break;
+ default:
+ LOGE("Media vision colorspace is not supported by ZBar symbol");
+ return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT;
+ }
- err = mv_source_get_buffer_c(mvSource, &buffer, &size);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("Can't get mv_source_h buffer to convert to ZBar image. Conversion failed");
- return err;
- }
+ err = mv_source_get_buffer_c(mvSource, &buffer, &size);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("Can't get mv_source_h buffer to convert to ZBar image. Conversion failed");
+ return err;
+ }
- err = mv_source_get_height_c(mvSource, &height);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("Can't get mv_source_h height for conversion. Conversion failed");
- return err;
- }
+ err = mv_source_get_height_c(mvSource, &height);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("Can't get mv_source_h height for conversion. Conversion failed");
+ return err;
+ }
- err = mv_source_get_width_c(mvSource, &width);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("Can't get mv_source_h width for conversion. Conversion failed");
- return err;
- }
+ err = mv_source_get_width_c(mvSource, &width);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("Can't get mv_source_h width for conversion. Conversion failed");
+ return err;
+ }
- zbarSource.set_size(width, height);
- zbarSource.set_data(buffer, size);
+ zbarSource.set_size(width, height);
+ zbarSource.set_data(buffer, size);
- return err;
+ return err;
}
} /* Barcode */
diff --git a/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp
index dd5e557d..b2357f7a 100644
--- a/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp
+++ b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp
@@ -26,128 +26,117 @@
using namespace MediaVision::Barcode;
int mv_barcode_detect_open(
- mv_source_h source,
- mv_engine_config_h engine_cfg,
- mv_rectangle_s roi,
- mv_barcode_detected_cb detect_cb,
- void *user_data)
+ mv_source_h source,
+ mv_engine_config_h engine_cfg,
+ mv_rectangle_s roi,
+ mv_barcode_detected_cb detect_cb,
+ void *user_data)
{
- if (!source || !detect_cb)
- {
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
-
- zbar::Image image;
- int err = convertSourceMV2Zbar(source, image);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("convertSourceMV2Zbar failed");
- return err;
- }
-
- zbar::Image greyImage = image.convert("Y800");
- greyImage.set_crop(roi.point.x, roi.point.y, roi.width, roi.height);
- zbar::ImageScanner scanner;
-
- int target_val;
- err = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_DETECT_ATTR_TARGET", &target_val);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("mv_engine_config_get_int_attribute failed");
- return err;
- }
-
- /**
- * 0 - linear barcodes and QR codes
- * 1 - only linear barcodes
- * 2 - only QR codes
- */
- switch (target_val)
- {
- case 0:
- scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
- break;
- case 1:
- scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
- scanner.set_config(zbar::ZBAR_UPCA, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_UPCE, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_EAN8, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_CODE128, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_CODE39, zbar::ZBAR_CFG_ENABLE, 1);
- scanner.set_config(zbar::ZBAR_I25, zbar::ZBAR_CFG_ENABLE, 1);
- break;
- case 2:
- scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
- scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);
- break;
- default:
- LOGW("Unavailabe target value %d", target_val);
- }
-
- int numberOfBarcodes = scanner.scan(greyImage);
- LOGI("ZBar scanner has found %i barcodes on the mv_source_h", numberOfBarcodes);
- mv_quadrangle_s *barcodeLocations = NULL;
- mv_barcode_type_e *types = NULL;
-
- if (numberOfBarcodes == 0)
- {
- LOGI("Call the detect callback for 0 detected barcodes");
- detect_cb(source, engine_cfg, barcodeLocations, NULL, types, numberOfBarcodes, user_data);
- return MEDIA_VISION_ERROR_NONE;
- }
- else if (numberOfBarcodes < 0)
- {
- LOGW("Incorrect number of barcodes (%i), detection is terminated", numberOfBarcodes);
- return MEDIA_VISION_ERROR_INTERNAL;
- }
-
- const char **messagesArray = new const char*[numberOfBarcodes];
- barcodeLocations = new mv_quadrangle_s[numberOfBarcodes];
- types = new mv_barcode_type_e[numberOfBarcodes];
-
- int i = 0;
- //extract results and prepare them for callback passing
- for (zbar::SymbolIterator symbol = greyImage.symbol_begin();
- symbol != greyImage.symbol_end();
- ++symbol, ++i)
- {
- Barcode curBarcode(*symbol);
-
- size_t messageLength = curBarcode.getMessage().size();
- char *curMessage = new char[messageLength + 1];
- curBarcode.getMessage().copy(curMessage, messageLength);
- curMessage[messageLength] = '\0';
- messagesArray[i] = curMessage;
-
- types[i] = curBarcode.getType();
-
- int err = curBarcode.calculateLocation(barcodeLocations[i]);
- if (err != MEDIA_VISION_ERROR_NONE)
- {
- LOGW("Can't determine location for barcode, detection is terminated");
- for (int j = 0; j <= i; ++j)
- {
- delete[] messagesArray[j];
- }
- delete[] messagesArray;
- delete[] barcodeLocations;
- delete[] types;
- return err;
- }
- }
-
- LOGI("Call the detect callback for %i detected barcodes", numberOfBarcodes);
- detect_cb(source, engine_cfg, barcodeLocations, messagesArray, types, numberOfBarcodes, user_data);
-
- LOGI("Clean the memory from barcodes messages, locations and types");
- for (int j = 0; j < numberOfBarcodes; ++j)
- {
- delete[] messagesArray[j];
- }
- delete[] messagesArray;
- delete[] barcodeLocations;
- delete[] types;
-
- return MEDIA_VISION_ERROR_NONE;
+ if (!source || !detect_cb) {
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
+ zbar::Image image;
+ int err = convertSourceMV2Zbar(source, image);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("convertSourceMV2Zbar failed");
+ return err;
+ }
+
+ zbar::Image greyImage = image.convert("Y800");
+ greyImage.set_crop(roi.point.x, roi.point.y, roi.width, roi.height);
+ zbar::ImageScanner scanner;
+
+ int target_val;
+ err = mv_engine_config_get_int_attribute(engine_cfg, "MV_BARCODE_DETECT_ATTR_TARGET", &target_val);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("mv_engine_config_get_int_attribute failed");
+ return err;
+ }
+
+ /**
+ * 0 - linear barcodes and QR codes
+ * 1 - only linear barcodes
+ * 2 - only QR codes
+ */
+ switch (target_val) {
+ case 0:
+ scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
+ break;
+ case 1:
+ scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
+ scanner.set_config(zbar::ZBAR_UPCA, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_UPCE, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_EAN8, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_EAN13, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_CODE128, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_CODE39, zbar::ZBAR_CFG_ENABLE, 1);
+ scanner.set_config(zbar::ZBAR_I25, zbar::ZBAR_CFG_ENABLE, 1);
+ break;
+ case 2:
+ scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
+ scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);
+ break;
+ default:
+ LOGW("Unavailabe target value %d", target_val);
+ }
+
+ int numberOfBarcodes = scanner.scan(greyImage);
+ LOGI("ZBar scanner has found %i barcodes on the mv_source_h", numberOfBarcodes);
+ mv_quadrangle_s *barcodeLocations = NULL;
+ mv_barcode_type_e *types = NULL;
+
+ if (numberOfBarcodes == 0) {
+ LOGI("Call the detect callback for 0 detected barcodes");
+ detect_cb(source, engine_cfg, barcodeLocations, NULL, types, numberOfBarcodes, user_data);
+ return MEDIA_VISION_ERROR_NONE;
+ } else if (numberOfBarcodes < 0) {
+ LOGW("Incorrect number of barcodes (%i), detection is terminated", numberOfBarcodes);
+ return MEDIA_VISION_ERROR_INTERNAL;
+ }
+
+ const char **messagesArray = new const char*[numberOfBarcodes];
+ barcodeLocations = new mv_quadrangle_s[numberOfBarcodes];
+ types = new mv_barcode_type_e[numberOfBarcodes];
+
+ int i = 0;
+ /* extract results and prepare them for callback passing */
+ for (zbar::SymbolIterator symbol = greyImage.symbol_begin();
+ symbol != greyImage.symbol_end();
+ ++symbol, ++i) {
+ Barcode curBarcode(*symbol);
+
+ size_t messageLength = curBarcode.getMessage().size();
+ char *curMessage = new char[messageLength + 1];
+ curBarcode.getMessage().copy(curMessage, messageLength);
+ curMessage[messageLength] = '\0';
+ messagesArray[i] = curMessage;
+
+ types[i] = curBarcode.getType();
+
+ int err = curBarcode.calculateLocation(barcodeLocations[i]);
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ LOGW("Can't determine location for barcode, detection is terminated");
+ for (int j = 0; j <= i; ++j) {
+ delete[] messagesArray[j];
+ }
+ delete[] messagesArray;
+ delete[] barcodeLocations;
+ delete[] types;
+ return err;
+ }
+ }
+
+ LOGI("Call the detect callback for %i detected barcodes", numberOfBarcodes);
+ detect_cb(source, engine_cfg, barcodeLocations, messagesArray, types, numberOfBarcodes, user_data);
+
+ LOGI("Clean the memory from barcodes messages, locations and types");
+ for (int j = 0; j < numberOfBarcodes; ++j) {
+ delete[] messagesArray[j];
+ }
+ delete[] messagesArray;
+ delete[] barcodeLocations;
+ delete[] types;
+
+ return MEDIA_VISION_ERROR_NONE;
}
diff --git a/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h b/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h
index b1197239..40d71636 100644
--- a/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h
+++ b/mv_barcode/barcode_detector_lic/include/mv_barcode_detect_lic.h
@@ -50,11 +50,11 @@ extern "C" {
* @see mv_barcode_detected_cb()
*/
int mv_barcode_detect_lic(
- mv_source_h source,
- mv_engine_config_h engine_cfg,
- mv_rectangle_s roi,
- mv_barcode_detected_cb detect_cb,
- void *user_data);
+ mv_source_h source,
+ mv_engine_config_h engine_cfg,
+ mv_rectangle_s roi,
+ mv_barcode_detected_cb detect_cb,
+ void *user_data);
#ifdef __cplusplus
}
diff --git a/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c b/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c
index 5dc9fc02..e54a69ee 100644
--- a/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c
+++ b/mv_barcode/barcode_detector_lic/src/mv_barcode_detect_lic.c
@@ -17,11 +17,11 @@
#include "mv_barcode_detect_lic.h"
int mv_barcode_detect_lic(
- mv_source_h source,
- mv_engine_config_h engine_cfg,
- mv_rectangle_s roi,
- mv_barcode_detected_cb detect_cb,
- void *user_data)
+ mv_source_h source,
+ mv_engine_config_h engine_cfg,
+ mv_rectangle_s roi,
+ mv_barcode_detected_cb detect_cb,
+ void *user_data)
{
- return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+ return MEDIA_VISION_ERROR_NOT_SUPPORTED;
}
diff --git a/mv_barcode/barcode_generator/include/BarcodeGenerator.h b/mv_barcode/barcode_generator/include/BarcodeGenerator.h
index 40659aea..9fb0104b 100644
--- a/mv_barcode/barcode_generator/include/BarcodeGenerator.h
+++ b/mv_barcode/barcode_generator/include/BarcodeGenerator.h
@@ -26,78 +26,73 @@
* @brief This file contains the BarcodeGenerator class.
*/
-namespace MediaVision
-{
-namespace Barcode
-{
-
+namespace MediaVision {
+namespace Barcode {
/**
* @brief This class implements barcode generation.
* @details 1D Barcodes and 2D QR codes are supported.
*
* @since_tizen 2.4
*/
-class BarcodeGenerator
-{
+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
+ * @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,
+ BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
+ BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
+ int qrVersion = 0,
+ int showText = 0);
- /**
- * @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
- * @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,
- BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
- BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
- int qrVersion = 0,
- int showText = 0);
-
- /**
- * @brief This method generates Barcodes image buffer according to options.
- *
- * @since_tizen 2.4
- * @param [out] imageBuffer Image buffer with image to be generated
- * @param [out] imageWidth Image buffer width which will be generated
- * @param [out] imageHeight Image buffer height which will be generated
- * @param [out] imageChannels Image buffer channels number 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
- * @return BARCODE_ERROR_NONE from BarcodeError which is 0 if success,
- * BarcodeError value otherwise
- */
- static int generateBarcodeToBuffer(
- unsigned char **imageBuffer,
- unsigned int *imageWidth,
- unsigned int *imageHeight,
- unsigned int *imageChannels,
- const std::string& message,
- BarcodeType type,
- BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
- BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
- int qrVersion = 0,
- int showText = 0);
+ /**
+ * @brief This method generates Barcodes image buffer according to options.
+ *
+ * @since_tizen 2.4
+ * @param [out] imageBuffer Image buffer with image to be generated
+ * @param [out] imageWidth Image buffer width which will be generated
+ * @param [out] imageHeight Image buffer height which will be generated
+ * @param [out] imageChannels Image buffer channels number 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
+ * @return BARCODE_ERROR_NONE from BarcodeError which is 0 if success,
+ * BarcodeError value otherwise
+ */
+ static int generateBarcodeToBuffer(
+ unsigned char **imageBuffer,
+ unsigned int *imageWidth,
+ unsigned int *imageHeight,
+ unsigned int *imageChannels,
+ const std::string& message,
+ BarcodeType type,
+ BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_UNAVAILABLE,
+ BarcodeQRErrorCorrectionLevel correctionLevel = BARCODE_QR_ECC_UNAVAILABLE,
+ int qrVersion = 0,
+ int showText = 0);
};
} /* Barcode */
diff --git a/mv_barcode/barcode_generator/include/BarcodeOptions.h b/mv_barcode/barcode_generator/include/BarcodeOptions.h
index c6435500..2ebf4025 100644
--- a/mv_barcode/barcode_generator/include/BarcodeOptions.h
+++ b/mv_barcode/barcode_generator/include/BarcodeOptions.h
@@ -22,26 +22,22 @@
* @brief This file contains the Barcode options.
*/
-namespace MediaVision
-{
-namespace Barcode
-{
-
+namespace MediaVision {
+namespace Barcode {
/**
* @brief The Barcode type enumeration.
*
* @since_tizen 2.4
*/
-enum BarcodeType
-{
- BARCODE_QR = 58,
- BARCODE_UPCA = 34,
- BARCODE_UPCE = 37,
- BARCODE_EAN8 = 13,
- BARCODE_EAN13 = BARCODE_EAN8,
- BARCODE_CODE39 = 8,
- BARCODE_CODE128 = 20,
- BARCODE_INTERLEAVE_2_5 = 3
+enum BarcodeType {
+ BARCODE_QR = 58,
+ BARCODE_UPCA = 34,
+ BARCODE_UPCE = 37,
+ BARCODE_EAN8 = 13,
+ BARCODE_EAN13 = BARCODE_EAN8,
+ BARCODE_CODE39 = 8,
+ BARCODE_CODE128 = 20,
+ BARCODE_INTERLEAVE_2_5 = 3
};
/**
@@ -50,30 +46,27 @@ enum BarcodeType
* @since_tizen 2.4
* @remarks This is unavailable for 1D barcodes.
*/
-enum BarcodeQRErrorCorrectionLevel
-{
- BARCODE_QR_ECC_UNAVAILABLE = 0,
- BARCODE_QR_ECC_LOW = 1,
- BARCODE_QR_ECC_MEDIUM = 2,
- BARCODE_QR_ECC_QUARTILE = 3,
- BARCODE_QR_ECC_HIGH = 4
+enum BarcodeQRErrorCorrectionLevel {
+ BARCODE_QR_ECC_UNAVAILABLE = 0,
+ BARCODE_QR_ECC_LOW = 1,
+ BARCODE_QR_ECC_MEDIUM = 2,
+ BARCODE_QR_ECC_QUARTILE = 3,
+ BARCODE_QR_ECC_HIGH = 4
};
-
/**
* @brief The Barcode encoding mode enumeration.
*
* @since_tizen 2.4
* @remarks This is unavailable for 1D barcodes.
*/
-enum BarcodeQREncodingMode
-{
- BARCODE_QR_MODE_NUMERIC = 1,
- BARCODE_QR_MODE_ALPHANUMERIC = 1,
- BARCODE_QR_MODE_BYTE = 0,
- BARCODE_QR_MODE_UTF8 = 1,
- BARCODE_QR_MODE_KANJI = 3,
- BARCODE_QR_MODE_UNAVAILABLE
+enum BarcodeQREncodingMode {
+ BARCODE_QR_MODE_NUMERIC = 1,
+ BARCODE_QR_MODE_ALPHANUMERIC = 1,
+ BARCODE_QR_MODE_BYTE = 0,
+ BARCODE_QR_MODE_UTF8 = 1,
+ BARCODE_QR_MODE_KANJI = 3,
+ BARCODE_QR_MODE_UNAVAILABLE
};
/**
@@ -81,11 +74,10 @@ enum BarcodeQREncodingMode
*
* @since_tizen 2.4
*/
-enum BarcodeImageFormat
-{
- BARCODE_IMAGE_JPG,
- BARCODE_IMAGE_PNG,
- BARCODE_IMAGE_BMP
+enum BarcodeImageFormat {
+ BARCODE_IMAGE_JPG,
+ BARCODE_IMAGE_PNG,
+ BARCODE_IMAGE_BMP
};
/**
@@ -93,8 +85,7 @@ enum BarcodeImageFormat
*
* @since_tizen 2.4
*/
-enum BarcodeGenTextOpt
-{
+enum BarcodeGenTextOpt {
BARCODE_GEN_TEXT_INVISIBLE,
BARCODE_GEN_TEXT_VISIBLE
};
@@ -104,18 +95,17 @@ enum BarcodeGenTextOpt
*
* @since_tizen 2.4
*/
-enum BarcodeError
-{
- BARCODE_ERROR_NONE = 0,
- BARCODE_WARNING_INVALID_OPTION = 2,
- BARCODE_ERROR_TOO_LONG = 5,
- BARCODE_ERROR_INVALID_DATA = 6,
- BARCODE_ERROR_INVALID_CHECK = 7,
- BARCODE_ERROR_INVALID_OPTION = 8,
- BARCODE_ERROR_ENCODING_PROBLEM = 9,
- BARCODE_ERROR_FILE_ACCESS = 10,
- BARCODE_ERROR_MEMORY = 11,
- BARCODE_ERROR_INVALID_PATH =12,
+enum BarcodeError {
+ BARCODE_ERROR_NONE = 0,
+ BARCODE_WARNING_INVALID_OPTION = 2,
+ BARCODE_ERROR_TOO_LONG = 5,
+ BARCODE_ERROR_INVALID_DATA = 6,
+ BARCODE_ERROR_INVALID_CHECK = 7,
+ BARCODE_ERROR_INVALID_OPTION = 8,
+ BARCODE_ERROR_ENCODING_PROBLEM = 9,
+ BARCODE_ERROR_FILE_ACCESS = 10,
+ BARCODE_ERROR_MEMORY = 11,
+ BARCODE_ERROR_INVALID_PATH = 12,
};
} /* Barcode */
diff --git a/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h b/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h
index d3134ace..bb1e8b6b 100644
--- a/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h
+++ b/mv_barcode/barcode_generator/include/mv_barcode_generate_open.h
@@ -55,12 +55,12 @@ extern "C" {
* @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);
+ 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.
@@ -91,16 +91,16 @@ int mv_barcode_generate_source_open(mv_engine_config_h engine_cfg,
* @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);
+ 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
}
diff --git a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
index 624a3f51..522f65f0 100644
--- a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
+++ b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
@@ -28,277 +28,256 @@
#include <vector>
#include <unistd.h>
-namespace MediaVision
-{
-namespace Barcode
-{
-
-namespace
-{
+namespace MediaVision {
+namespace Barcode {
+namespace {
int getFormatEncodingInfo(
- BarcodeImageFormat imageFormat,
- std::vector<std::string>& extensions,
- std::vector<int>& compressionParams)
+ BarcodeImageFormat imageFormat,
+ std::vector<std::string>& extensions,
+ std::vector<int>& compressionParams)
{
- static const int PNGCompressionLevel = 3;
-
- compressionParams.clear();
- extensions.clear();
-
- switch (imageFormat)
- {
- case BARCODE_IMAGE_PNG:
- compressionParams.push_back(CV_IMWRITE_PNG_COMPRESSION);
- compressionParams.push_back(PNGCompressionLevel);
- extensions.push_back(".png");
- break;
- case BARCODE_IMAGE_JPG:
- extensions.push_back(".jpg");
- extensions.push_back(".jpeg");
- extensions.push_back(".jpe");
- break;
- case BARCODE_IMAGE_BMP:
- extensions.push_back(".bmp");
- extensions.push_back(".dib");
- break;
- default:
- return BARCODE_ERROR_INVALID_OPTION;
- }
- return BARCODE_ERROR_NONE;
+ static const int PNGCompressionLevel = 3;
+
+ compressionParams.clear();
+ extensions.clear();
+
+ switch (imageFormat) {
+ case BARCODE_IMAGE_PNG:
+ compressionParams.push_back(CV_IMWRITE_PNG_COMPRESSION);
+ compressionParams.push_back(PNGCompressionLevel);
+ extensions.push_back(".png");
+ break;
+ case BARCODE_IMAGE_JPG:
+ extensions.push_back(".jpg");
+ extensions.push_back(".jpeg");
+ extensions.push_back(".jpe");
+ break;
+ case BARCODE_IMAGE_BMP:
+ extensions.push_back(".bmp");
+ extensions.push_back(".dib");
+ break;
+ default:
+ return BARCODE_ERROR_INVALID_OPTION;
+ }
+ return BARCODE_ERROR_NONE;
}
int createBarcode(
- const std::string& message,
- BarcodeType type,
- BarcodeQREncodingMode encodingMode,
- BarcodeQRErrorCorrectionLevel correctionLevel,
- int qrVersion,
- int showText,
- zint_symbol *symbol)
+ const std::string& message,
+ BarcodeType type,
+ BarcodeQREncodingMode encodingMode,
+ BarcodeQRErrorCorrectionLevel correctionLevel,
+ int qrVersion,
+ int showText,
+ zint_symbol *symbol)
{
- // set input values
- symbol->symbology = type;
- symbol->input_mode = encodingMode;
- symbol->option_1 = correctionLevel;
- symbol->option_2 = qrVersion;
- symbol->scale = 1;
- symbol->show_hrt = showText;
-
- // set default values
- std::strncpy(symbol->fgcolour, "000000", 10);
- std::strncpy(symbol->bgcolour, "ffffff", 10);
- symbol->border_width = 1;
- symbol->height = 50;
-
- if (type == BARCODE_QR) {
- symbol->whitespace_width = 0;
- } else {
- symbol->whitespace_width = 10;
- }
-
- // create barcode
- const int rotationAngle = 0;
- int error = ZBarcode_Encode_and_Buffer(
- symbol,
- (unsigned char*)(message.c_str()),
- message.length(),
- rotationAngle);
-
- return error;
+ /* set input values */
+ symbol->symbology = type;
+ symbol->input_mode = encodingMode;
+ symbol->option_1 = correctionLevel;
+ symbol->option_2 = qrVersion;
+ symbol->scale = 1;
+ symbol->show_hrt = showText;
+
+ /* set default values */
+ std::strncpy(symbol->fgcolour, "000000", 10);
+ std::strncpy(symbol->bgcolour, "ffffff", 10);
+ symbol->border_width = 1;
+ symbol->height = 50;
+
+ if (type == BARCODE_QR) {
+ symbol->whitespace_width = 0;
+ } else {
+ symbol->whitespace_width = 10;
+ }
+
+ /* create barcode */
+ const int rotationAngle = 0;
+ int error = ZBarcode_Encode_and_Buffer(
+ symbol,
+ (unsigned char*)(message.c_str()),
+ message.length(),
+ rotationAngle);
+
+ return error;
}
int writeBufferToImageFile(
- zint_symbol *symbol,
- const std::string& imageFileName,
- BarcodeImageFormat imageFormat,
- const int imageWidth,
- const int imageHeight)
+ zint_symbol *symbol,
+ const std::string& imageFileName,
+ BarcodeImageFormat imageFormat,
+ const int imageWidth,
+ const int imageHeight)
{
- if (imageWidth <= 0 || imageHeight <= 0)
- {
- LOGE("Barcode image size is invalid: %i x %i. Terminate write to "
- "the image operation", imageWidth, imageHeight);
- return BARCODE_ERROR_INVALID_DATA;
- }
-
- /* find directory */
- std::string prefix_imageFileName = imageFileName.substr(0, imageFileName.find_last_of('/'));
- LOGD("prefix_path: %s", prefix_imageFileName.c_str());
-
- /* check the directory is available */
- if (access(prefix_imageFileName.c_str(),F_OK))
- {
- LOGE("Can't save barcode image to the path. The path[%s] doesn't existed.", prefix_imageFileName.c_str());
- return BARCODE_ERROR_INVALID_PATH;
- }
-
- // check current extension
- std::vector<std::string> expectedExtensions;
- std::vector<int> compressionParams;
-
- int error = getFormatEncodingInfo(imageFormat,
- expectedExtensions, compressionParams);
-
- if (BARCODE_ERROR_NONE != error || expectedExtensions.empty())
- {
- LOGE("Image format is incorrectly specified or not supported");
- return error;
- }
-
- bool rightExtensionFlag = false;
-
- std::string resultFilePath(imageFileName);
-
- for (size_t extNum = 0; extNum < expectedExtensions.size(); ++extNum)
- {
- if (resultFilePath.size() >= expectedExtensions[extNum].size())
- {
- std::string givenExtension = resultFilePath.substr(
- resultFilePath.length() - expectedExtensions[extNum].size(),
- expectedExtensions[extNum].size());
-
- std::transform(
- givenExtension.begin(), givenExtension.end(),
- givenExtension.begin(), ::tolower);
-
- if (givenExtension == expectedExtensions[extNum])
- {
- rightExtensionFlag = true;
- break;
- }
- }
- }
-
- if (!rightExtensionFlag)
- {
- resultFilePath += expectedExtensions[0];
- }
-
- 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);
-
- error = cv::imwrite(resultFilePath, image, compressionParams) ?
- BARCODE_ERROR_NONE : BARCODE_ERROR_INVALID_DATA;
-
- if (BARCODE_ERROR_NONE != error)
- {
- LOGE("Write barcode image to file %s operation failed.",
- resultFilePath.c_str());
- return error;
- }
-
- return error;
+ if (imageWidth <= 0 || imageHeight <= 0) {
+ LOGE("Barcode image size is invalid: %i x %i. Terminate write to "
+ "the image operation", imageWidth, imageHeight);
+ return BARCODE_ERROR_INVALID_DATA;
+ }
+
+ /* find directory */
+ std::string prefix_imageFileName = imageFileName.substr(0, imageFileName.find_last_of('/'));
+ LOGD("prefix_path: %s", prefix_imageFileName.c_str());
+
+ /* check the directory is available */
+ if (access(prefix_imageFileName.c_str(), F_OK)) {
+ LOGE("Can't save barcode image to the path. The path[%s] doesn't existed.", prefix_imageFileName.c_str());
+ return BARCODE_ERROR_INVALID_PATH;
+ }
+
+ /* check current extension */
+ std::vector<std::string> expectedExtensions;
+ std::vector<int> compressionParams;
+
+ int error = getFormatEncodingInfo(imageFormat,
+ expectedExtensions, compressionParams);
+
+ if (BARCODE_ERROR_NONE != error || expectedExtensions.empty()) {
+ LOGE("Image format is incorrectly specified or not supported");
+ return error;
+ }
+
+ bool rightExtensionFlag = false;
+
+ std::string resultFilePath(imageFileName);
+
+ for (size_t extNum = 0; extNum < expectedExtensions.size(); ++extNum) {
+ if (resultFilePath.size() >= expectedExtensions[extNum].size()) {
+ std::string givenExtension = resultFilePath.substr(
+ resultFilePath.length() - expectedExtensions[extNum].size(),
+ expectedExtensions[extNum].size());
+
+ std::transform(
+ givenExtension.begin(), givenExtension.end(),
+ givenExtension.begin(), ::tolower);
+
+ if (givenExtension == expectedExtensions[extNum]) {
+ rightExtensionFlag = true;
+ break;
+ }
+ }
+ }
+
+ if (!rightExtensionFlag) {
+ resultFilePath += expectedExtensions[0];
+ }
+
+ 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);
+
+ error = cv::imwrite(resultFilePath, image, compressionParams) ?
+ BARCODE_ERROR_NONE : BARCODE_ERROR_INVALID_DATA;
+
+ if (BARCODE_ERROR_NONE != error) {
+ LOGE("Write barcode image to file %s operation failed.",
+ resultFilePath.c_str());
+ return error;
+ }
+
+ return error;
}
} /* anonymous namespace */
int BarcodeGenerator::generateBarcodeToImage(
- const std::string& imageFileName,
- BarcodeImageFormat imageFormat,
- const int imageWidth,
- const int imageHeight,
- const std::string& message,
- BarcodeType type,
- BarcodeQREncodingMode encodingMode,
- BarcodeQRErrorCorrectionLevel correctionLevel,
- int qrVersion,
- int showText)
+ const std::string& imageFileName,
+ BarcodeImageFormat imageFormat,
+ const int imageWidth,
+ const int imageHeight,
+ const std::string& message,
+ BarcodeType type,
+ BarcodeQREncodingMode encodingMode,
+ BarcodeQRErrorCorrectionLevel correctionLevel,
+ int qrVersion,
+ int showText)
{
- 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,
- symbol);
-
- if (error != BARCODE_ERROR_NONE)
- {
- LOGE("Barcode creation failed, clean memory");
- ZBarcode_Delete(symbol);
- return error;
- }
-
- error = writeBufferToImageFile(
- symbol,
- imageFileName,
- imageFormat,
- imageWidth,
- imageHeight);
- 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(symbol);
-
- return error;
+ 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,
+ symbol);
+
+ if (error != BARCODE_ERROR_NONE) {
+ LOGE("Barcode creation failed, clean memory");
+ ZBarcode_Delete(symbol);
+ return error;
+ }
+
+ error = writeBufferToImageFile(
+ symbol,
+ imageFileName,
+ imageFormat,
+ imageWidth,
+ imageHeight);
+ 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(symbol);
+
+ return error;
}
int BarcodeGenerator::generateBarcodeToBuffer(
- unsigned char **imageBuffer,
- unsigned int *imageWidth,
- unsigned int *imageHeight,
- unsigned int *imageChannels,
- const std::string& message,
- BarcodeType type,
- BarcodeQREncodingMode encodingMode,
- BarcodeQRErrorCorrectionLevel correctionLevel,
- int qrVersion,
- int showText)
+ unsigned char **imageBuffer,
+ unsigned int *imageWidth,
+ unsigned int *imageHeight,
+ unsigned int *imageChannels,
+ const std::string& message,
+ BarcodeType type,
+ BarcodeQREncodingMode encodingMode,
+ BarcodeQRErrorCorrectionLevel correctionLevel,
+ int qrVersion,
+ int showText)
{
- 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,
- symbol);
-
- if (error != BARCODE_ERROR_NONE)
- {
- LOGE("Barcode creation failed, clean memory");
- ZBarcode_Delete(symbol);
- return error;
- }
-
- // fill output buffer
- *imageWidth = symbol->bitmap_width;
- *imageHeight = symbol->bitmap_height;
- *imageChannels = 3;
- const unsigned int imageBufferSize = (*imageWidth) * (*imageHeight) * (*imageChannels);
- *imageBuffer = new unsigned char [imageBufferSize];
- memmove(*imageBuffer, symbol->bitmap, imageBufferSize);
-
- LOGI("Barcode buffer has been successfully generated, clean memory");
- ZBarcode_Delete(symbol);
-
- return BARCODE_ERROR_NONE;
+ 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,
+ symbol);
+
+ if (error != BARCODE_ERROR_NONE) {
+ LOGE("Barcode creation failed, clean memory");
+ ZBarcode_Delete(symbol);
+ return error;
+ }
+
+ /* fill output buffer */
+ *imageWidth = symbol->bitmap_width;
+ *imageHeight = symbol->bitmap_height;
+ *imageChannels = 3;
+ const unsigned int imageBufferSize = (*imageWidth) * (*imageHeight) * (*imageChannels);
+ *imageBuffer = new unsigned char[imageBufferSize];
+ memmove(*imageBuffer, symbol->bitmap, imageBufferSize);
+
+ LOGI("Barcode buffer has been successfully generated, clean memory");
+ ZBarcode_Delete(symbol);
+
+ return BARCODE_ERROR_NONE;
}
} /* Barcode */
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 19657d3e..44c68b22 100644
--- a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp
+++ b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp
@@ -26,353 +26,326 @@
using namespace MediaVision::Barcode;
-namespace
-{
-
+namespace {
int alphanumToUpper(std::string& strToTransform)
{
- std::string tempString = strToTransform;
- std::transform(tempString.begin(), tempString.end(),
- tempString.begin(), ::toupper);
-
- if (std::string::npos != tempString.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"))
- {
- LOGE("Barcode message can't be converted according to support "
- "alphanumeric (0..9, A..Z, space, $, %, *, +, -, ., /, :) "
- "mode: %s", strToTransform.c_str());
- return BARCODE_ERROR_INVALID_DATA;
- }
-
- LOGI("Barcode message was converted according to support alphanumeric "
- "mode: %s -> %s", strToTransform.c_str(), tempString.c_str());
- strToTransform = tempString;
- return BARCODE_ERROR_NONE;
+ std::string tempString = strToTransform;
+ std::transform(tempString.begin(), tempString.end(),
+ tempString.begin(), ::toupper);
+
+ if (std::string::npos != tempString.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:")) {
+ LOGE("Barcode message can't be converted according to support "
+ "alphanumeric (0..9, A..Z, space, $, %, *, +, -, ., /, :) "
+ "mode: %s", strToTransform.c_str());
+ return BARCODE_ERROR_INVALID_DATA;
+ }
+
+ LOGI("Barcode message was converted according to support alphanumeric "
+ "mode: %s -> %s", strToTransform.c_str(), tempString.c_str());
+ strToTransform = tempString;
+ return BARCODE_ERROR_NONE;
}
BarcodeType convertBarcodeType(mv_barcode_type_e type)
{
- BarcodeType barcodeType = BARCODE_QR;
- switch (type)
- {
- case MV_BARCODE_UPC_A:
- barcodeType = BARCODE_UPCA;
- break;
- case MV_BARCODE_UPC_E:
- barcodeType = BARCODE_UPCE;
- break;
- case MV_BARCODE_EAN_8:
- barcodeType = BARCODE_EAN8;
- break;
- case MV_BARCODE_EAN_13:
- barcodeType = BARCODE_EAN13;
- break;
- case MV_BARCODE_CODE128:
- barcodeType = BARCODE_CODE128;
- break;
- case MV_BARCODE_CODE39:
- barcodeType = BARCODE_CODE39;
- break;
- case MV_BARCODE_I2_5:
- barcodeType = BARCODE_INTERLEAVE_2_5;
- break;
- default:
- break;
- }
-
- LOGI("Media vision barcode type has been converted to ZInt barcode type "
- "(%i -> %i)", type, barcodeType);
- return barcodeType;
+ BarcodeType barcodeType = BARCODE_QR;
+ switch (type) {
+ case MV_BARCODE_UPC_A:
+ barcodeType = BARCODE_UPCA;
+ break;
+ case MV_BARCODE_UPC_E:
+ barcodeType = BARCODE_UPCE;
+ break;
+ case MV_BARCODE_EAN_8:
+ barcodeType = BARCODE_EAN8;
+ break;
+ case MV_BARCODE_EAN_13:
+ barcodeType = BARCODE_EAN13;
+ break;
+ case MV_BARCODE_CODE128:
+ barcodeType = BARCODE_CODE128;
+ break;
+ case MV_BARCODE_CODE39:
+ barcodeType = BARCODE_CODE39;
+ break;
+ case MV_BARCODE_I2_5:
+ barcodeType = BARCODE_INTERLEAVE_2_5;
+ break;
+ default:
+ break;
+ }
+
+ LOGI("Media vision barcode type has been converted to ZInt barcode type "
+ "(%i -> %i)", type, barcodeType);
+ return barcodeType;
}
BarcodeQREncodingMode convertEncodingMode(mv_barcode_qr_mode_e mode)
{
- BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_ALPHANUMERIC;
-
- switch (mode)
- {
- case MV_BARCODE_QR_MODE_NUMERIC:
- encodingMode = BARCODE_QR_MODE_NUMERIC;
- break;
- case MV_BARCODE_QR_MODE_BYTE:
- encodingMode = BARCODE_QR_MODE_BYTE;
- break;
- case MV_BARCODE_QR_MODE_UTF8:
- encodingMode = BARCODE_QR_MODE_UTF8;
- break;
- default:
- break;
- }
-
- LOGI("Media vision QRCode encoding mode has been converted to "
- "ZInt encoding mode (%i -> %i)", mode, encodingMode);
- return encodingMode;
+ BarcodeQREncodingMode encodingMode = BARCODE_QR_MODE_ALPHANUMERIC;
+
+ switch (mode) {
+ case MV_BARCODE_QR_MODE_NUMERIC:
+ encodingMode = BARCODE_QR_MODE_NUMERIC;
+ break;
+ case MV_BARCODE_QR_MODE_BYTE:
+ encodingMode = BARCODE_QR_MODE_BYTE;
+ break;
+ case MV_BARCODE_QR_MODE_UTF8:
+ encodingMode = BARCODE_QR_MODE_UTF8;
+ break;
+ default:
+ break;
+ }
+
+ LOGI("Media vision QRCode encoding mode has been converted to "
+ "ZInt encoding mode (%i -> %i)", mode, encodingMode);
+ return encodingMode;
}
BarcodeQRErrorCorrectionLevel convertECC(mv_barcode_qr_ecc_e ecc)
{
- BarcodeQRErrorCorrectionLevel ecclevel = BARCODE_QR_ECC_LOW;
-
- switch (ecc)
- {
- case MV_BARCODE_QR_ECC_MEDIUM:
- ecclevel = BARCODE_QR_ECC_MEDIUM;
- break;
- case MV_BARCODE_QR_ECC_QUARTILE:
- ecclevel = BARCODE_QR_ECC_QUARTILE;
- break;
- case MV_BARCODE_QR_ECC_HIGH:
- ecclevel = BARCODE_QR_ECC_HIGH;
- break;
- default:
- break;
- }
-
- LOGI("Media vision ECC level has been converted to "
- "ZInt ECC level (%i -> %i)", ecc, ecclevel);
- return ecclevel;
+ BarcodeQRErrorCorrectionLevel ecclevel = BARCODE_QR_ECC_LOW;
+
+ switch (ecc) {
+ case MV_BARCODE_QR_ECC_MEDIUM:
+ ecclevel = BARCODE_QR_ECC_MEDIUM;
+ break;
+ case MV_BARCODE_QR_ECC_QUARTILE:
+ ecclevel = BARCODE_QR_ECC_QUARTILE;
+ break;
+ case MV_BARCODE_QR_ECC_HIGH:
+ ecclevel = BARCODE_QR_ECC_HIGH;
+ break;
+ default:
+ break;
+ }
+
+ LOGI("Media vision ECC level has been converted to "
+ "ZInt ECC level (%i -> %i)", ecc, ecclevel);
+ return ecclevel;
}
int convertBarcodeError(int barcodeError)
{
- int mvError = MEDIA_VISION_ERROR_NONE;
-
- switch (barcodeError)
- {
- case BARCODE_WARNING_INVALID_OPTION:
- mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
- break;
- case BARCODE_ERROR_TOO_LONG:
- mvError = MEDIA_VISION_ERROR_MSG_TOO_LONG;
- break;
- case BARCODE_ERROR_INVALID_DATA:
- mvError = MEDIA_VISION_ERROR_INVALID_DATA;
- break;
- case BARCODE_ERROR_INVALID_CHECK:
- mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
- break;
- case BARCODE_ERROR_INVALID_OPTION:
- mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
- break;
- case BARCODE_ERROR_ENCODING_PROBLEM:
- mvError = MEDIA_VISION_ERROR_INTERNAL;
- break;
- case BARCODE_ERROR_FILE_ACCESS:
- mvError = MEDIA_VISION_ERROR_PERMISSION_DENIED;
- break;
- case BARCODE_ERROR_MEMORY:
- mvError = MEDIA_VISION_ERROR_OUT_OF_MEMORY;
- break;
- case BARCODE_ERROR_INVALID_PATH:
- mvError = MEDIA_VISION_ERROR_INVALID_PATH;
- default:
- break;
- }
-
- LOGI("ZInt error code has been converted to the media vision error code "
- "(%i -> (0x%08x))", barcodeError, mvError);
- return mvError;
+ int mvError = MEDIA_VISION_ERROR_NONE;
+
+ switch (barcodeError) {
+ case BARCODE_WARNING_INVALID_OPTION:
+ mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ break;
+ case BARCODE_ERROR_TOO_LONG:
+ mvError = MEDIA_VISION_ERROR_MSG_TOO_LONG;
+ break;
+ case BARCODE_ERROR_INVALID_DATA:
+ mvError = MEDIA_VISION_ERROR_INVALID_DATA;
+ break;
+ case BARCODE_ERROR_INVALID_CHECK:
+ mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ break;
+ case BARCODE_ERROR_INVALID_OPTION:
+ mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ break;
+ case BARCODE_ERROR_ENCODING_PROBLEM:
+ mvError = MEDIA_VISION_ERROR_INTERNAL;
+ break;
+ case BARCODE_ERROR_FILE_ACCESS:
+ mvError = MEDIA_VISION_ERROR_PERMISSION_DENIED;
+ break;
+ case BARCODE_ERROR_MEMORY:
+ mvError = MEDIA_VISION_ERROR_OUT_OF_MEMORY;
+ break;
+ case BARCODE_ERROR_INVALID_PATH:
+ mvError = MEDIA_VISION_ERROR_INVALID_PATH;
+ default:
+ break;
+ }
+
+ LOGI("ZInt error code has been converted to the media vision error code "
+ "(%i -> (0x%08x))", barcodeError, mvError);
+ 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;
+ 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;
}
} /* anonymous namespace */
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)
+ 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)
{
- std::string messageStr = std::string(message);
-
- if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC &&
- messageStr.find_first_not_of("0123456789") != std::string::npos)
- {
- LOGE("Barcode message can't be used according to support "
- "numeric (0..9) mode: %s", messageStr.c_str());
- return MEDIA_VISION_ERROR_INVALID_DATA;
- }
-
- int error = BARCODE_ERROR_NONE;
- if (MV_BARCODE_QR == type &&
- MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode)
- {
- error = alphanumToUpper(messageStr);
- if (BARCODE_ERROR_NONE != error)
- {
- return convertBarcodeError(error);
- }
- }
-
- unsigned char *imageBuffer = NULL;
- unsigned int imageWidth = 0u;
- unsigned int imageHeight = 0u;
- 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;
- }
-
- 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;
- }
-
- error = BarcodeGenerator::generateBarcodeToBuffer(
- &imageBuffer,
- &imageWidth,
- &imageHeight,
- &imageChannels,
- messageStr,
- convertBarcodeType(type),
- convertEncodingMode(qr_enc_mode),
- convertECC(qr_ecc),
- qr_version,
- showText);
-
- if (error != BARCODE_ERROR_NONE)
- {
- LOGE("Barcode generation to the buffer failed");
- if (NULL != imageBuffer)
- {
- LOGI("Delete temporal buffer");
- delete[] imageBuffer;
- }
- return convertBarcodeError(error);
- }
-
- const unsigned int imageBufferSize = imageWidth * imageHeight * imageChannels;
-
- LOGI("Barcode has been generated to the buffer: "
- "Buffer size = %ui x %ui; Channels = %ui; Message = %s",
- imageWidth, imageHeight, imageChannels, messageStr.c_str());
-
- error = mv_source_fill_by_buffer_c(
- image,
- imageBuffer,
- imageBufferSize,
- imageWidth,
- imageHeight,
- MEDIA_VISION_COLORSPACE_RGB888);
-
- if (error != MEDIA_VISION_ERROR_NONE)
- {
- LOGE("Meidiavision source fill by generated buffer failed");
- }
-
- if (NULL != imageBuffer)
- {
- LOGI("Delete temporal buffer");
- delete[] imageBuffer;
- }
-
- return error;
+ std::string messageStr = std::string(message);
+
+ if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC &&
+ messageStr.find_first_not_of("0123456789") != std::string::npos) {
+ LOGE("Barcode message can't be used according to support "
+ "numeric (0..9) mode: %s", messageStr.c_str());
+ return MEDIA_VISION_ERROR_INVALID_DATA;
+ }
+
+ int error = BARCODE_ERROR_NONE;
+ if (MV_BARCODE_QR == type &&
+ MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode) {
+ error = alphanumToUpper(messageStr);
+ if (BARCODE_ERROR_NONE != error) {
+ return convertBarcodeError(error);
+ }
+ }
+
+ unsigned char *imageBuffer = NULL;
+ unsigned int imageWidth = 0u;
+ unsigned int imageHeight = 0u;
+ 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;
+ }
+
+ 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;
+ }
+
+ error = BarcodeGenerator::generateBarcodeToBuffer(
+ &imageBuffer,
+ &imageWidth,
+ &imageHeight,
+ &imageChannels,
+ messageStr,
+ convertBarcodeType(type),
+ convertEncodingMode(qr_enc_mode),
+ convertECC(qr_ecc),
+ qr_version,
+ showText);
+
+ if (error != BARCODE_ERROR_NONE) {
+ LOGE("Barcode generation to the buffer failed");
+ if (NULL != imageBuffer) {
+ LOGI("Delete temporal buffer");
+ delete[] imageBuffer;
+ }
+ return convertBarcodeError(error);
+ }
+
+ const unsigned int imageBufferSize = imageWidth * imageHeight * imageChannels;
+
+ LOGI("Barcode has been generated to the buffer: "
+ "Buffer size = %ui x %ui; Channels = %ui; Message = %s",
+ imageWidth, imageHeight, imageChannels, messageStr.c_str());
+
+ error = mv_source_fill_by_buffer_c(
+ image,
+ imageBuffer,
+ imageBufferSize,
+ imageWidth,
+ imageHeight,
+ MEDIA_VISION_COLORSPACE_RGB888);
+
+ if (error != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Meidiavision source fill by generated buffer failed");
+ }
+
+ if (NULL != imageBuffer) {
+ LOGI("Delete temporal buffer");
+ delete[] imageBuffer;
+ }
+
+ 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)
+ 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 = std::string(message);
-
- if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC &&
- messageStr.find_first_not_of("0123456789") != std::string::npos)
- {
- LOGE("Barcode message can't be used according to support "
- "numeric (0..9) mode: %s", messageStr.c_str());
- return MEDIA_VISION_ERROR_INVALID_DATA;
- }
-
- if (NULL == image_path)
- {
- LOGE("Can't save barcode image to the path[%p]. The path has to be specified", image_path);
- return MEDIA_VISION_ERROR_INVALID_PATH;
- }
-
- int error = BARCODE_ERROR_NONE;
- if (MV_BARCODE_QR == type &&
- MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode)
- {
- error = alphanumToUpper(messageStr);
- if (BARCODE_ERROR_NONE != error)
- {
- return convertBarcodeError(error);
- }
- }
-
- 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;
- }
-
- 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;
- }
-
- 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);
-
- 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);
+ std::string messageStr = std::string(message);
+
+ if (qr_enc_mode == MV_BARCODE_QR_MODE_NUMERIC &&
+ messageStr.find_first_not_of("0123456789") != std::string::npos) {
+ LOGE("Barcode message can't be used according to support "
+ "numeric (0..9) mode: %s", messageStr.c_str());
+ return MEDIA_VISION_ERROR_INVALID_DATA;
+ }
+
+ if (NULL == image_path) {
+ LOGE("Can't save barcode image to the path[%p]. The path has to be specified", image_path);
+ return MEDIA_VISION_ERROR_INVALID_PATH;
+ }
+
+ int error = BARCODE_ERROR_NONE;
+ if (MV_BARCODE_QR == type &&
+ MV_BARCODE_QR_MODE_ALPHANUMERIC == qr_enc_mode) {
+ error = alphanumToUpper(messageStr);
+ if (BARCODE_ERROR_NONE != error) {
+ return convertBarcodeError(error);
+ }
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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);
+
+ 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);
}
-
diff --git a/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h b/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h
index 2076b0c1..2fbd9352 100644
--- a/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h
+++ b/mv_barcode/barcode_generator_lic/include/mv_barcode_generate_lic.h
@@ -55,13 +55,13 @@ extern "C" {
* @see mv_barcode_generate_image_lic()
*/
int mv_barcode_generate_source_lic(
- 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);
+ 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.
@@ -89,16 +89,16 @@ int mv_barcode_generate_source_lic(
* @see mv_barcode_generate_source_lic()
*/
int mv_barcode_generate_image_lic(
- 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);
+ 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
}
diff --git a/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c b/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c
index d57621fc..fada9e79 100644
--- a/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c
+++ b/mv_barcode/barcode_generator_lic/src/mv_barcode_generate_lic.c
@@ -17,29 +17,28 @@
#include "mv_barcode_generate_lic.h"
int mv_barcode_generate_source_lic(
- 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)
+ 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)
{
- return MEDIA_VISION_ERROR_NOT_SUPPORTED;;
+ return MEDIA_VISION_ERROR_NOT_SUPPORTED;;
}
int mv_barcode_generate_image_lic(
- 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)
+ 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)
{
- return MEDIA_VISION_ERROR_NOT_SUPPORTED;
+ return MEDIA_VISION_ERROR_NOT_SUPPORTED;
}
-