MM_UTIL_JPEG_MEM,
} mm_util_jpeg_cont_format_e;
-static int __mm_image_encode_with_libjpeg(mm_util_jpeg_cont_format_e control_format, void *rawdata, int width, int height, mm_util_color_format_e color_format, int quality, FILE *fp, void **mem, size_t *csize)
+static gboolean __is_supported_color_format_with_libjpeg(mm_util_color_format_e color_format)
+{
+ gboolean _bool = FALSE;
+
+ if (color_format == MM_UTIL_COLOR_RGB24 ||
+ color_format == MM_UTIL_COLOR_RGBA ||
+ color_format == MM_UTIL_COLOR_BGRA ||
+ color_format == MM_UTIL_COLOR_ARGB ||
+ color_format == MM_UTIL_COLOR_YUV420 ||
+ color_format == MM_UTIL_COLOR_YUV422 ||
+ color_format == MM_UTIL_COLOR_UYVY ||
+ color_format == MM_UTIL_COLOR_GRAYSCALE) {
+ _bool = TRUE;
+ }
+
+ if (!_bool)
+ mm_util_error("not supported color format %d", color_format);
+
+ return _bool;
+}
+
+static gboolean _mm_util_is_supported_color_format(mm_util_color_format_e color_format)
+{
+ gboolean _bool = FALSE;
+
+ if (__is_supported_color_format_with_libjpeg(color_format) ||
+ color_format == MM_UTIL_COLOR_NV12) {
+ _bool = TRUE;
+ }
+
+ if (!_bool)
+ mm_util_error("not supported color format %d", color_format);
+
+ return _bool;
+}
+
+static int __mm_image_encode_with_libjpeg(mm_util_jpeg_cont_format_e control_format, void *rawdata, unsigned int width, unsigned int height, mm_util_color_format_e color_format, int quality, FILE *fp, void **mem, size_t *csize)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
else if (color_format == MM_UTIL_COLOR_RGB24 || color_format == MM_UTIL_COLOR_GRAYSCALE || color_format == MM_UTIL_COLOR_RGBA || color_format == MM_UTIL_COLOR_BGRA || color_format == MM_UTIL_COLOR_ARGB) {
JSAMPROW row_pointer[1];
- int iRowStride = 0;
+ unsigned int iRowStride = 0;
if (color_format == MM_UTIL_COLOR_RGB24) {
cinfo.input_components = 3;
mm_util_retvm_if(decoded->data == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src data");
mm_util_retvm_if((decoded->width <= 0) || (decoded->height <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width[%d] height[%d]", decoded->width, decoded->height);
mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(decoded->format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", decoded->format);
+ mm_util_retvm_if((!_mm_util_is_supported_color_format(decoded->format)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", decoded->format);
mm_util_retvm_if((quality < 1) || (quality > 100), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid quality [%d]", quality);
mm_util_debug("#START# LIBJPEG");
unsigned char *dst = NULL;
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_COLOR_NV12, MM_UTIL_COLOR_YUV420, &dst, &res_w, &res_h, &res_buffer_size);
- ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, dst, decoded->width, decoded->height, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL);
+ ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, dst, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL);
MMUTIL_SAFE_FREE(dst);
- } else if (decoded->format == MM_UTIL_COLOR_NV21) {
- mm_util_error("Not supported format NV12");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
-
} else {
ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, decoded->data, decoded->width, decoded->height, decoded->format, quality, fp, NULL, NULL);
}
mm_util_retvm_if(decoded->data == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src data");
mm_util_retvm_if((decoded->width <= 0) || (decoded->height <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width[%d] height[%d]", decoded->width, decoded->height);
mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(decoded->format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", decoded->format);
+ mm_util_retvm_if((!_mm_util_is_supported_color_format(decoded->format)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", decoded->format);
mm_util_retvm_if((quality < 1) || (quality > 100), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid quality [%d]", quality);
mm_util_debug("#START# libjpeg");
unsigned char *dst = NULL;
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_COLOR_NV12, MM_UTIL_COLOR_YUV420, &dst, &res_w, &res_h, &res_buffer_size);
- ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, dst, decoded->width, decoded->height, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size);
+ ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, dst, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size);
MMUTIL_SAFE_FREE(dst);
- } else if (decoded->format == MM_UTIL_COLOR_NV21) {
- return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
} else {
ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, decoded->data, decoded->width, decoded->height, decoded->format, quality, NULL, mem, size);
}
mm_util_retvm_if(decoded == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded");
mm_util_retvm_if(filename == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid filename");
mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(fmt) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", fmt);
+ mm_util_retvm_if((!_mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt);
if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
&& (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
mm_util_retvm_if(decoded == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded");
mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid filename");
mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(fmt) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", fmt);
+ mm_util_retvm_if((!_mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt);
if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
&& (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {