unsigned char *data = NULL;
unsigned char *dst = NULL;
unsigned long long src_size = 0;
- int image_type = -1;
int encode_image_type = -1;
if (argc < 4) {
fprintf(stderr, "\t[usage]\n");
- fprintf(stderr, "\t\t1. decode : mm_util_png_testsuite decode image_type filepath encode_image_type\n");
+ fprintf(stderr, "\t\t1. decode : mm_util_png_testsuite decode filepath encode_image_type\n");
return 0;
}
- image_type = atoi(argv[2]);
- if(argv[4])
- encode_image_type = atoi(argv[4]);
- else
- encode_image_type = atoi(argv[2]);
+ if(argv[3])
+ encode_image_type = atoi(argv[3]);
if (!strcmp("decode", argv[1]) || !strcmp("decode-mem", argv[1]) || !strcmp("decode-async", argv[1])) {
- ret = image_util_decode_create(image_type, &decoded);
+ ret = image_util_decode_create(&decoded);
if (ret != IMAGE_UTIL_ERROR_NONE)
return 0;
if (!strcmp("decode", argv[1])) {
- ret = image_util_decode_set_input_path(decoded, argv[3]);
+ ret = image_util_decode_set_input_path(decoded, argv[2]);
if (ret != IMAGE_UTIL_ERROR_NONE)
return 0;
} else {
- if (_read_file(argv[3], &src, &src_size)) {
+ if (_read_file(argv[2], &src, &src_size)) {
ret = image_util_decode_set_input_buffer(decoded, (unsigned char *)src, src_size);
if (ret != IMAGE_UTIL_ERROR_NONE)
return 0;
return err;
}
-int image_util_decode_create(image_util_type_e image_type, image_util_decode_h * handle)
+int image_util_decode_create(image_util_decode_h * handle)
{
int err = MM_UTIL_ERROR_NONE;
decode_encode_s *_handle = (decode_encode_s *) calloc(1, sizeof(decode_encode_s));
image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
- _handle->image_type = image_type;
_handle->src_buffer = NULL;
_handle->dst_buffer = NULL;
_handle->path = NULL;
_handle->image_h = 0;
_handle->is_decode = TRUE;
+ _handle->image_type = -1;
+
+ *handle = (image_util_decode_h) _handle;
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+static char _JPEG_HEADER[] = { 0xFF, 0xD8 };
+static char _PNG_HEADER[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+static char _GIF_HEADER[] = { 'G', 'I', 'F' };
+static char _BMP_HEADER[] = { 'B', 'M' };
+
+static int _image_util_decode_create_image_handle(image_util_decode_h handle, const unsigned char *src_buffer)
+{
+ image_util_type_e image_type = -1;
+ static struct
+ {
+ char* header;
+ int size;
+ image_util_type_e image_type;
+ } image_header[] = {
+ { _JPEG_HEADER, sizeof(_JPEG_HEADER), IMAGE_UTIL_JPEG },
+ { _PNG_HEADER, sizeof(_PNG_HEADER), IMAGE_UTIL_PNG },
+ { _GIF_HEADER, sizeof(_GIF_HEADER), IMAGE_UTIL_GIF },
+ { _BMP_HEADER, sizeof(_BMP_HEADER), IMAGE_UTIL_BMP },
+ };
+ unsigned int i = 0;
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (src_buffer == NULL) {
+ image_util_error("Invalid input buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ for (i = 0; i < sizeof(image_header)/sizeof(image_header[0]); i++)
+ {
+ if (strncmp((const char *)src_buffer, image_header[i].header, image_header[i].size) == 0)
+ {
+ image_type = image_header[i].image_type;
+ break;
+ }
+ }
+
+ _handle->image_type = image_type;
switch (image_type) {
case IMAGE_UTIL_JPEG:
err = _image_util_decode_create_bmp_handle(_handle);
break;
default:
- err = MM_UTIL_ERROR_INVALID_PARAMETER;
+ err = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
break;
}
return _convert_image_util_error_code(__func__, err);
}
- *handle = (image_util_decode_h) _handle;
-
return _convert_image_util_error_code(__func__, err);
}
{
int err = IMAGE_UTIL_ERROR_NONE;
decode_encode_s *_handle = (decode_encode_s *) handle;
+ FILE *fp = NULL;
+ unsigned char *src_buffer = NULL;
if (_handle == NULL || _handle->is_decode == FALSE) {
image_util_error("Invalid Handle");
if (_handle->src_buffer)
_handle->src_buffer = NULL;
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ image_util_error("File open failed");
+ return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
+ }
+ src_buffer = (void *)malloc(sizeof(_PNG_HEADER));
+ if (!fread(src_buffer, 1, sizeof(_PNG_HEADER), fp)) {
+ image_util_error("File read failed");
+ fclose(fp);
+ fp = NULL;
+ free(src_buffer);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ err = _image_util_decode_create_image_handle(_handle, src_buffer);
+
+ fclose(fp);
+ fp = NULL;
+ free(src_buffer);
+
_handle->path = path;
return err;
if (_handle->path)
_handle->path = NULL;
+ err = _image_util_decode_create_image_handle(_handle, src_buffer);
+
_handle->src_buffer = (void *)src_buffer;
_handle->src_size = src_size;
}
break;
default:
- err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
break;
}