diff options
author | Kwanghoon Son <k.son@samsung.com> | 2024-01-18 11:04:04 +0900 |
---|---|---|
committer | Inki Dae <inki.dae@samsung.com> | 2024-01-24 06:40:34 +0000 |
commit | ad22fa5003a703b49fa6efaa434d446b423a68ef (patch) | |
tree | 0011169b1e817ffda0a04792c8467c41e8ad16be | |
parent | 37fb4002c49c706ce2534fb76b59361c319f409e (diff) | |
download | mediavision-ad22fa5003a703b49fa6efaa434d446b423a68ef.tar.gz mediavision-ad22fa5003a703b49fa6efaa434d446b423a68ef.tar.bz2 mediavision-ad22fa5003a703b49fa6efaa434d446b423a68ef.zip |
mv_barcode: Clean duplicate parameter checker
Move check position and rename MEDIA_VISION_CHECK_ERR
Change-Id: I1b911b4ad341bc348ceea01f281209f54bb7ed20
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
-rw-r--r-- | mv_barcode/barcode_generator/src/BarcodeGenerator.cpp | 7 | ||||
-rw-r--r-- | mv_barcode/barcode_generator/src/mv_barcode_generate.cpp | 62 | ||||
-rw-r--r-- | mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp | 5 | ||||
-rw-r--r-- | mv_common/include/mv_private.h | 2 | ||||
-rw-r--r-- | mv_common/src/CommonUtils.cpp | 8 | ||||
-rw-r--r-- | mv_image/image/src/mv_image_open.cpp | 6 | ||||
-rw-r--r-- | mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp | 8 | ||||
-rw-r--r-- | mv_surveillance/surveillance/src/EventManager.cpp | 6 | ||||
-rw-r--r-- | mv_surveillance/surveillance/src/SurveillanceHelper.cpp | 8 |
9 files changed, 40 insertions, 72 deletions
diff --git a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp index f32eeaf3..bd1657e3 100644 --- a/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp +++ b/mv_barcode/barcode_generator/src/BarcodeGenerator.cpp @@ -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()); diff --git a/mv_barcode/barcode_generator/src/mv_barcode_generate.cpp b/mv_barcode/barcode_generator/src/mv_barcode_generate.cpp index 73624a2a..7e95534c 100644 --- a/mv_barcode/barcode_generator/src/mv_barcode_generate.cpp +++ b/mv_barcode/barcode_generator/src/mv_barcode_generate.cpp @@ -31,27 +31,19 @@ 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, 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 0515f108..16dee223 100644 --- a/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp +++ b/mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp @@ -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) { diff --git a/mv_common/include/mv_private.h b/mv_common/include/mv_private.h index 06ac898c..93813db2 100644 --- a/mv_common/include/mv_private.h +++ b/mv_common/include/mv_private.h @@ -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) { \ diff --git a/mv_common/src/CommonUtils.cpp b/mv_common/src/CommonUtils.cpp index 4937dfbc..b57f23e7 100644 --- a/mv_common/src/CommonUtils.cpp +++ b/mv_common/src/CommonUtils.cpp @@ -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) { diff --git a/mv_image/image/src/mv_image_open.cpp b/mv_image/image/src/mv_image_open.cpp index b8a207a1..8f732ea6 100644 --- a/mv_image/image/src/mv_image_open.cpp +++ b/mv_image/image/src/mv_image_open.cpp @@ -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) { diff --git a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp index 38e2649d..50c6e579 100644 --- a/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp +++ b/mv_roi_tracker/roi_tracker/src/mv_roi_tracker_open.cpp @@ -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 { diff --git a/mv_surveillance/surveillance/src/EventManager.cpp b/mv_surveillance/surveillance/src/EventManager.cpp index 4948cf32..5c9165dc 100644 --- a/mv_surveillance/surveillance/src/EventManager.cpp +++ b/mv_surveillance/surveillance/src/EventManager.cpp @@ -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; diff --git a/mv_surveillance/surveillance/src/SurveillanceHelper.cpp b/mv_surveillance/surveillance/src/SurveillanceHelper.cpp index f1351db2..ce2c21cd 100644 --- a/mv_surveillance/surveillance/src/SurveillanceHelper.cpp +++ b/mv_surveillance/surveillance/src/SurveillanceHelper.cpp @@ -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."); |