return ret;
}
-static int __mm_util_jpeg_convert_colorspace(mm_util_image_h image, mm_util_image_h *converted)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_image_info_s *_image = (mm_image_info_s *)image;
- unsigned int dst_w = 0, dst_h = 0;
- unsigned char *dst_data = NULL;
- size_t dst_data_size = 0;
-
- ret = mm_util_convert_colorspace(_image->data, _image->width, _image->height, MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NV12, &dst_data, &dst_w, &dst_h, &dst_data_size);
- mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to mm_util_convert_colorspace [%d]", ret);
-
- return mm_image_create_image(dst_w, dst_h, MM_UTIL_COLOR_NV12, dst_data, dst_data_size, converted);
-}
-
int mm_util_jpeg_encode_to_file(mm_image_info_s *decoded, int quality, const char *filename)
{
int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s *_converted_image = NULL;
mm_util_fenter();
mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_safe_fopen fail (%d)", ret);
if (decoded->color == MM_UTIL_COLOR_NV12) {
- unsigned int res_w = 0;
- unsigned int res_h = 0;
- size_t res_buffer_size = 0;
- 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, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL);
-
- MMUTIL_SAFE_FREE(dst);
+ ret = mm_util_convert_colorspace(decoded, MM_UTIL_COLOR_YUV420, (mm_util_image_h *)&_converted_image);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ mm_util_error("mm_util_convert_image failed (%d)", ret);
+ mm_util_safe_fclose(fp);
+ return ret;
+ }
+ ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, _converted_image->data, _converted_image->width, _converted_image->height, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL);
+ mm_image_destroy_image(_converted_image);
} else {
ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, decoded->data, decoded->width, decoded->height, decoded->color, quality, fp, NULL, NULL);
}
mm_util_retvm_if(size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size");
- decoded.width = (unsigned long)width;
- decoded.height = (unsigned long)height;
+ decoded.width = width;
+ decoded.height = height;
decoded.color = color;
decoded.data = src;
int mm_util_encode_to_jpeg_memory(mm_image_info_s *decoded, int quality, void **mem, size_t *size)
{
int ret = MM_UTIL_ERROR_NONE;
+ mm_image_info_s *_converted_image = NULL;
mm_util_fenter();
mm_util_debug("#START# libjpeg");
if (decoded->color == MM_UTIL_COLOR_NV12) {
- unsigned int res_w = 0;
- unsigned int res_h = 0;
- size_t res_buffer_size = 0;
- 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, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size);
-
- MMUTIL_SAFE_FREE(dst);
+ ret = mm_util_convert_colorspace(decoded, MM_UTIL_COLOR_YUV420, (mm_util_image_h *)&_converted_image);
+ mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_convert_image fail (%d)", ret);
+ ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, _converted_image->data, _converted_image->width, _converted_image->height, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size);
+ mm_image_destroy_image(_converted_image);
} else {
ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, decoded->data, decoded->width, decoded->height, decoded->color, quality, NULL, mem, size);
}
if (fmt == MM_UTIL_COLOR_NV12) {
ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, MM_UTIL_COLOR_YUV420, downscale, &_decoded);
if (ret == MM_UTIL_ERROR_NONE)
- ret = __mm_util_jpeg_convert_colorspace(_decoded, decoded);
+ ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded);
mm_image_destroy_image(_decoded);
} else {
ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded);
if (fmt == MM_UTIL_COLOR_NV12) {
ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_MEM, NULL, memory, src_size, MM_UTIL_COLOR_YUV420, downscale, &_decoded);
if (ret == MM_UTIL_ERROR_NONE)
- ret = __mm_util_jpeg_convert_colorspace(_decoded, decoded);
+ ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded);
mm_image_destroy_image(_decoded);
} else {
ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_MEM, NULL, memory, src_size, fmt, downscale, decoded);