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];
*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];
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");
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);