mv_barcode: Clean duplicate parameter checker 74/304474/9
authorKwanghoon Son <k.son@samsung.com>
Thu, 18 Jan 2024 02:04:04 +0000 (11:04 +0900)
committerInki Dae <inki.dae@samsung.com>
Wed, 24 Jan 2024 06:40:34 +0000 (06:40 +0000)
Move check position and rename MEDIA_VISION_CHECK_ERR

Change-Id: I1b911b4ad341bc348ceea01f281209f54bb7ed20
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_barcode/barcode_generator/src/BarcodeGenerator.cpp
mv_barcode/barcode_generator/src/mv_barcode_generate.cpp
mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp
mv_common/include/mv_private.h
mv_common/src/CommonUtils.cpp
mv_image/image/src/mv_image_open.cpp
mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp
mv_surveillance/surveillance/src/EventManager.cpp
mv_surveillance/surveillance/src/SurveillanceHelper.cpp

index f32eeaf..bd1657e 100644 (file)
@@ -234,13 +234,6 @@ static int __draw_logo(cv::Mat &image, Common::EngineConfig *engineCfg)
 static int __write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, BarcodeImageFormat imageFormat,
                                                                 const int imageWidth, const int imageHeight, Common::EngineConfig *engineCfg)
 {
-       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());
index 73624a2..7e95534 100644 (file)
 static const char *feature_keys[] = { "http://tizen.org/feature/vision.barcode_generation" };
 static const size_t num_keys = sizeof(feature_keys) / sizeof(char *);
 
-int mv_barcode_generate_source(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 __check_barcode_param(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)
 {
-       MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, false));
        MEDIA_VISION_NULL_ARG_CHECK(message);
-       MEDIA_VISION_INSTANCE_CHECK(image);
-
-       MEDIA_VISION_FUNCTION_ENTER();
-
        if (type < MV_BARCODE_QR || type >= MV_BARCODE_UNKNOWN || type == MV_BARCODE_UNDEFINED) {
                LOGE("Not supported barcode type [%d]", type);
                return MEDIA_VISION_ERROR_INVALID_PARAMETER;
        }
-
        if (type == MV_BARCODE_QR) {
                if (qr_enc_mode < MV_BARCODE_QR_MODE_NUMERIC || qr_enc_mode >= MV_BARCODE_QR_MODE_UNAVAILABLE) {
                        LOGE("Not supported QR encoding mode[%d]", qr_enc_mode);
                        return MEDIA_VISION_ERROR_INVALID_PARAMETER;
                }
-
                if (qr_ecc < MV_BARCODE_QR_ECC_LOW || qr_ecc >= MV_BARCODE_QR_ECC_UNAVAILABLE) {
                        LOGE("Not supported QR ECC level [%d]", qr_ecc);
                        return MEDIA_VISION_ERROR_INVALID_PARAMETER;
@@ -62,6 +54,17 @@ int mv_barcode_generate_source(mv_engine_config_h engine_cfg, const char *messag
                        return MEDIA_VISION_ERROR_INVALID_PARAMETER;
                }
        }
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_barcode_generate_source(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)
+{
+       MEDIA_VISION_FUNCTION_ENTER();
+       MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, false));
+       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);
@@ -74,42 +77,19 @@ int mv_barcode_generate_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, const char *image_path, mv_barcode_image_format_e image_format)
 {
-       MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, false));
-       MEDIA_VISION_NULL_ARG_CHECK(message);
-
        MEDIA_VISION_FUNCTION_ENTER();
-
-       if (image_path == NULL) {
-               LOGE("image_path is NULL");
-               return MEDIA_VISION_ERROR_INVALID_PATH;
-       }
-
-       if (type < MV_BARCODE_QR || type >= MV_BARCODE_UNKNOWN || type == MV_BARCODE_UNDEFINED) {
-               LOGE("Not supported barcode type [%d]", type);
-               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
-       }
-
-       if (type == MV_BARCODE_QR) {
-               if (qr_enc_mode < MV_BARCODE_QR_MODE_NUMERIC || qr_enc_mode >= MV_BARCODE_QR_MODE_UNAVAILABLE) {
-                       LOGE("Not supported QR encoding mode[%d]", qr_enc_mode);
-                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
-               }
-
-               if (qr_ecc < MV_BARCODE_QR_ECC_LOW || qr_ecc >= MV_BARCODE_QR_ECC_UNAVAILABLE) {
-                       LOGE("Not supported QR ECC level [%d]", qr_ecc);
-                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
-               }
-
-               if (qr_version < 1 || qr_version > 40) {
-                       LOGE("Not supported QR version [%d]", qr_version);
-                       return MEDIA_VISION_ERROR_INVALID_PARAMETER;
-               }
-       }
-
+       MEDIA_VISION_SUPPORT_CHECK(mv_check_feature_key(feature_keys, num_keys, false));
+       MEDIA_VISION_CHECK_ERR(__check_barcode_param(message, type, qr_enc_mode, qr_ecc, qr_version), "Invalid parameter");
+       MEDIA_VISION_NULL_ARG_CHECK(image_path);
        if (image_format < MV_BARCODE_IMAGE_FORMAT_BMP || image_format >= MV_BARCODE_IMAGE_FORMAT_NUM) {
                LOGE("Not supported image format [%d]", image_format);
                return MEDIA_VISION_ERROR_INVALID_PARAMETER;
        }
+       if (image_width <= 0 || image_height <= 0) {
+               LOGE("Barcode image size is invalid: %d x %d. Terminate write to the image operation", image_width,
+                        image_height);
+               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,
index 0515f10..16dee22 100644 (file)
@@ -338,11 +338,6 @@ int mv_barcode_generate_image_open(mv_engine_config_h engine_cfg, const char *me
                                                                   mv_barcode_qr_ecc_e qr_ecc, int qr_version, const char *image_path,
                                                                   mv_barcode_image_format_e image_format)
 {
-       if (!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;
-       }
-
        std::string messageStr;
        int error = prepareMessageToGenerate(message, type, qr_enc_mode, messageStr);
        if (error != MEDIA_VISION_ERROR_NONE) {
index 06ac898..93813db 100644 (file)
@@ -34,7 +34,7 @@ extern "C" {
 
 #define MEDIA_VISION_FUNCTION_LEAVE() LOGI("[%s] <LEAVE>", __FUNCTION__)
 
-#define MEDIA_VISION_ASSERT(function, msg)           \
+#define MEDIA_VISION_CHECK_ERR(function, msg)        \
        do {                                             \
                int error_code = function;                   \
                if (error_code != MEDIA_VISION_ERROR_NONE) { \
index 4937dfb..b57f23e 100644 (file)
@@ -34,10 +34,10 @@ int convertSourceMV2GrayCV(mv_source_h mvSource, cv::Mat &cvSource)
 
        mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
 
-       MEDIA_VISION_ASSERT(mv_source_get_width(mvSource, &width), "Failed to get the width.");
-       MEDIA_VISION_ASSERT(mv_source_get_height(mvSource, &height), "Failed to get the height.");
-       MEDIA_VISION_ASSERT(mv_source_get_colorspace(mvSource, &colorspace), "Failed to get the colorspace.");
-       MEDIA_VISION_ASSERT(mv_source_get_buffer(mvSource, &buffer, &bufferSize), "Failed to get the buffer size.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_width(mvSource, &width), "Failed to get the width.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_height(mvSource, &height), "Failed to get the height.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_colorspace(mvSource, &colorspace), "Failed to get the colorspace.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_buffer(mvSource, &buffer, &bufferSize), "Failed to get the buffer size.");
 
        int conversionType;
        switch (colorspace) {
index b8a207a..8f732ea 100644 (file)
@@ -259,7 +259,7 @@ int mv_image_recognize_open(mv_source_h source, const mv_image_object_h *image_o
        MEDIA_VISION_NULL_ARG_CHECK(recognized_cb);
 
        cv::Mat scene;
-       MEDIA_VISION_ASSERT(MediaVision::Common::convertSourceMV2GrayCV(source, scene), "Failed to convert mv_source.");
+       MEDIA_VISION_CHECK_ERR(MediaVision::Common::convertSourceMV2GrayCV(source, scene), "Failed to convert mv_source.");
 
        int ret = MEDIA_VISION_ERROR_NONE;
 
@@ -325,7 +325,7 @@ int mv_image_track_open(mv_source_h source, mv_image_tracking_model_h image_trac
        extractTrackingParams(engine_cfg, trackingParams);
 
        cv::Mat frame;
-       MEDIA_VISION_ASSERT(MediaVision::Common::convertSourceMV2GrayCV(source, frame), "Failed to convert mv_source.");
+       MEDIA_VISION_CHECK_ERR(MediaVision::Common::convertSourceMV2GrayCV(source, frame), "Failed to convert mv_source.");
 
        MediaVision::Image::ImageTrackingModel *trackingModel =
                        (MediaVision::Image::ImageTrackingModel *) image_tracking_model;
@@ -374,7 +374,7 @@ int mv_image_object_fill_open(mv_image_object_h image_object, mv_engine_config_h
        MEDIA_VISION_INSTANCE_CHECK(source);
 
        cv::Mat image;
-       MEDIA_VISION_ASSERT(MediaVision::Common::convertSourceMV2GrayCV(source, image), "Failed to convert mv_source.");
+       MEDIA_VISION_CHECK_ERR(MediaVision::Common::convertSourceMV2GrayCV(source, image), "Failed to convert mv_source.");
 
        std::vector<cv::Point2f> roi;
        if (NULL != location) {
index 38e2649..50c6e57 100644 (file)
@@ -148,10 +148,10 @@ int mv_roi_tracker_perform_open(mv_roi_tracker_h handle, mv_source_h source, mv_
        unsigned char *buffer = NULL;
        mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
 
-       MEDIA_VISION_ASSERT(mv_source_get_width(source, &width), "Failed to get the width.");
-       MEDIA_VISION_ASSERT(mv_source_get_height(source, &height), "Failed to get the height.");
-       MEDIA_VISION_ASSERT(mv_source_get_colorspace(source, &colorspace), "Failed to get the colorspace.");
-       MEDIA_VISION_ASSERT(mv_source_get_buffer(source, &buffer, &bufferSize), "Failed to get the buffer size.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_width(source, &width), "Failed to get the width.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_height(source, &height), "Failed to get the height.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_colorspace(source, &colorspace), "Failed to get the colorspace.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_buffer(source, &buffer, &bufferSize), "Failed to get the buffer size.");
 
        LOGD(" w: %d, h: %d, c: %d", width, height, channels);
        try {
index 4948cf3..5c9165d 100644 (file)
@@ -231,9 +231,9 @@ int EventManager::pushSource(mv_source_h source, int videoStreamId)
        unsigned int height = 0;
        mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
 
-       MEDIA_VISION_ASSERT(mv_source_get_width(source, &width), "Failed to get the width.");
-       MEDIA_VISION_ASSERT(mv_source_get_height(source, &height), "Failed to get the height.");
-       MEDIA_VISION_ASSERT(mv_source_get_colorspace(source, &colorspace), "Failed to get the colorspace.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_width(source, &width), "Failed to get the width.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_height(source, &height), "Failed to get the height.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_colorspace(source, &colorspace), "Failed to get the colorspace.");
 
        cv::Mat grayImage;
 
index f1351db..ce2c21c 100644 (file)
@@ -38,10 +38,10 @@ int SurveillanceHelper::convertSourceMVRGB2GrayCVNeon(mv_source_h mvSource, cv::
 
        mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
 
-       MEDIA_VISION_ASSERT(mv_source_get_width(mvSource, &width), "Failed to get the width.");
-       MEDIA_VISION_ASSERT(mv_source_get_height(mvSource, &height), "Failed to get the height.");
-       MEDIA_VISION_ASSERT(mv_source_get_colorspace(mvSource, &colorspace), "Failed to get the colorspace.");
-       MEDIA_VISION_ASSERT(mv_source_get_buffer(mvSource, &src, &bufferSize), "Failed to get the buffer size.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_width(mvSource, &width), "Failed to get the width.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_height(mvSource, &height), "Failed to get the height.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_colorspace(mvSource, &colorspace), "Failed to get the colorspace.");
+       MEDIA_VISION_CHECK_ERR(mv_source_get_buffer(mvSource, &src, &bufferSize), "Failed to get the buffer size.");
 
        if (colorspace != MEDIA_VISION_COLORSPACE_RGB888) {
                LOGE("Error: mv_source has unsupported colorspace.");