Code cleanup. change the location of getting file extension and optimization 16/237116/5
authorjiyong.min <jiyong.min@samsung.com>
Thu, 25 Jun 2020 05:29:13 +0000 (14:29 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 26 Jun 2020 04:52:09 +0000 (13:52 +0900)
  - Only wbmp needs the file extension.

Change-Id: Ibb89b8d79c1561301fd4cdd77a474bc03a3eebc4

magick/mm_util_info.c

index 6b3041d..0e6d998 100644 (file)
@@ -77,7 +77,7 @@ static unsigned int __ReadLE32bitsToUINT(unsigned char *pBuffer)
        return ((*pBuffer) | ((*(pBuffer + 1)) << 8) | ((*(pBuffer + 2)) << 16) | ((*(pBuffer + 3)) << 24));
 }
 
-static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
+static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
 {
        unsigned long fileread;
        unsigned char EncodedDataBuffer[4096];
@@ -203,7 +203,14 @@ static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt,
                *type = IMG_CODEC_GIF;
        }
        /*********************** WBMP *************************/
-       else if ((memcmp(EncodedDataBuffer, gIfegWBMPHeader, WBMP_HEADER_LENGTH) == 0) && (strcasecmp(fileExt, "wbmp") == 0)) {
+       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;
+               }
+
                /* Parse BMP File and get image width and image height */
                *width = EncodedDataBuffer[2];
                *height = EncodedDataBuffer[3];
@@ -217,29 +224,10 @@ static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt,
        return MM_UTIL_ERROR_NONE;
 }
 
-static int __ImgGetFileExt(const char *path, char *file_ext, int max_len)
-{
-       int i = 0;
-
-       for (i = (int)strlen(path); i >= 0; i--) {
-               if ((path[i] == '.') && (i < (int)strlen(path))) {
-                       SAFE_STRLCPY(file_ext, &path[i + 1], max_len);
-                       return MM_UTIL_ERROR_NONE;
-               }
-
-               /* meet the dir. no ext */
-               if (path[i] == '/')
-                       return MM_UTIL_ERROR_INVALID_PARAMETER;
-       }
-
-       return MM_UTIL_ERROR_INVALID_PARAMETER;
-}
-
 int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height)
 {
        FILE *hFile;
        unsigned long file_size = 0;
-       char file_ext[10] = { 0, };
        int ret = MM_UTIL_ERROR_NONE;
 
        mm_util_retvm_if(!path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
@@ -253,11 +241,7 @@ int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, u
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       ret = __ImgGetFileExt(path, file_ext, sizeof(file_ext));
-       if (ret != MM_UTIL_ERROR_NONE)
-               mm_util_warn("__ImgGetFileExt failed");
-
-       ret = __ImgGetImageInfo(hFile, file_size, file_ext, type, width, height);
+       ret = __ImgGetImageInfo(hFile, file_size, path, type, width, height);
 
        fclose(hFile);