summaryrefslogtreecommitdiff
path: root/src/codec
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec')
-rwxr-xr-x[-rw-r--r--]src/codec/IfegDecodeAGIF.c226
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec-osal.c2
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec-parser.c711
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec.c23
4 files changed, 413 insertions, 549 deletions
diff --git a/src/codec/IfegDecodeAGIF.c b/src/codec/IfegDecodeAGIF.c
index e1e5a11..6fc2f1a 100644..100755
--- a/src/codec/IfegDecodeAGIF.c
+++ b/src/codec/IfegDecodeAGIF.c
@@ -35,17 +35,13 @@ int image_top_pos_N = 0;
AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int height, unsigned char *pEncodedData, unsigned int file_size, unsigned int ui_backcolor, BOOL bLoop)
{
- int header_temp;
+ unsigned int header_temp;
int backcolor_index;
unsigned int image_backcolor;
unsigned int backcolor_parsing;
- unsigned int transcolor_565 = 0;
int transparent = 0;
int transIndex = 0;
- int local_color_table_flag;
-
int inputPos = 0;
- int inputPos_temp = 0;
AGifFrameInfo *pFrameData;
if (0 == (pFrameData = IfegMemAlloc(sizeof(AGifFrameInfo)))) {
@@ -59,9 +55,9 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
pFrameData->logi_wdt = pEncodedData[6] | (pEncodedData[7]<<8);
pFrameData->logi_hgt = pEncodedData[8] | (pEncodedData[9]<<8);
#ifdef INTERNAL_IMGCODEC
- thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt);
+ thumb_dbg("logi_wdt:%d, logi_hgt:%d", pFrameData->logi_wdt, pFrameData->logi_hgt);
#else
- thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt);
+ thumb_dbg("logi_wdt:%d, logi_hgt:%d", pFrameData->logi_wdt, pFrameData->logi_hgt);
if ((pFrameData->logi_wdt > MAXWIDTH) || (pFrameData->logi_hgt > MAXHEIGHT)) {
if (pFrameData) {
IfegMemFree(pFrameData);
@@ -78,7 +74,7 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
} else {
header_temp = 0;
}
-
+
if (file_size > 30+header_temp && pEncodedData[14+header_temp] == 0xFF) {
pFrameData->nLoopCount = pEncodedData[30+header_temp]<<8 | pEncodedData[29+header_temp];
} else if (file_size > 30+8+header_temp && pEncodedData[14+8+header_temp] == 0xFF) {
@@ -86,38 +82,22 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
} else {
pFrameData->nLoopCount = -1;
}
-
+
pFrameData->nRepeatCount = 0;
- thumb_dbg("10st data : 0x%x , global color table num : %d\n", pEncodedData[10], header_temp);
- thumb_dbg("13: 0x%x ,14: 0x%x, 15: 0x%x, nRepeatCount : %d, nLoopCount : %d\n", pEncodedData[13+header_temp], pEncodedData[14+header_temp], pEncodedData[15+header_temp], pFrameData->nRepeatCount, pFrameData->nLoopCount);
+ thumb_dbg("10st data : 0x%x , global color table num : %d", pEncodedData[10], header_temp);
+ thumb_dbg("13: 0x%x ,14: 0x%x, 15: 0x%x, nRepeatCount : %d, nLoopCount : %d", pEncodedData[13+header_temp], pEncodedData[14+header_temp], pEncodedData[15+header_temp], pFrameData->nRepeatCount, pFrameData->nLoopCount);
backcolor_index = pEncodedData[11];
if (pEncodedData[14+header_temp] == 0xF9) {
- inputPos_temp = 14+header_temp+17;
transparent = pEncodedData[16+header_temp] & 0x01;
transIndex = pEncodedData[19+header_temp];
- local_color_table_flag = pEncodedData[30+header_temp] & 0x80;
-
- if (local_color_table_flag == 0x80) {
- transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3);
- } else {
- transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3);
- }
backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3);
} else if (pEncodedData[14+19+header_temp] == 0xF9) {
- inputPos_temp = 14+19+header_temp+17;
transparent = pEncodedData[35+header_temp] & 0x01;
transIndex = pEncodedData[38+header_temp];
- local_color_table_flag = pEncodedData[49+header_temp] & 0x80;
-
- if (local_color_table_flag == 0x80) {
- transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3);
- } else {
- transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3);
- }
backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3);
} else if ((pEncodedData[10]&0x80) != 0x80) { /* global color table */
@@ -372,6 +352,34 @@ void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData)
} \
}
+#define __get_next_code_first_nbits_left_0_nobuffer(pInputStream) \
+{\
+ {\
+ if (navail_bytes == 0) {\
+ navail_bytes = (pInputStream)[inputPos++];\
+ if ((inputPos + navail_bytes) > filesize) {\
+ if (decoderline) {\
+ IfegMemFree(decoderline);\
+ decoderline = 0;\
+ } \
+ if (pDecBuf) {\
+ IfegMemFree(pDecBuf);\
+ pDecBuf = 0;\
+ } \
+ if (done_prefix) {\
+ IfegMemFree(done_prefix);\
+ done_prefix = 0;\
+ } \
+ return -1;\
+ } \
+ } \
+ b1 = (pInputStream)[inputPos++];\
+ ret = b1;\
+ nbits_left = 8;\
+ --navail_bytes;\
+ } \
+}
+
#define __get_next_code_first_nbits_left_not_0(pInputStream) \
{\
{\
@@ -406,6 +414,37 @@ void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData)
c = ret;\
}
+#define __get_next_code_first_while_nobuffer(pInputStream) \
+{\
+ while (curr_size > nbits_left) {\
+ if (navail_bytes == 0) {\
+ navail_bytes = (pInputStream)[inputPos++];\
+ if ((inputPos + navail_bytes) > filesize) {\
+ if (decoderline) {\
+ IfegMemFree(decoderline);\
+ decoderline = 0;\
+ } \
+ if (pDecBuf) {\
+ IfegMemFree(pDecBuf);\
+ pDecBuf = 0;\
+ } \
+ if (done_prefix) {\
+ IfegMemFree(done_prefix);\
+ done_prefix = 0;\
+ } \
+ return -1;\
+ } \
+ } \
+ b1 = (pInputStream)[inputPos++];\
+ ret |= b1 << nbits_left;\
+ nbits_left += 8;\
+ --navail_bytes;\
+ } \
+ nbits_left -= curr_size;\
+ ret &= (1<<curr_size)-1;\
+ c = ret;\
+}
+
#define __get_next_code_second_nbits_left_0(pInputStream) \
{\
{\
@@ -479,7 +518,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
int spCount = 0;
int logi_wdt; /* logical screen width */
int logi_hgt;
- int logi_image_size;
int image_backcolor;
int ui_backcolor;
int backcolor;
@@ -501,8 +539,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
int flag = 0;
unsigned int end;
- int count = 0;
-
unsigned char *pDecBuf = 0;
int expected_width = pFrameData->width;
@@ -522,12 +558,19 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
unsigned int *global_dacbox = pFrameData->pGlobal_table;
register unsigned char *pInputStream = pFrameData->pEncodedData;
void *pOutBits = pFrameData->pOutBits;
- unsigned short *prefix = pFrameData->pPrefix;
- unsigned char *dstack = pFrameData->pDstack;
- unsigned char *suffix = pFrameData->pSuffix;
+ unsigned short *prefix = pFrameData->pPrefix;
+ unsigned char *dstack = pFrameData->pDstack;
+ unsigned char *suffix = pFrameData->pSuffix;
+ unsigned char *done_prefix = 0;
inputPos = pFrameData->offset;
+ done_prefix = IfegMemAlloc(sizeof(unsigned char)*(MAX_CODES+1));
+ if (done_prefix == 0)
+ {
+ thumb_err("Failed to allocate memory for check buffer.");
+ return -1;
+ }
IfegMemset(prefix, 0, sizeof(unsigned short)*(MAX_CODES+1));
IfegMemset(dstack, 0, sizeof(unsigned char)*(MAX_CODES+1));
IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1));
@@ -561,13 +604,14 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
/* Regard the width/height of image block as the size of thumbnails. */
pFrameData->logi_wdt = logi_wdt = expected_width;
pFrameData->logi_hgt = logi_hgt = expected_height;
- logi_image_size = logi_wdt * logi_hgt;
/* ouput resized image size */
if (logi_wdt <= expected_width && logi_hgt <= expected_height) {
@@ -588,6 +632,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
@@ -661,8 +707,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = ui_backcolor;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 1;
} else {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
}
@@ -678,6 +728,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
pDecBuf = 0;
}
if (pFrameData->imgCount == 0) {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
pFrameData->imgCount = 0;
@@ -696,11 +748,13 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = ui_backcolor;
}
-
+
inputPos = pFrameData->offset;
continue;
} else {
/* if there is last frame and bLoop is FALSE, return 2. */
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 2;
}
#else
@@ -710,8 +764,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = backcolor;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 1;
} else {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
#endif
@@ -728,6 +786,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
@@ -735,7 +795,7 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
transparent = pInputStream[inputPos++] & 0x01; /* does it use? 1:on 0:off */
pFrameData->delay = (pInputStream[inputPos] | (pInputStream[inputPos+1] << 8))*10;
inputPos += 2; /* Delay time (skip) */
- transIndex = pInputStream[inputPos++];
+ transIndex = pInputStream[inputPos++];
inputPos++; /* block end */
break;
@@ -751,6 +811,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -768,6 +830,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -786,6 +850,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -821,6 +887,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
#endif
@@ -846,13 +914,15 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
IfegMemset(decoderline, 0, orgwdt);
decwdt = ((orgwdt * resized_width+logi_wdt-1) / logi_wdt);
dechgt = ((orghgt * resized_height+logi_hgt-1) / logi_hgt);
-
+
if (!decwdt || !dechgt) {
if (decoderline != 0) {
IfegMemFree(decoderline);
@@ -862,6 +932,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
@@ -878,6 +950,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
IfegMemset(pDecBuf, 0, decwdt * dechgt * 4);
@@ -903,8 +977,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
numcolors = (buffer[8] & 0x7) + 1;
numcolors = 1 << numcolors;
- count = 0;
-
/* Make color table */
for (i = 0 ; i < numcolors; i++) {
dacbox[i] = ((pInputStream[inputPos++] >> 2)<<16);
@@ -936,6 +1008,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
@@ -961,20 +1035,20 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream) */
if (navail_bytes < 2) {
if (nbits_left == 0) {
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
} else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
-
+
__get_next_code_second_while(pInputStream)
- }
-
+ }
+
if (c == ending) {
break;
}
@@ -989,20 +1063,20 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream); */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
__get_next_code_second_while(pInputStream)
}
-
+
} while (c == clear);
if (c == ending) {
@@ -1324,12 +1398,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream) */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
@@ -1351,18 +1425,18 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream); */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
__get_next_code_second_while(pInputStream)
- }
+ }
} while (c == clear);
if (c == ending) {
@@ -1382,8 +1456,26 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
code = oc;
*sp++ = (unsigned char)fc;
}
+
+ IfegMemset(done_prefix, 0, sizeof(unsigned char)*(MAX_CODES+1));
while (code >= newcodes) {
*sp++ = suffix[code];
+ if ((code == prefix[code]) || (done_prefix[code] == 1))
+ {
+ thumb_err("Circular entry in table.");
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
+ return 0;
+ }
+ done_prefix[code] = 1;
code = prefix[code];
}
@@ -1542,6 +1634,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
pFrameData->offset = inputPos;
pFrameData->imgCount++;
@@ -1594,11 +1688,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
int spCount = 0;
int logi_wdt; /* logical screen width */
int logi_hgt;
- int logi_image_size;
int ui_backcolor565;
int backcolor565;
- int ui_backcolor888;
int backcolor888;
int image_left_pos; /* left position of image in Logical screeen */
@@ -1622,8 +1714,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
int flag = 0;
unsigned int end;
- int count = 0;
-
unsigned char *pDecBuf = 0;
int expected_width = pFrameData->width;
@@ -1642,9 +1732,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
unsigned int *global_dacbox = pFrameData->pGlobal_table;
unsigned char *pInputStream = pFrameData->pEncodedData;
void *pOutBits = pFrameData->pOutBits;
- unsigned short *prefix = pFrameData->pPrefix;
- unsigned char *dstack = pFrameData->pDstack;
- unsigned char *suffix = pFrameData->pSuffix;
+ unsigned short *prefix = pFrameData->pPrefix;
+ unsigned char *dstack = pFrameData->pDstack;
+ unsigned char *suffix = pFrameData->pSuffix;
int filesize = pFrameData->inputSize;
inputPos = pFrameData->offset;
@@ -1654,13 +1744,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1));
ui_backcolor565 = pFrameData->ui_backcolor;
- ui_backcolor888 =
- ((ui_backcolor565&0xf800) << 6)|
- ((ui_backcolor565&0x7e0) << 3)|
- ((ui_backcolor565&0x1f) << 1);
backcolor565 = pFrameData->backcolor;
- backcolor888 =
+ backcolor888 =
((backcolor565&0xf800) << 6)|
((backcolor565&0x7e0) << 3)|
((backcolor565&0x1f) << 1);
@@ -1696,8 +1782,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
pFrameData->logi_wdt = logi_wdt = buffer[6] | (buffer[7] << 8);
pFrameData->logi_hgt = logi_hgt = buffer[8] | (buffer[9] << 8);
- logi_image_size = logi_wdt * logi_hgt;
-
/* ouput resized image size */
if (logi_wdt <= expected_width && logi_hgt <= expected_height) {
resized_width = logi_wdt;
@@ -2034,8 +2118,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
numcolors = (buffer[8] & 0x7) + 1;
numcolors = 1 << numcolors;
- count = 0;
-
/* Make color table */
for (i = 0; i < numcolors; i++) {
dacbox[i] = ((pInputStream[inputPos++] >> 2) << 16);
diff --git a/src/codec/img-codec-osal.c b/src/codec/img-codec-osal.c
index 9a257fa..cefe59f 100644..100755
--- a/src/codec/img-codec-osal.c
+++ b/src/codec/img-codec-osal.c
@@ -69,8 +69,8 @@ HFile DrmOpenFile(const char *szPathName)
FILE *fp = fopen(szPathName, "rb");
if (fp == NULL) {
- thumb_err("file open error: %s", szPathName);
return (HFile) INVALID_HOBJ;
+ thumb_err("file open error: %s", szPathName);
}
return fp;
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
index dd04455..2d8d348 100644..100755
--- a/src/codec/img-codec-parser.c
+++ b/src/codec/img-codec-parser.c
@@ -33,6 +33,21 @@
#include "img-codec-common.h"
#include "img-codec-parser.h"
+#define MINIMUM_HEADER_BYTES 8
+
+#define PNG_HEADER_LENGTH 8
+#define JPG_HEADER_LENGTH 2
+#define GIF_HEADER_LENGTH 3
+#define TIFF_HEADER_LENGTH 2
+#define BMP_HEADER_LENGTH 2
+#define WBMP_HEADER_LENGTH 2
+#define TIFF_IMAGE_WIDTH 0x100
+#define TIFF_IMAGE_HEIGHT 0x101
+
+#define JPG_HEADER_TYPE_LENGTH 2
+#define JPG_BLOCK_SIZE_LENGTH 2
+#define JPG_IMAGE_SIZE_LENGTH 8
+
#define FILE_READ_SIZE 4096
typedef struct _stream {
HFile fd;
@@ -44,61 +59,11 @@ typedef struct _stream {
unsigned char *buffer;
} IFEGSTREAMCTRL;
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo);
-BOOL process_EXIF(unsigned char *ExifSection, unsigned int length,
- unsigned int *pOrientataion);
-
-ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- ImgCodecType result = 0;
- SysAssert(hFile);
- SysAssert(fileSize);
-
- if (imgInfo == NULL) {
- result = _ImgGetInfoStreaming(hFile, fileSize, NULL);
- } else {
- result = _ImgGetInfoStreaming(hFile, fileSize, imgInfo);
- }
-
- DrmSeekFile(hFile, SEEK_SET, 0);
-
- return result;
-
-}
-
-ImgCodecType ImgGetInfoFile(const char *filePath, ImgImageInfo * imgInfo)
-{
- HFile hFile;
- FmFileAttribute fileAttrib;
- ImgCodecType result;
- SysAssert(filePath);
- hFile = DrmOpenFile(filePath);
-
- if (hFile == (HFile) INVALID_HOBJ) {
- return IMG_CODEC_NONE;
- }
- DrmGetFileAttributes(filePath, &fileAttrib);
-
- if ((fileAttrib.fileSize == 0)) {
- DrmCloseFile(hFile);
- return IMG_CODEC_NONE;
- }
-
- result = ImgGetInfoHFile(hFile, fileAttrib.fileSize, imgInfo);
-
- DrmCloseFile(hFile);
-
- return result;
-
-}
-
-static unsigned char gIfegPNGHeader[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+static unsigned char gIfegPNGHeader[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 };
static unsigned char gIfegGIFHeader[] = { "GIF" };
static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
+static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
static int _CheckBuffer(IFEGSTREAMCTRL *pIfegstreamctrl, unsigned int size)
{
@@ -160,277 +125,118 @@ static unsigned int _IfegReadUINT(unsigned char *pBuffer)
((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
}
-ImgCodecType ImgGetInfo(unsigned char *pEncodedData, unsigned long fileSize,
- ImgImageInfo *imgInfo)
+static int _ImgGetImageInfo(HFile hFile, unsigned long fileSize, char *fileExt, ImgCodecType *type, unsigned int *width, unsigned int *height, bool fast_mode)
{
- unsigned int width = 0, height = 0;
-
- /* Initialize values */
- if (imgInfo) {
- imgInfo->width = 0;
- imgInfo->height = 0;
- imgInfo->numberOfFrame = 1;
- imgInfo->bOrientation = 0;
- }
-
- SysAssert(pEncodedData);
- SysAssert(fileSize);
+ unsigned int fileleft;
+ unsigned long fileread;
+ unsigned char EncodedDataBuffer[4096];
- /*********************** PNG *************************/
- if (AcMemcmp(pEncodedData, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
- unsigned char tmp;
+ unsigned int *pWidth = NULL;
+ unsigned int *pHeight = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
- if (fileSize < 40) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Get Image Width */
- width = _IfegReadUINT((pEncodedData + 16));
+ if (type == NULL || width == NULL ||height == NULL ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ } else {
+ pWidth = width;
+ pHeight = height;
- /* Get Image Height */
- height = _IfegReadUINT((pEncodedData + 20));
+ *type = IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = 0;
+ *pHeight = 0;
+ }
- /* Read Interlace byte */
- tmp = *(pEncodedData + 28);
- /* If image is interlaced then multiple should be 2 */
- if (tmp) {
- thumb_dbg("Interlaced PNG Image.");
- }
+ AcMemset(EncodedDataBuffer, 0, 4096);
- thumb_dbg("type: IMG_CODEC_PNG");
+ SysAssert((const char *)&fileSize);
- if (imgInfo) {
- imgInfo->width = width;
- imgInfo->height = height;
- }
- return IMG_CODEC_PNG;
+ if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- /*********************** BMP *************************/
- else if (AcMemcmp(pEncodedData, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
- /* Parse BMP File and get image width and image height */
- if (fileSize < 26) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[18] | (pEncodedData[19] << 8) |
- (pEncodedData[20] << 16) | (pEncodedData[21] << 24);
- imgInfo->height =
- pEncodedData[22] | (pEncodedData[23] << 8) |
- (pEncodedData[24] << 16) | (pEncodedData[25] << 24);
- }
-
- thumb_dbg("type : IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
-
+ if (fileread < MINIMUM_HEADER_BYTES) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
+ return ret;
}
- /*********************** GIF *************************/
- else if (AcMemcmp(pEncodedData, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
- int length;
- int inputPos = 0;
- int temp;
- int finished;
- int imagecount = 0;
-
- if ((unsigned int)inputPos + 13 > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- if (pEncodedData[0] != 'G' || pEncodedData[1] != 'I'
- || pEncodedData[2] != 'F' || pEncodedData[3] < '0'
- || pEncodedData[3] > '9' || pEncodedData[4] < '0'
- || pEncodedData[4] > '9' || pEncodedData[5] < 'A'
- || pEncodedData[5] > 'z') {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* get Logical width, height */
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[6] | (pEncodedData[7] << 8);
- imgInfo->height =
- pEncodedData[8] | (pEncodedData[9] << 8);
- }
- if ((pEncodedData[10] & 0x80) != 0) /* Global color table */ {
- temp = (pEncodedData[10] & 0x7) + 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- }
+ if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) == 0) {
+ if (fast_mode == FALSE) {
+ unsigned char header_type[JPG_HEADER_TYPE_LENGTH];
+ unsigned char block_size[JPG_BLOCK_SIZE_LENGTH];
+ unsigned char image_size[JPG_IMAGE_SIZE_LENGTH];
- inputPos += 13;
- finished = 0;
+ rewind(hFile);
- /* still gif image (image_cnt = 1) */
- while (!finished) {
- if ((unsigned int)inputPos > fileSize)
- break;
+ unsigned short block_length = EncodedDataBuffer[4] * 256 + EncodedDataBuffer[5];
+ thumb_dbg("block length : %d", block_length);
+ unsigned int i = 4;
- switch (pEncodedData[inputPos++]) {
- case 0x3b: /* End of the GIF dataset */
- finished = 1;
- break;
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length+4) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- case 0x21: /* Extension Block */
- switch (pEncodedData[inputPos++]) {
- case 0xf9: /* Graphic control extension block */
- if (4 != pEncodedData[inputPos++]) { /* data length : fixed 4 bytes */
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- inputPos += 4;
- inputPos++; /* block end */
+ while (i < fileSize) {
+ i += block_length;
+ if (i >= fileSize) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
+ }
- case 0x01: /* Plain Text block */
- case 0xfe: /* Comment Extension block */
- case 0xff: /* Appliation Extension block */
- while ((length = pEncodedData[inputPos++]) > 0) { /* get the data length */
- inputPos += (length);
- if ((unsigned int)inputPos >
- fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return
- IMG_CODEC_UNKNOWN_TYPE;
- }
- }
- break;
+ AcMemset(header_type, 0, JPG_HEADER_TYPE_LENGTH);
+ if (DrmReadFile(hFile, header_type, (ULONG)JPG_HEADER_TYPE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- default:
+ if (header_type[0] != 0xFF) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
}
- break;
-
- case 0x2c: /* Start of an image object. Read the image description. */
-
- if ((unsigned int)inputPos + 9 > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Color Resolution */
- if ((pEncodedData[inputPos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (pEncodedData[inputPos + 8] & 0x7) +
- 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (header_type[1] == 0xC0 || header_type[1] == 0xC2) {
+ AcMemset(image_size, 0, JPG_IMAGE_SIZE_LENGTH);
+ if (DrmReadFile(hFile, image_size, (ULONG)JPG_IMAGE_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- }
-
- inputPos += 9;
- temp = pEncodedData[inputPos++];
- if (temp < 2 || 9 < temp) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- do {
- length = pEncodedData[inputPos++];
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = image_size[5] * 256 + image_size[6];
+ *pHeight = image_size[3] * 256 + image_size[4];
+ break;
+ } else {
+ i += 2;
+ AcMemset(block_size, 0, JPG_BLOCK_SIZE_LENGTH);
+ if (DrmReadFile(hFile, block_size, (ULONG)JPG_BLOCK_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- } while (length);
- if (!imagecount)
- imagecount++;
- else {
- if (imgInfo)
- imgInfo->numberOfFrame = 2;
- return IMG_CODEC_AGIF;
+ block_length = block_size[0] * 256 + block_size[1];
+ thumb_dbg("new block length : %d", block_length);
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length-JPG_BLOCK_SIZE_LENGTH) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
}
- break;
-
- default:
- finished = 0;
- break;
-
- } /* end of switch (pEncodedData[inputPos++]) */
- } /* end of while (pImage->bitmapCount > image_cnt && !finished) */
-
- return IMG_CODEC_GIF;
- }
-
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
-}
-
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- unsigned int fileleft;
- unsigned long fileread;
- unsigned char EncodedDataBuffer[4096];
-
- unsigned int *pNumberOfFrames = NULL;
- unsigned int *pWidth = NULL;
- unsigned int *pHeight = NULL;
- unsigned int *pOrientation = NULL;
-
- if (imgInfo == NULL) {
- pNumberOfFrames = NULL;
- pWidth = NULL;
- pHeight = NULL;
- pOrientation = NULL;
- } else {
- pWidth = &(imgInfo->width);
- pHeight = &(imgInfo->height);
- pOrientation = &(imgInfo->bOrientation);
- pNumberOfFrames = &(imgInfo->numberOfFrame);
-
- *pWidth = 0;
- *pHeight = 0;
- *pOrientation = 0;
- }
-
- AcMemset(EncodedDataBuffer, 0, 4096);
-
- /* Initialize values */
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
-
- SysAssert((const char *)&fileSize);
-
- if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
- }
-
- if (fileread < MINIMUM_HEADER_BYTES) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
+ }
+ thumb_dbg("IMG_CODEC_JPEG");
+ *type = IMG_CODEC_JPEG;
}
/*********************** PNG *************************/
- if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
unsigned char tmp;
if (DrmReadFile(hFile, EncodedDataBuffer, 32, &fileread) ==
FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 32) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Get Image Width */
if (pWidth) {
@@ -448,25 +254,19 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (tmp) {
thumb_dbg("Interlaced PNG Image.");
}
- thumb_dbg("IMG_CODEC_PNG\n");
- return IMG_CODEC_PNG;
+ thumb_dbg("IMG_CODEC_PNG");
+ *type = IMG_CODEC_PNG;
}
/*********************** BMP *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH)
- == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
/* Parse BMP File and get image width and image height */
- if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) ==
- FALSE) {
+ if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 18) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (pWidth == NULL || pHeight == NULL
- || pNumberOfFrames == NULL) {
- return IMG_CODEC_BMP;
+ return ret;
}
if (pWidth) {
*pWidth =
@@ -482,7 +282,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
thumb_dbg("IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
+ *type = IMG_CODEC_BMP;
}
/*********************** GIF *************************/
else if (AcMemcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
@@ -495,17 +295,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (13 > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (DrmReadFile(hFile, &EncodedDataBuffer[8], 5, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 5) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I'
@@ -514,17 +313,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
|| EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A'
|| EncodedDataBuffer[5] > 'z') {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (!(pWidth && pHeight)) {
- return IMG_CODEC_UNKNOWN_TYPE;
- } else {
- *pWidth =
- EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
- *pHeight =
- EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
- }
+ *pWidth = EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
+ *pHeight = EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
thumb_dbg("Logical width : %d, Height : %d", *pWidth, *pHeight);
@@ -534,22 +327,21 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if ((tablelength * sizeof(char)) > sizeof(EncodedDataBuffer)) {
thumb_warn("_ImgGetInfoStreaming :table length is more than buffer length");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (13 + tablelength > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* coverity[ -tainted_data_argument : EncodedDataBuffer ] */
if (DrmReadFile(hFile, EncodedDataBuffer, tablelength, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < tablelength) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
}
@@ -567,7 +359,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
break;
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -579,7 +371,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0x21: /* Extension Block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -587,11 +379,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xf9: /* Graphic control extension block */
if (_CheckBuffer(&ifegstreamctrl, 6) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
- return 0;
+ if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
+ *type = 0;
}
ifegstreamctrl.buffpos += 4;
ifegstreamctrl.buffpos++; /* block end */
@@ -602,24 +394,25 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xff: /* Appliation Extension block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (ifegstreamctrl.buffpos > sizeof(EncodedDataBuffer)) {
thumb_warn("buffer position exceeds buffer max length ");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer)) && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
+ while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer))
+ && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
if (_CheckBuffer(&ifegstreamctrl, length) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Check integer overflow */
if (ifegstreamctrl.buffpos > 0xffffffff - length) {
thumb_err("Prevent integer overflow..");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
ifegstreamctrl.buffpos += (length);
@@ -637,41 +430,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 9) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
#if 1
if (imagecount == 0) {
/* Regard the width/height of the first image block as the size of thumbnails. */
- int img_block_w, img_block_h,
- img_block_left, img_block_top;
- img_block_left =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 1] << 8);
- img_block_top =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 2] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 3] << 8);
-
- img_block_w =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 4] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 5] << 8);
- img_block_h =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 6] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 7] << 8);
- thumb_dbg
- ("Image block width : %d, Height : %d, left:%d, top:%d\n",
- img_block_w, img_block_h,
- img_block_left, img_block_top);
+ int img_block_w, img_block_h;
+
+ img_block_w = EncodedDataBuffer[ifegstreamctrl.buffpos + 4] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 5] << 8);
+ img_block_h = EncodedDataBuffer[ifegstreamctrl.buffpos + 6] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 7] << 8);
+ thumb_dbg ("Image block width : %d, Height : %d, left:%d, top:%d", img_block_w, img_block_h);
*pWidth = img_block_w;
*pHeight = img_block_h;
@@ -679,17 +447,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
#endif
/* Color Resolution */
if ((EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos +
- 8] & 0x7) + 1;
+ temp = (EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x7) + 1;
length = (1 << temp) * 3;
- if (_CheckBuffer
- (&ifegstreamctrl,
- length + 9) == 0) {
- thumb_warn
- ("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (_CheckBuffer(&ifegstreamctrl, length + 9) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return ret;
}
ifegstreamctrl.buffpos += length;
@@ -700,18 +462,18 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
temp = EncodedDataBuffer[ifegstreamctrl.buffpos++];
if (temp < 2 || 9 < temp) {
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
do {
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
length =EncodedDataBuffer[ifegstreamctrl.buffpos++];
@@ -722,13 +484,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
ifegstreamctrl.buffend;
if (DrmSeekFile(ifegstreamctrl.fd, SEEK_CUR, length) == FALSE) {
if (imagecount) {
- if (pNumberOfFrames)
- *pNumberOfFrames
- = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
- return IMG_CODEC_UNKNOWN_TYPE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
ifegstreamctrl.filepos += length;
ifegstreamctrl.buffpos = 0;
@@ -742,10 +502,9 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (!imagecount)
imagecount++;
else {
- if (pNumberOfFrames)
- *pNumberOfFrames = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
break;
@@ -755,102 +514,122 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
}
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
thumb_dbg("IMG_CODEC_GIF");
- return IMG_CODEC_GIF;
+ *type = IMG_CODEC_GIF;
}
+ /*********************** WBMP *************************/
+ else if ((AcMemcmp(EncodedDataBuffer, gIfegWBMPHeader, WBMP_HEADER_LENGTH) == 0)
+ && (strcasecmp(fileExt, "wbmp") == 0)) {
+ /* Parse BMP File and get image width and image height */
+/* if (DrmReadFile(hFile, &EncodedDataBuffer[2], 2, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
+ if (fileread < 2) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in WBMP");
+ return ret;
+ }*/
+ if (pWidth) {
+ *pWidth = EncodedDataBuffer[2];
+ }
+ if (pHeight) {
+ *pHeight = EncodedDataBuffer[3];
+ }
+ thumb_dbg("WBMP w: %d, h: %d", *pWidth, *pHeight);
- /*********************** Jpeg *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH)
- == 0) {
-#if 1
- /*
- IFEGSTREAMCTRL ifegstreamctrl;
- if( DrmReadFile(hFile, &EncodedDataBuffer[8], FILE_READ_SIZE-8, &fileread) == FALSE )
- {
- thumb_err( "DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
- }
-
- ifegstreamctrl.fd = hFile;
- ifegstreamctrl.filesize = fileSize;
- ifegstreamctrl.filepos = fileread+8;
- ifegstreamctrl.buffpos = 2;
- ifegstreamctrl.buffend = 8+fileread;
- ifegstreamctrl.buffer = EncodedDataBuffer;
- */
-
-#else /* Get w / h from jpeg header */
-
-#ifdef _PERFORMANCE_CHECK_
- long start = 0L, end = 0L;
- start = mediainfo_get_debug_time();
-#endif
- unsigned char *img_buf = NULL;
- img_buf = (unsigned char *)malloc(fileSize);
+ thumb_dbg("IMG_CODEC_WBMP");
+ *type = IMG_CODEC_WBMP;
+ }
+ return ret;
+}
- rewind(hFile);
- if (DrmReadFile(hFile, img_buf, fileSize, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
+static int _ImgGetFileExt(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
- return IMG_CODEC_NONE;
+ for (i = (int)strlen(file_path); i >= 0; i--) {
+ if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
+ strncpy(file_ext, &file_path[i + 1], max_len);
+ return 0;
}
- unsigned short block_length = img_buf[4] * 256 + img_buf[5];
- thumb_dbg("block length : %d", block_length);
- int i = 4;
+ /* meet the dir. no ext */
+ if (file_path[i] == '/') {
+ return -1;
+ }
+ }
- while (i < fileSize) {
- i += block_length;
- if (i >= fileSize) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+ return -1;
+}
- if (img_buf[i] != 0xFF) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+int ImgGetImageInfo(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
- if (img_buf[i + 1] == 0xC0) {
- *pWidth = img_buf[i + 5] * 256 + img_buf[i + 6];
- *pHeight =
- img_buf[i + 7] * 256 + img_buf[i + 8];
- break;
- } else {
- i += 2;
- block_length =
- img_buf[i] * 256 + img_buf[i + 1];
- thumb_dbg("new block length : %d",
- block_length);
- }
- }
- thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
-
- if (img_buf)
- free(img_buf);
-
-#if defined(_PERFORMANCE_CHECK_) && defined(_USE_LOG_FILE_)
- end = mediainfo_get_debug_time();
- double get_size =
- ((double)(end - start) / (double)CLOCKS_PER_SEC);
- thumb_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_init_file_debug();
- mediainfo_file_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_close_file_debug();
-#endif
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
-#endif /* End of Get w / h from jpeg header */
+ DrmGetFileAttributes(filePath, &fileAttrib);
- thumb_dbg("IMG_CODEC_JPEG");
- return IMG_CODEC_JPEG;
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
}
- return IMG_CODEC_UNKNOWN_TYPE;
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, FALSE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
+}
+
+int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
+
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ DrmGetFileAttributes(filePath, &fileAttrib);
+
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
+ };
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, TRUE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
}
diff --git a/src/codec/img-codec.c b/src/codec/img-codec.c
index fadd8c2..a27495c 100644..100755
--- a/src/codec/img-codec.c
+++ b/src/codec/img-codec.c
@@ -25,7 +25,7 @@
#include <mm_util_imgp.h>
unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
- ImgImageInfo *image_info)
+ unsigned int width, unsigned int height)
{
AGifFrameInfo *pFrameInfo = 0;
void *pDecodedRGB888Buf = 0;
@@ -37,15 +37,15 @@ unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
return NULL;
}
- if (image_info == NULL) {
+ if (width == 0 || height == 0) {
thumb_err
- ("ImgGetFirstFrameAGIFAtSize: Input ImgImageInfo is NULL");
+ ("ImgGetFirstFrameAGIFAtSize: Input width or height is zero");
return NULL;
}
pFrameInfo =
- ImgCreateAGIFFrame(szFileName, image_info->width,
- image_info->height, 0, FALSE);
+ ImgCreateAGIFFrame(szFileName, width,
+ height, 0, FALSE);
if (pFrameInfo && pFrameInfo->pOutBits) {
ImgGetNextAGIFFrame(pFrameInfo, TRUE);
@@ -61,13 +61,17 @@ unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
unsigned int i = 0;
- if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, image_info->width, image_info->height, &i) < 0) {
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, width, height, &i) < 0) {
thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size");
return NULL;
}
thumb_dbg("ImgGetFirstFrameAGIFAtSize: raw data size : %d)", i);
raw_data = (unsigned char *)malloc(i);
+ if (raw_data == NULL) {
+ thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to allocate memory");
+ return NULL;
+ }
memset(raw_data, 0, i);
unsigned char *dest = raw_data;
while (i--) {
@@ -162,8 +166,6 @@ AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width,
return FALSE;
}
- SysRequireEx(szFileName != NULL, FALSE);
-
hFile = DrmOpenFile(szFileName);
if (hFile == (HFile) INVALID_HOBJ) {
thumb_err("ImgCreateAGIFFrame: Cannot open file");
@@ -180,13 +182,14 @@ AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width,
cFileSize = fileAttrib.fileSize;
/* A size of allocated memory - w * h *2 means RGB565 and 4096 means the max of header length */
- mem_alloc_size = width * height * 2 + MAX_GIF_HEADER_SIZE;
-
+// mem_alloc_size = width * height * 2 + MAX_GIF_HEADER_SIZE;
+ mem_alloc_size = cFileSize;
if ((pEncodedData = (unsigned char *)malloc(mem_alloc_size)) == NULL) {
thumb_err("Memory Allocation to pEncodedData failed");
DrmCloseFile(hFile);
return NULL;
}
+ memset(pEncodedData,0,mem_alloc_size);
/* coverity[ -tainted_data_argument : pEncodedData ] */
if (DrmReadFile(hFile, pEncodedData, mem_alloc_size, &size) == FALSE) {
thumb_err("DrmReadFile was failed");