#ifndef __MM_UTIL_TYPE_H__
#define __MM_UTIL_TYPE_H__
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
* 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;
/**
*/
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 {
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;
}
#endif
-#endif /*__MM_UTIL_TYPE_H__*/
+#endif /*__MM_UTIL_TYPE_H__*/
#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)
{
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;
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;
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;
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;