Refactoring option validity check 39/273939/9
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 18 Apr 2022 11:37:20 +0000 (20:37 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 22 Apr 2022 06:03:44 +0000 (15:03 +0900)
Change-Id: I2c52e90639fb1766e808c85143c1c9592e42ed29

common/include/mm_util_type.h
common/mm_util_option.c
packaging/libmm-utility.spec

index 3846d2a..a800d39 100755 (executable)
@@ -22,6 +22,8 @@
 #ifndef __MM_UTIL_TYPE_H__
 #define __MM_UTIL_TYPE_H__
 
+#include <stddef.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,12 +34,12 @@ typedef void *mm_util_image_h;
  * error type
  */
 typedef enum {
-       MM_UTIL_ERROR_NONE =              0,       /**< Successful */
-       MM_UTIL_ERROR_INVALID_PARAMETER = -1,      /**< Invalid parameter */
-       MM_UTIL_ERROR_OUT_OF_MEMORY = -2,          /**< Out of memory */
-       MM_UTIL_ERROR_NO_SUCH_FILE  = -3,                  /**< No such file */
-       MM_UTIL_ERROR_INVALID_OPERATION = -4,      /**< Internal error */
-       MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT = -5,   /**< Not supported format */
+       MM_UTIL_ERROR_NONE                 =  0, /**< Successful */
+       MM_UTIL_ERROR_INVALID_PARAMETER    = -1, /**< Invalid parameter */
+       MM_UTIL_ERROR_OUT_OF_MEMORY        = -2, /**< Out of memory */
+       MM_UTIL_ERROR_NO_SUCH_FILE         = -3, /**< No such file */
+       MM_UTIL_ERROR_INVALID_OPERATION    = -4, /**< Internal error */
+       MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT = -5, /**< Not supported format */
 } mm_util_error_e;
 
 /**
@@ -45,46 +47,46 @@ typedef enum {
  */
 typedef enum {
        /* YUV planar format */
-       MM_UTIL_COLOR_YUV420,                   /**< YUV420 format - planer YV12*/
-       MM_UTIL_COLOR_YUV422,                   /**< YUV422 format - planer */
-       MM_UTIL_COLOR_I420,                             /**< YUV420 format - planar */
-       MM_UTIL_COLOR_NV12,                             /**< NV12 format - planer */
+       MM_UTIL_COLOR_YUV420,     /**< YUV420 format - planer YV12*/
+       MM_UTIL_COLOR_YUV422,     /**< YUV422 format - planer */
+       MM_UTIL_COLOR_I420,       /**< YUV420 format - planar */
+       MM_UTIL_COLOR_NV12,       /**< NV12 format - planer */
 
        /* YUV packed format */
-       MM_UTIL_COLOR_UYVY,                             /**< UYVY format - YUV packed format */
-       MM_UTIL_COLOR_YUYV,                             /**< YUYV format - YUV packed format */
+       MM_UTIL_COLOR_UYVY,       /**< UYVY format - YUV packed format */
+       MM_UTIL_COLOR_YUYV,       /**< YUYV format - YUV packed format */
 
        /* RGB color */
-       MM_UTIL_COLOR_RGB16,            /**< RGB565 pixel format */
-       MM_UTIL_COLOR_RGB24,                    /**< RGB888 pixel format */
-       MM_UTIL_COLOR_ARGB,                             /**< ARGB8888 pixel format */
+       MM_UTIL_COLOR_RGB16,      /**< RGB565 pixel format */
+       MM_UTIL_COLOR_RGB24,      /**< RGB888 pixel format */
+       MM_UTIL_COLOR_ARGB,       /**< ARGB8888 pixel format */
 
-       MM_UTIL_COLOR_BGRA,                             /**< BGRA8888 pixel format */
-       MM_UTIL_COLOR_RGBA,                             /**< RGBA8888 pixel format */
-       MM_UTIL_COLOR_BGRX,                             /**< BGRX8888 pixel format */
+       MM_UTIL_COLOR_BGRA,       /**< BGRA8888 pixel format */
+       MM_UTIL_COLOR_RGBA,       /**< RGBA8888 pixel format */
+       MM_UTIL_COLOR_BGRX,       /**< BGRX8888 pixel format */
 
        /* non-standard format */
-       MM_UTIL_COLOR_NV12_TILED,               /**< Customized color format in s5pc110 */
-       MM_UTIL_COLOR_NV16,                             /**< NV16 pixel format */
-       MM_UTIL_COLOR_NV61,                             /**< NV61 pixel format */
-       MM_UTIL_COLOR_NV21,                     /**< NV21 format - planer */
+       MM_UTIL_COLOR_NV12_TILED, /**< Customized color format in s5pc110 */
+       MM_UTIL_COLOR_NV16,       /**< NV16 pixel format */
+       MM_UTIL_COLOR_NV61,       /**< NV61 pixel format */
+       MM_UTIL_COLOR_NV21,       /**< NV21 format - planer */
 
        /* GrayScale */
-       MM_UTIL_COLOR_GRAYSCALE,                /**< Grayscale pixel format */
-       MM_UTIL_COLOR_NUM,                              /**< Number of image formats */
+       MM_UTIL_COLOR_GRAYSCALE,  /**< Grayscale pixel format */
+       MM_UTIL_COLOR_NUM,        /**< Number of image formats */
 } mm_util_color_format_e;
 
 /**
  * Image rotation types
  */
 typedef enum {
-       MM_UTIL_ROTATE_0,               /**< Rotation 0 degree - no effect */
-       MM_UTIL_ROTATE_90,              /**< Rotation 90 degree */
-       MM_UTIL_ROTATE_180,             /**< Rotation 180 degree */
-       MM_UTIL_ROTATE_270,             /**< Rotation 270 degree */
-       MM_UTIL_ROTATE_FLIP_HORZ,       /**< Flip horizontal */
-       MM_UTIL_ROTATE_FLIP_VERT,       /**< Flip vertial */
-       MM_UTIL_ROTATE_NUM              /**< Number of rotation types */
+       MM_UTIL_ROTATE_0,         /**< Rotation 0 degree - no effect */
+       MM_UTIL_ROTATE_90,        /**< Rotation 90 degree */
+       MM_UTIL_ROTATE_180,       /**< Rotation 180 degree */
+       MM_UTIL_ROTATE_270,       /**< Rotation 270 degree */
+       MM_UTIL_ROTATE_FLIP_HORZ, /**< Flip horizontal */
+       MM_UTIL_ROTATE_FLIP_VERT, /**< Flip vertial */
+       MM_UTIL_ROTATE_NUM        /**< Number of rotation types */
 } mm_util_rotate_type_e;
 
 typedef enum {
@@ -94,7 +96,7 @@ typedef enum {
        IMG_CODEC_BMP,
        IMG_CODEC_WEBP,
        IMG_CODEC_JPEGXL,
-       IMG_CODEC_WBMP = 100,           // used by only media-content
+       IMG_CODEC_WBMP, /* Note: used by only media-content */
        IMG_CODEC_UNKNOWN_TYPE,
 } mm_util_img_codec_type;
 
@@ -117,4 +119,4 @@ typedef struct {
 }
 #endif
 
-#endif   /*__MM_UTIL_TYPE_H__*/
+#endif /*__MM_UTIL_TYPE_H__*/
index c898423..2ab9764 100755 (executable)
 #include "mm_util_private.h"
 #include "mm_util_option.h"
 
-#define DEFAULT_PNG_COMPRESSION 6
+#define PNG_COMPRESSION_DEFAULT 6
+#define PNG_COMPRESSION_MAX 9
+
+typedef struct _valid_options {
+       bool codec;
+       bool compression; /* ToDo: handle compression value */
+       bool lossless;
+} valid_options_t;
+
+static valid_options_t validator[] = {
+       [IMG_CODEC_JPEG] = { true, false, false },
+       [IMG_CODEC_PNG] = { true, true, false },
+       [IMG_CODEC_GIF] = { true, false, false },
+       [IMG_CODEC_BMP] = { true, false, false },
+       [IMG_CODEC_WEBP] = { true, false, true },
+       [IMG_CODEC_JPEGXL] = { true, false, true },
+       [IMG_CODEC_WBMP] = { true, false, false },
+       [IMG_CODEC_UNKNOWN_TYPE] = { false, false, false },
+};
 
 int mm_util_enc_opt_create(mm_util_enc_opt_h *enc_opt)
 {
@@ -29,7 +47,7 @@ int mm_util_enc_opt_create(mm_util_enc_opt_h *enc_opt)
 
        enc_option = g_new0(mm_util_enc_opt_t, 1);
        enc_option->codec = IMG_CODEC_UNKNOWN_TYPE;
-       enc_option->compression = DEFAULT_PNG_COMPRESSION;
+       enc_option->compression = PNG_COMPRESSION_DEFAULT;
        enc_option->lossless = false;
 
        *enc_opt = enc_option;
@@ -42,7 +60,8 @@ int mm_util_enc_opt_set_codec(mm_util_enc_opt_h enc_opt, mm_util_img_codec_type
        mm_util_enc_opt_t *enc_option = (mm_util_enc_opt_t *)enc_opt;
 
        mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
-       mm_util_retvm_if(codec >= IMG_CODEC_WBMP, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid codec [%d]", codec);
+       mm_util_retvm_if(!validator[codec].codec, MM_UTIL_ERROR_INVALID_PARAMETER,
+                                       "invalid codec [%d]", codec);
 
        enc_option->codec = codec;
 
@@ -54,8 +73,10 @@ int mm_util_enc_opt_set_png_compression(mm_util_enc_opt_h enc_opt, unsigned int
        mm_util_enc_opt_t *enc_option = (mm_util_enc_opt_t *)enc_opt;
 
        mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
-       mm_util_retvm_if(compression > 9, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid compression [%d]", compression);
-       mm_util_retvm_if(enc_option->codec != IMG_CODEC_PNG, MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format [%d]", enc_option->codec);
+       mm_util_retvm_if(!validator[enc_option->codec].compression, MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT,
+                                       "not supported format [%d]", enc_option->codec);
+       mm_util_retvm_if(compression > PNG_COMPRESSION_MAX, MM_UTIL_ERROR_INVALID_PARAMETER,
+                                       "invalid compression [%d]", compression);
 
        enc_option->compression = compression;
 
@@ -67,7 +88,8 @@ int mm_util_enc_opt_set_lossless(mm_util_enc_opt_h enc_opt, bool lossless)
        mm_util_enc_opt_t *enc_option = (mm_util_enc_opt_t *)enc_opt;
 
        mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
-       mm_util_retvm_if(enc_option->codec != IMG_CODEC_WEBP && enc_option->codec != IMG_CODEC_JPEGXL, MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format [%d]", enc_option->codec);
+       mm_util_retvm_if(!validator[enc_option->codec].lossless, MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT,
+                                       "not supported format [%d]", enc_option->codec);
 
        enc_option->lossless = lossless;
 
index e3fbc34..68c9ea4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.4.0
+Version:    0.4.1
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0