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]);
- } else {
- mm_util_error("[infile] file open [%s]", filename);
- mm_util_stderror("file open failed");
- return MM_UTIL_ERROR_NO_SUCH_FILE;
- }
+ mm_util_debug("#START# libjpeg fmt [%d]", fmt);
+ 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) {
+ unsigned int res_w = 0;
+ unsigned int res_h = 0;
+ size_t res_buffer_size = 0;
+ unsigned char *dst = NULL;
- fseek(fp, 0, SEEK_SET);
+ 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);
- 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_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, MM_UTIL_COLOR_YUV420, downscale, decoded);
- 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 = dst;
- decoded->size = res_buffer_size;
- }
- } else {
- ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded);
+ MMUTIL_SAFE_FREE(decoded->data);
+
+ decoded->data = dst;
+ decoded->size = res_buffer_size;
}
-#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;
+ ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded);
}
+ 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);
mm_util_safe_fclose(fp);