Code refactoring for 'mm_util_extract_image_info' 13/237213/13 accepted/tizen/unified/20200702.141801 submit/tizen/20200701.023736
authorjiyong.min <jiyong.min@samsung.com>
Fri, 26 Jun 2020 03:47:54 +0000 (12:47 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 30 Jun 2020 23:27:54 +0000 (08:27 +0900)
Change-Id: I1024be716a81e647e4820d649ecf4cba5d6b509f

magick/mm_util_info.c
packaging/libmm-utility.spec

index 0e6d998..a9d60e1 100644 (file)
 #include "mm_util_private.h"
 #include "mm_util_magick.h"
 
-#define                MINIMUM_HEADER_BYTES    8
-
-#define                PNG_HEADER_LENGTH       8
-#define                JPG_HEADER_LENGTH       2
-#define                GIF_HEADER_LENGTH       3
-#define                BMP_HEADER_LENGTH       2
-#define                WBMP_HEADER_LENGTH      2
+#define                MINIMUM_HEADER_BYTES    12
 
 #define                JPG_HEADER_TYPE_LENGTH 2
 #define                JPG_BLOCK_SIZE_LENGTH 2
 #define                JPG_IMAGE_SIZE_LENGTH 8
 
-#define                FILE_READ_SIZE          4096
+#define                READ_JPEG_SIZE          6
+#define                READ_PNG_SIZE           12
+#define                READ_BMP_SIZE           14
+
+typedef struct {
+       unsigned char *signature;
+       unsigned int len;
+       unsigned int offset;
+} image_signature_t;
 
 static unsigned char gIfegPNGHeader[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
 static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 };
@@ -43,208 +45,296 @@ static unsigned char gIfegGIFHeader[] = { "GIF" };
 static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
 static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
 
-static void __ImgGetFileAttributes(const char *szPathName, unsigned long *pFileAttr)
-{
-       FILE *f = NULL;
-
-       f = fopen(szPathName, "r");
-       if (f != NULL) {
-               if (fseek(f, 0, SEEK_END) < 0)
-                       mm_util_stderror("fseek failed");
-               else
-                       *pFileAttr = ftell(f);
-               fclose(f);
-       }
-}
+static const image_signature_t signature_info[] = {
+       { gIfegGIFHeader, 3, 0},
+       { gIfegPNGHeader, 8, 0},
+       { gIfegWBMPHeader, 2, 0},
+       { gIfegJPEGHeader, 2, 0},
+       { gIfegBMPHeader, 2, 0}
+};
 
-static unsigned int __IfegReadUINT(unsigned char *pBuffer)
+static unsigned int __ReadBE16bitsToUINT(const unsigned char *pBuffer)
 {
-       return (((*pBuffer) << 24) | ((*(pBuffer + 1)) << 16) | ((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
+       return ((*pBuffer) << 8 | (*(pBuffer + 1)));
 }
 
-static unsigned int __ReadBE16bitsToUINT(unsigned char *pBuffer)
+static unsigned int __ReadBE32bitsToUINT(const unsigned char *pBuffer)
 {
-       return ((*pBuffer) << 8 | (*(pBuffer + 1)));
+       return (((*pBuffer) << 24) | ((*(pBuffer + 1)) << 16) | ((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
 }
 
-static unsigned int __ReadLE16bitsToUINT(unsigned char *pBuffer)
+static unsigned int __ReadLE16bitsToUINT(const unsigned char *pBuffer)
 {
        return ((*pBuffer) | ((*(pBuffer + 1)) << 8));
 }
 
-static unsigned int __ReadLE32bitsToUINT(unsigned char *pBuffer)
+static unsigned int __ReadLE32bitsToUINT(const unsigned char *pBuffer)
 {
        return ((*pBuffer) | ((*(pBuffer + 1)) << 8) | ((*(pBuffer + 2)) << 16) | ((*(pBuffer + 3)) << 24));
 }
 
-static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
+static long __mm_util_info_get_file_size(FILE *fp)
 {
-       unsigned long fileread;
-       unsigned char EncodedDataBuffer[4096];
+       long file_size = 0;
+       long cur_pos = 0;
 
-       mm_util_retvm_if((type == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "type is null");
-       mm_util_retvm_if((width == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "width is null");
-       mm_util_retvm_if((height == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "height is null");
+       mm_util_retvm_if(!fp, -1, "invalid fp");
 
-       /* initialize the result */
-       *type = IMG_CODEC_UNKNOWN_TYPE;
-       *width = 0;
-       *height = 0;
+       cur_pos = ftell(fp);
+       if (cur_pos < 0) {
+               mm_util_stderror("ftell failed");
+               return -1;
+       }
 
-       memset(EncodedDataBuffer, 0, 4096);
+       if (fseek(fp, 0, SEEK_END) < 0) {
+               mm_util_stderror("fseek failed");
+               return -1;
+       }
 
-       fileread = fread(EncodedDataBuffer, sizeof(char), MINIMUM_HEADER_BYTES, hFile);
-       mm_util_retvm_if((fileread < MINIMUM_HEADER_BYTES), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE");
+       file_size = ftell(fp);
 
-       if (memcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) == 0) {
-               unsigned char header_type[JPG_HEADER_TYPE_LENGTH];
-               unsigned char block_size[JPG_BLOCK_SIZE_LENGTH];
-               unsigned char image_size[JPG_IMAGE_SIZE_LENGTH];
+       if (fseek(fp, cur_pos, SEEK_SET) < 0)
+               mm_util_stderror("fseek failed");
 
-               rewind(hFile);
+       return file_size;
+}
 
-               unsigned short block_length = EncodedDataBuffer[4] * 256 + EncodedDataBuffer[5];
-               mm_util_sec_debug("block length : %u", block_length);
-               unsigned long long i = 4;
+static int __mm_util_info_get_jpeg_size(FILE *fp, long file_size, unsigned int *width, unsigned int *height)
+{
+       unsigned char data[READ_JPEG_SIZE] = {0, };
+       unsigned char header_type[JPG_HEADER_TYPE_LENGTH] = {0, };
+       unsigned char block_size[JPG_BLOCK_SIZE_LENGTH] = {0, };
+       unsigned char image_size[JPG_IMAGE_SIZE_LENGTH] = {0, };
+       size_t file_read = 0;
+       unsigned short block_length = 0;
+       unsigned long total_length = 0;         // length of start header
+
+       mm_util_retvm_if(!fp, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fp");
+       mm_util_retvm_if(file_size <= 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_size");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       rewind(fp);
+       // __mm_util_info_get_codec_type decrease file_size
+       file_size += MINIMUM_HEADER_BYTES;
+
+       file_read = fread(data, sizeof(char), READ_JPEG_SIZE, fp);
+       mm_util_retvm_if((file_read < READ_JPEG_SIZE), MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
+
+       block_length = (unsigned short)__ReadBE16bitsToUINT(data + 4);
+       mm_util_retvm_if(block_length < 2, MM_UTIL_ERROR_INVALID_PARAMETER, "block_length is too short(%d)", block_length);
+
+       mm_util_sec_debug("block length : %u", block_length);
+
+       if (fseek(fp, block_length + 4 - READ_JPEG_SIZE, SEEK_CUR) < 0) {
+               mm_util_stderror("fseek failed");
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
 
-               if (fseek(hFile, block_length + 4, SEEK_CUR) < 0) {
-                       mm_util_stderror("fseek failed");
-                       return MM_UTIL_ERROR_INVALID_OPERATION;
+       while (total_length < file_size) {
+               total_length += block_length;
+               if (total_length >= file_size) {
+                       mm_util_warn("Failed to get w / h from jpeg at index [%lu]", total_length);
+                       break;
                }
 
-               while (i < fileSize) {
-                       i += block_length;
-                       if (i >= fileSize) {
-                               mm_util_warn("Failed to get w / h from jpeg at index [%llu]", i);
-                               break;
-                       }
-
-                       memset(header_type, 0, JPG_HEADER_TYPE_LENGTH);
-                       fileread = fread(header_type, sizeof(char), JPG_HEADER_TYPE_LENGTH, hFile);
-                       mm_util_retvm_if((fileread < JPG_HEADER_TYPE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG");
+               memset(header_type, 0, JPG_HEADER_TYPE_LENGTH);
+               file_read = fread(header_type, sizeof(char), JPG_HEADER_TYPE_LENGTH, fp);
+               mm_util_retvm_if(file_read < JPG_HEADER_TYPE_LENGTH, MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
 
-                       if (header_type[0] != 0xFF) {
-                               mm_util_warn("Failed to get w / h from jpeg at index [%llu] and go to next block.", i);
-                               /* add error handling when jpeg image has junk data in header */
-                               block_length = JPG_HEADER_TYPE_LENGTH;
-                               continue;
-                       }
+               if (header_type[0] != 0xFF) {
+                       mm_util_warn("Failed to get w / h from jpeg at index [%lu] and go to next block.", total_length);
+                       /* add error handling when jpeg image has junk data in header */
+                       block_length = JPG_HEADER_TYPE_LENGTH;
+                       continue;
+               }
 
-                       if (header_type[1] == 0xC0 || header_type[1] == 0xC2) {
-                               memset(image_size, 0, JPG_IMAGE_SIZE_LENGTH);
-                               fileread = fread(image_size, sizeof(char), JPG_IMAGE_SIZE_LENGTH, hFile);
-                               mm_util_retvm_if((fileread < JPG_IMAGE_SIZE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG");
-
-                               *width = __ReadBE16bitsToUINT(image_size + 5);
-                               *height = __ReadBE16bitsToUINT(image_size + 3);
-                               break;
-                       } else {
-                               i += JPG_HEADER_TYPE_LENGTH;
-                               memset(block_size, 0, JPG_BLOCK_SIZE_LENGTH);
-                               fileread = fread(block_size, sizeof(char), JPG_BLOCK_SIZE_LENGTH, hFile);
-                               mm_util_retvm_if((fileread < JPG_BLOCK_SIZE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG");
-                               block_length = (unsigned short)__ReadBE16bitsToUINT(block_size);
-                               mm_util_sec_debug("new block length : %u", block_length);
-
-                               if (fseek(hFile, block_length - JPG_BLOCK_SIZE_LENGTH, SEEK_CUR) < 0) {
-                                        mm_util_stderror("fseek failed");
-                                        return MM_UTIL_ERROR_INVALID_OPERATION;
-                               }
+               if (header_type[1] == 0xC0 || header_type[1] == 0xC2) {
+                       memset(image_size, 0, JPG_IMAGE_SIZE_LENGTH);
+                       file_read = fread(image_size, sizeof(char), JPG_IMAGE_SIZE_LENGTH, fp);
+                       mm_util_retvm_if(file_read < JPG_IMAGE_SIZE_LENGTH, MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
+
+                       *width = __ReadBE16bitsToUINT(image_size + 5);
+                       *height = __ReadBE16bitsToUINT(image_size + 3);
+                       break;
+               } else {
+                       total_length += JPG_HEADER_TYPE_LENGTH;
+                       memset(block_size, 0, JPG_BLOCK_SIZE_LENGTH);
+                       file_read = fread(block_size, sizeof(char), JPG_BLOCK_SIZE_LENGTH, fp);
+                       mm_util_retvm_if(file_read < JPG_BLOCK_SIZE_LENGTH, MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
+                       block_length = (unsigned short)__ReadBE16bitsToUINT(block_size);
+                       mm_util_sec_debug("new block length : %u", block_length);
+
+                       if (fseek(fp, block_length - JPG_BLOCK_SIZE_LENGTH, SEEK_CUR) < 0) {
+                                mm_util_stderror("fseek failed");
+                                return MM_UTIL_ERROR_INVALID_OPERATION;
                        }
                }
-               mm_util_sec_debug("IMG_CODEC_JPEG");
-               *type = IMG_CODEC_JPEG;
        }
-       /*********************** PNG *************************/
-       else if (memcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
-               fileread = fread(EncodedDataBuffer, sizeof(char), 32, hFile);
-               mm_util_retvm_if((fileread < 32), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in PNG");
 
-               /* Get Image width & height */
-               *width = __IfegReadUINT((EncodedDataBuffer + 8));
-               *height = __IfegReadUINT((EncodedDataBuffer + 12));
+       return MM_UTIL_ERROR_NONE;
+}
 
-               mm_util_sec_debug("IMG_CODEC_PNG");
-               *type = IMG_CODEC_PNG;
-       }
-       /*********************** BMP *************************/
-       else if (memcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
-               /* Parse BMP File and get image width and image height */
-               fileread = fread(&EncodedDataBuffer[8], sizeof(char), 18, hFile);
-               mm_util_retvm_if((fileread < 18), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in BMP");
-
-               *width = __ReadLE32bitsToUINT(EncodedDataBuffer + 18);
-               // add the reference function abs(). may have negative height values in bmp header.
-               *height = abs(__ReadLE32bitsToUINT(EncodedDataBuffer + 22));
-
-               mm_util_sec_debug("IMG_CODEC_BMP");
-               *type = IMG_CODEC_BMP;
-       }
-       /*********************** GIF *************************/
-       else if (memcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
-               mm_util_retvm_if((MINIMUM_HEADER_BYTES + 4 > fileSize), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in GIF");
-
-               fileread = fread(&EncodedDataBuffer[8], sizeof(char), 4, hFile);
-               mm_util_retvm_if((fileread < 4), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in GIF");
-
-               if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I'
-               || EncodedDataBuffer[2] != 'F' || EncodedDataBuffer[3] < '0'
-               || EncodedDataBuffer[3] > '9' || EncodedDataBuffer[4] < '0'
-               || EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A'
-               || EncodedDataBuffer[5] > 'z') {
-                       mm_util_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
-                       return MM_UTIL_ERROR_INVALID_PARAMETER;
-               }
+static int __mm_util_info_get_png_size(FILE *fp, long file_size, unsigned int *width, unsigned int *height)
+{
+       unsigned char data[READ_PNG_SIZE] = {0, };
+       size_t file_read = 0;
 
-               *width = __ReadLE16bitsToUINT(EncodedDataBuffer + 6);
-               *height = __ReadLE16bitsToUINT(EncodedDataBuffer + 8);
+       mm_util_retvm_if(!fp, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fp");
+       mm_util_retvm_if(file_size < READ_PNG_SIZE, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_size");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       file_read = fread(data, sizeof(char), READ_PNG_SIZE, fp);
+       mm_util_retvm_if(file_read < READ_PNG_SIZE, MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
+
+       *width = __ReadBE32bitsToUINT((data + 4));
+       *height = __ReadBE32bitsToUINT((data + 8));
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+static int __mm_util_info_get_bmp_size(FILE *fp, long file_size, unsigned int *width, unsigned int *height)
+{
+       unsigned char data[READ_BMP_SIZE] = {0, };
+       size_t file_read = 0;
 
-               mm_util_sec_debug("IMG_CODEC_GIF");
-               *type = IMG_CODEC_GIF;
+       mm_util_retvm_if(!fp, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fp");
+       mm_util_retvm_if(file_size < READ_BMP_SIZE, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_size");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       file_read = fread(data, sizeof(char), READ_BMP_SIZE, fp);
+       mm_util_retvm_if(file_read < READ_BMP_SIZE, MM_UTIL_ERROR_INVALID_PARAMETER, "fread error(%zu)", file_read);
+
+       *width = __ReadLE32bitsToUINT(data + 6);
+       // add the reference function abs(). may have negative height values in bmp header.
+       *height = abs(__ReadLE32bitsToUINT(data + 10));
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+static int __mm_util_info_get_gif_size(const unsigned char *data, unsigned int data_len, unsigned int *width, unsigned int *height)
+{
+       mm_util_retvm_if(!data, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid data");
+       mm_util_retvm_if(data_len < 10, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid data_len");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       // gif valid check
+       if (data[0] != 'G' || data[1] != 'I' || data[2] != 'F' ||
+               data[3] < '0' || data[3] > '9' ||
+               data[4] < '0' || data[4] > '9' ||
+               data[5] < 'A' || data[5] > 'z') {
+               mm_util_warn("invalid GIF");
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
-       /*********************** WBMP *************************/
-       else if (memcmp(EncodedDataBuffer, gIfegWBMPHeader, WBMP_HEADER_LENGTH) == 0) {
-               const gchar *extension = g_strrstr(path, ".");
 
-               if (!extension || (g_ascii_strcasecmp(extension, ".wbmp") != 0)) {
-                       mm_util_warn("IMG_CODEC_UNKNOWN_TYPE in WBMP");
-                       return MM_UTIL_ERROR_INVALID_PARAMETER;
-               }
+       *width = __ReadLE16bitsToUINT(data + 6);
+       *height = __ReadLE16bitsToUINT(data + 8);
 
-               /* Parse BMP File and get image width and image height */
-               *width = EncodedDataBuffer[2];
-               *height = EncodedDataBuffer[3];
+       return MM_UTIL_ERROR_NONE;
+}
 
-               mm_util_sec_debug("IMG_CODEC_WBMP");
-               *type = IMG_CODEC_WBMP;
+static int __mm_util_info_get_wbmp_size(const unsigned char *data, unsigned int data_len, const char *path, unsigned int *width, unsigned int *height)
+{
+       const gchar *extension = g_strrstr(path, ".");
+
+       mm_util_retvm_if(!data, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid data");
+       mm_util_retvm_if(data_len < 4, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid data_len");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       // wbmp valid check
+       if (!extension || (g_ascii_strcasecmp(extension, ".wbmp") != 0)) {
+               mm_util_warn("invalid WBMP");
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       mm_util_sec_debug("Image Width : %u, Height : %u", *width, *height);
+       *width = data[2];
+       *height = data[3];
 
        return MM_UTIL_ERROR_NONE;
 }
 
-int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
+static int __mm_util_get_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
 {
-       FILE *hFile;
-       unsigned long file_size = 0;
        int ret = MM_UTIL_ERROR_NONE;
+       FILE *fp = NULL;
+       long file_size = 0;
+       unsigned char data[MINIMUM_HEADER_BYTES] = {0, };
+       size_t file_read = 0;
+       unsigned int _type = 0, _width = 0, _height = 0;
 
        mm_util_retvm_if(!path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
 
-       hFile = fopen(path, "rb");
-       mm_util_retvm_if(!hFile, MM_UTIL_ERROR_INVALID_PARAMETER, "file open error: %s", path);
+       fp = fopen(path, "rb");
+       mm_util_retvm_if(!fp, MM_UTIL_ERROR_INVALID_PARAMETER, "fopen error: %s", path);
+
+       file_size = __mm_util_info_get_file_size(fp);
+       if (file_size < MINIMUM_HEADER_BYTES) {
+               mm_util_error("invalid file_size(%ld)", file_size);
+               fclose(fp);
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       }
 
-       __ImgGetFileAttributes(path, &file_size);
-       if (file_size == 0) {
-               fclose(hFile);
+       file_read = fread(data, sizeof(unsigned char), MINIMUM_HEADER_BYTES, fp);
+       if (file_read < MINIMUM_HEADER_BYTES) {
+               mm_util_stderror("fread error");
+               fclose(fp);
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
+       file_size -= MINIMUM_HEADER_BYTES;
 
-       ret = __ImgGetImageInfo(hFile, file_size, path, type, width, height);
+       // get codec type using signature
+       for (_type = 0; _type < IMG_CODEC_UNKNOWN_TYPE; _type++) {
+               if (memcmp(data + signature_info[_type].offset, signature_info[_type].signature, signature_info[_type].len) == 0) {
+                       mm_util_debug("type = %u", _type);
+                       break;
+               }
+       }
+
+       // get width and height
+       switch(_type) {
+       case IMG_CODEC_JPEG:
+               ret = __mm_util_info_get_jpeg_size(fp, file_size, &_width, &_height);
+               break;
+       case IMG_CODEC_PNG:
+               ret = __mm_util_info_get_png_size(fp, file_size, &_width, &_height);
+               break;
+       case IMG_CODEC_BMP:
+               ret = __mm_util_info_get_bmp_size(fp, file_size, &_width, &_height);
+               break;
+       case IMG_CODEC_GIF:
+               ret = __mm_util_info_get_gif_size(data, MINIMUM_HEADER_BYTES, &_width, &_height);
+               break;
+       case IMG_CODEC_WBMP:
+               ret = __mm_util_info_get_wbmp_size(data, MINIMUM_HEADER_BYTES, path, &_width, &_height);
+               break;
+       default:
+               mm_util_warn("IMG_CODEC_UNKNOWN_TYPE");
+               break;
+       }
 
-       fclose(hFile);
+       fclose(fp);
+
+       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "getting width and height failed(%d)", ret);
+
+       if (type)
+               *type = _type;
+       if (width)
+               *width = _width;
+       if (height)
+               *height = _height;
+
+       mm_util_debug("Image type: %u, width: %u, height: %u", _type, _width, _height);
 
        return ret;
 }
 
+int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
+{
+       mm_util_sec_debug("path = %s", path);
+
+       return __mm_util_get_image_info(path, type, width, height);
+}
index eb4a5e6..5c35bea 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.1.45
+Version:    0.1.46
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0