*/
int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, void *src, int width, int height, mm_util_color_format_e fmt, int quality);
-
-/**
- * This function extracts yuv data from jpeg file
- *
- * @param decoded [out] pointer of output stream pointer, that is, pointer of encoded jpeg stream pointer. After using it, please free the allocated memory.
- * @param filename [in] input file name, encoded stream file
- * @param fmt [in] color format
- * @return This function returns zero on success, or negative value with error code.
- * @remark
- * @see mm_util_jpeg_yuv_data, mm_util_color_format_e
- * @since R1, 1.0
- */
-int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_color_format_e fmt);
-
-
-/**
- * This function extracts yuv data from jpeg buffer
- *
- * @param decoded [out] pointer of output stream pointer, that is, pointer of encoded jpeg stream pointer. After using it, please free the allocated memory.
- * @param src [in] input stream pointer(pointer of encoded jpeg stream data)
- * @param size [in] size of input stream(size of pointer of encoded jpeg stream data)
- * @param fmt [in] color format
- * @return This function returns zero on success, or negative value with error code.
- * @remark
- * @see mm_util_jpeg_yuv_data, mm_util_color_format_e
- * @since R1, 1.0
- */
-int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_color_format_e fmt);
-
/**
* This function extracts yuv data from jpeg file with downscale decode option
*
return ret;
}
-int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_color_format_e fmt)
-{
- int ret = MM_UTIL_ERROR_NONE;
-
- mm_util_fenter();
-
- 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);
-
- FILE *fp = NULL;
- ret = mm_util_safe_fopen(filename, "rb", &fp);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("mm_util_safe_fopen failed (%d)", ret);
- return ret;
- }
-
- unsigned char magic[2] = {0};
- size_t read_size = 0;
- if (fp) {
- read_size = fread((void *)magic, 1, 2, fp);
- if (read_size > 0)
- mm_util_debug("Success fread");
-
- mm_util_debug("%x %x", magic[0], magic[1]);
- mm_util_safe_fclose(fp);
- } else {
- mm_util_error("[infile] file open [%s]", filename);
- mm_util_stderror("file open failed");
- return MM_UTIL_ERROR_NO_SUCH_FILE;
- }
-
- if (magic[0] == 0xff && magic[1] == 0xd8) {
-#ifdef LIBJPEG_TURBO
- mm_util_debug("#START# LIBJPEG_TURBO");
- ret = __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
-#else
- mm_util_debug("#START# libjpeg(fmt:%d)", fmt);
- if (fmt == MM_UTIL_COLOR_NV12) {
- ret = __mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_COLOR_YUV420, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1);
- if (ret == MM_UTIL_ERROR_NONE) {
- 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_YUV420, MM_UTIL_COLOR_NV12, &dst, &res_w, &res_h, &res_buffer_size);
-
- MMUTIL_SAFE_FREE(decoded->data);
-
- decoded->data = calloc(1, res_buffer_size);
- if (decoded->data == NULL) {
- mm_util_debug("memory allocation failed");
- MMUTIL_SAFE_FREE(dst);
- return MM_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- memcpy(decoded->data, dst, res_buffer_size);
- decoded->size = (unsigned int)res_buffer_size;
-
- MMUTIL_SAFE_FREE(dst);
- }
- } else {
- ret = __mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1);
- }
-#endif
- mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u", decoded->data, decoded->width, decoded->height, decoded->size);
- mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
- } else if (magic[0] == 0x47 && magic[1] == 0x49) {
- mm_util_error("Not JPEG IMAGE - GIF");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if (magic[0] == 0x89 && magic[1] == 0x50) {
- mm_util_error("Not JPEG IMAGE - PNG");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if (magic[0] == 0x49 && magic[1] == 0x49) {
- mm_util_error("Not JPEG IMAGE - TIFF");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else {
- mm_util_error("Not JPEG IMAGE");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
-
- mm_util_fleave();
-
- return ret;
-}
-
-int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, void *src, unsigned int size, mm_util_color_format_e fmt)
-{
- int ret = MM_UTIL_ERROR_NONE;
-
- mm_util_fenter();
-
- 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 src");
- mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(fmt) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", fmt);
-
-#ifdef LIBJPEG_TURBO
- mm_util_debug("#START# libjpeg");
- ret = __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(decoded, src, size, fmt);
-#else
- mm_util_debug("#START# libjpeg");
- if (fmt == MM_UTIL_COLOR_NV12) {
- ret = __mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, MM_UTIL_COLOR_YUV420, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1);
- if (ret == MM_UTIL_ERROR_NONE) {
- 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_YUV420, MM_UTIL_COLOR_NV12, &dst, &res_w, &res_h, &res_buffer_size);
-
- MMUTIL_SAFE_FREE(decoded->data);
-
- decoded->data = calloc(1, res_buffer_size);
- if (decoded->data == NULL) {
- mm_util_debug("memory allocation failed");
- MMUTIL_SAFE_FREE(dst);
- return MM_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- memcpy(decoded->data, dst, res_buffer_size);
- decoded->size = (unsigned int)res_buffer_size;
-
- MMUTIL_SAFE_FREE(dst);
- }
- } else {
- ret = __mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1);
- }
-#endif
- mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %u", decoded->data, decoded->width, decoded->height, decoded->size);
- mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
-
- return ret;
-}
-
int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_color_format_e fmt, mm_util_jpeg_decode_downscale downscale)
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_debug("#START# LIBJPEG_TURBO");
ret = __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
#else
- mm_util_debug("#START# libjpeg");
+ mm_util_debug("#START# libjpeg fmt [%d]", fmt);
if (fmt == MM_UTIL_COLOR_NV12) {
ret = __mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_COLOR_YUV420, downscale);
if (ret == MM_UTIL_ERROR_NONE) {
MMUTIL_SAFE_FREE(dst);
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
+
memcpy(decoded->data, dst, res_buffer_size);
decoded->size = (unsigned int)res_buffer_size;