summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2015-08-07 00:40:46 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2015-08-07 01:10:15 (GMT)
commit7adbb6954d7f05fd02b9cded3741ce6ed2c9226b (patch)
tree5315a9e75f2283f559b18a8375f093b6eca10a3e /src
parent41f405edc8f31d877615c580ed6eb308d7eaebec (diff)
downloadlibmedia-thumbnail-7adbb6954d7f05fd02b9cded3741ce6ed2c9226b.zip
libmedia-thumbnail-7adbb6954d7f05fd02b9cded3741ce6ed2c9226b.tar.gz
libmedia-thumbnail-7adbb6954d7f05fd02b9cded3741ce6ed2c9226b.tar.bz2
Separate CMakeFiles for apply fPIE option Remove unused code Remove thumb_type Modify jpeg thumbnail creation logic when exif thumbnail is smaller than request thumbnail size Add scale down logic when request huge size image Fix bugs, memory leaks Remove unused parameters in function Change thumb path creation API position Remove thumbnail folder creation API Rename some functions Change-Id: I0e13d393dd524b61bcf44722c33b6f270649b732 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'src')
-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
-rwxr-xr-x[-rw-r--r--]src/include/codec/AGifFrameInfo.h4
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec-common.h27
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec-parser.h25
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec.h2
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h4
-rwxr-xr-xsrc/include/media-thumb-internal.h15
-rwxr-xr-xsrc/include/util/media-thumb-db.h2
-rwxr-xr-xsrc/include/util/media-thumb-util.h17
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c11
-rwxr-xr-xsrc/media-thumb-internal.c674
-rwxr-xr-xsrc/media-thumbnail.c83
-rwxr-xr-xsrc/util/media-thumb-db.c10
-rwxr-xr-xsrc/util/media-thumb-debug.c3
-rwxr-xr-xsrc/util/media-thumb-util.c65
18 files changed, 828 insertions, 1076 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");
diff --git a/src/include/codec/AGifFrameInfo.h b/src/include/codec/AGifFrameInfo.h
index 0f5aa81..e9c69b8 100644..100755
--- a/src/include/codec/AGifFrameInfo.h
+++ b/src/include/codec/AGifFrameInfo.h
@@ -55,8 +55,8 @@ typedef struct tagFrameInfo
unsigned short delay;
#ifdef INTERNAL_IMGCODEC
- unsigned int nRepeatCount;
- unsigned int nLoopCount;
+ int nRepeatCount;
+ int nLoopCount;
unsigned char bOneFrame;
#endif
diff --git a/src/include/codec/img-codec-common.h b/src/include/codec/img-codec-common.h
index 4cb8922..91887f5 100644..100755
--- a/src/include/codec/img-codec-common.h
+++ b/src/include/codec/img-codec-common.h
@@ -37,19 +37,20 @@ extern "C" {
#define IMG_MAX_IMAGE_FILE_SIZE (10 * 1024 * 1024)
//////////////////////////////////////////////////////////////
+#if 0
#define ImgDebug(type, fmt, arg...) \
do { \
fprintf(stderr, "[Media-SVC]"fmt, ##arg); \
}while(0)
-
-#if 1
+
+
#define SysRequireEx(expr, retValue) \
if (!(expr)) { \
fprintf(stderr, "[Media-SVC][%s] INVALID_PARAM (%d lines in %s)\n",__FUNCTION__, __LINE__, __FILE__); \
return (retValue); \
}
-#define SysDebug(X) ImgDebug X
-
+#define SysDebug(X) ImgDebug X
+
#define SysAssert(expr)
#else
#define SysRequireEx(expr, retValue)
@@ -73,24 +74,6 @@ typedef enum
IMG_INFO_MEM_ALLOC_FAIL = -6
}ImgFastCodecInfo;
-
-
-typedef enum
-{
- IMG_CODEC_UNKNOWN_TYPE = -2,
- IMG_CODEC_BIG_PROGRESSIVE_JPEG = -1,
- IMG_CODEC_NONE = 0,
- IMG_CODEC_GIF = ( 1 << 0),
- IMG_CODEC_PNG = ( 1 << 1),
- IMG_CODEC_WBMP = ( 1 << 2),
- IMG_CODEC_JPEG = ( 1 << 3),
- IMG_CODEC_BMP = ( 1 << 4),
- IMG_CODEC_TIF = ( 1 << 5),
- IMG_CODEC_AGIF = ( 1 << 6),
- IMG_CODEC_PROGRESSIVE_JPEG = ( 1 << 7),
- IMG_CODEC_DRM = ( 1 << 8),
-} ImgCodecType;
-
typedef enum inputFlag
{
IMG_RGB_888_OUTPUT = 0x0001,
diff --git a/src/include/codec/img-codec-parser.h b/src/include/codec/img-codec-parser.h
index 097f24d..b412416 100644..100755
--- a/src/include/codec/img-codec-parser.h
+++ b/src/include/codec/img-codec-parser.h
@@ -30,15 +30,32 @@ extern "C" {
#define PNG_HEADER_LENGTH 8
#define JPG_HEADER_LENGTH 2
-#define GIF_HEADER_LENGTH 3
+#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
-ImgCodecType ImgGetInfo(unsigned char* pEncodedData, unsigned long fileSize, ImgImageInfo* imgInfo);
-ImgCodecType ImgGetInfoFile(const char*filePath, ImgImageInfo *imgInfo);
-ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize, ImgImageInfo* imgInfo);
+typedef enum
+{
+ IMG_CODEC_UNKNOWN_TYPE = -2,
+ IMG_CODEC_BIG_PROGRESSIVE_JPEG = -1,
+ IMG_CODEC_NONE = 0,
+ IMG_CODEC_GIF = ( 1 << 0),
+ IMG_CODEC_PNG = ( 1 << 1),
+ IMG_CODEC_WBMP = ( 1 << 2),
+ IMG_CODEC_JPEG = ( 1 << 3),
+ IMG_CODEC_BMP = ( 1 << 4),
+ IMG_CODEC_TIF = ( 1 << 5),
+ IMG_CODEC_AGIF = ( 1 << 6),
+ IMG_CODEC_PROGRESSIVE_JPEG = ( 1 << 7),
+ IMG_CODEC_DRM = ( 1 << 8),
+} ImgCodecType;
+
+//ImgCodecType ImgGetInfoFile(const char*filePath, ImgImageInfo *imgInfo);
+int ImgGetImageInfo(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height);
+int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height);
#ifdef __cplusplus
}
diff --git a/src/include/codec/img-codec.h b/src/include/codec/img-codec.h
index 708c5ce..d365705 100644..100755
--- a/src/include/codec/img-codec.h
+++ b/src/include/codec/img-codec.h
@@ -30,7 +30,7 @@
extern "C" {
#endif /* __cplusplus */
-unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, ImgImageInfo *image_info);
+unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, unsigned int width, unsigned int height);
int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width, int height);
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
index fcd4560..7251ed9 100755
--- a/src/include/ipc/media-thumb-ipc.h
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -30,8 +30,6 @@
#include <signal.h>
#include <sys/types.h>
-#include "media-thumb-debug.h"
-#include "media-thumb-types.h"
#include "media-thumb-internal.h"
#include "media-util-ipc.h"
#include "media-server-ipc.h"
@@ -72,7 +70,6 @@ int _media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf,
int _media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **buf, int *buf_size);
int _media_thumb_request(int msg_type,
- media_thumb_type thumb_type,
const char *origin_path,
char *thumb_path,
int max_length,
@@ -80,7 +77,6 @@ int _media_thumb_request(int msg_type,
uid_t uid);
int _media_thumb_request_async(int msg_type,
- media_thumb_type thumb_type,
const char *origin_path,
thumbUserData *userData,
uid_t uid);
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index ad50b04..b059658 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -23,8 +23,6 @@
#include <media-util-err.h>
#include "media-thumbnail.h"
#include "media-thumb-util.h"
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#ifndef _MEDIA_THUMB_INTERNAL_H_
#define _MEDIA_THUMB_INTERNAL_H_
@@ -44,8 +42,9 @@ typedef struct {
int height;
int origin_width;
int origin_height;
- gboolean alpha;
+ int alpha;
unsigned char *data;
+ bool is_saved;
} media_thumb_info;
enum Exif_Orientation {
@@ -71,21 +70,21 @@ typedef struct {
} thumbRawUserData;
int _media_thumb_image(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
media_thumb_info *thumb_info,
- bool is_raw,
- uid_t uid);
+ bool is_req_raw);
int _media_thumb_video(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid);
+ media_thumb_info *thumb_info);
-int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
+int _media_thumb_get_hash_name(const char *file_full_path,
+ char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
int _media_thumb_save_to_file_with_evas(unsigned char *data,
int w,
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
index fcd284f..23ac277 100755
--- a/src/include/util/media-thumb-db.h
+++ b/src/include/util/media-thumb-db.h
@@ -21,8 +21,6 @@
#include <sqlite3.h>
#include <media-util.h>
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#ifndef _MEDIA_THUMB_DB_H_
#define _MEDIA_THUMB_DB_H_
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
index 3bb71df..de6d9f6 100755
--- a/src/include/util/media-thumb-util.h
+++ b/src/include/util/media-thumb-util.h
@@ -19,8 +19,6 @@
*
*/
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#include "media-util.h"
#include <tzplatform_config.h>
@@ -28,6 +26,13 @@
#define _MEDIA_THUMB_UTIL_H_
#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
+#define THUMB_MALLOC(src, size) { if (size <= 0) {src = NULL;} \
+ else { src = malloc(size); if(src) memset(src, 0x0, size);} }
+
+typedef enum {
+ MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */
+ MEDIA_THUMB_RGB888, /* RGB888 */
+} media_thumb_format;
#define THUMB_NONE_TYPE -1 /* None */
#define THUMB_IMAGE_TYPE 0 /* Image */
@@ -47,23 +52,17 @@ typedef enum
THUMB_MMC /**< Stored only in MMC */
} media_thumb_store_type;
-int _media_thumb_get_length(media_thumb_type thumb_type);
-
int _media_thumb_get_store_type_by_path(const char *full_path);
int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len);
int _media_thumb_get_file_type(const char *file_full_path);
-int _media_thumb_remove_file(const char *path);
-
char* _media_thumb_generate_hash_name(const char *file);
int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
-int _media_thumb_get_width(media_thumb_type thumb_type);
-
-int _media_thumb_get_height(media_thumb_type thumb_type);
+int _media_thumb_remove_file(const char *path);
#endif /*_MEDIA_THUMB_UTIL_H_*/
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 7a94900..7920fe7 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -379,7 +379,7 @@ _media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **bu
}
int
-_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
+_media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
{
int sock = -1;
struct sockaddr_un serv_addr;
@@ -419,7 +419,6 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
/* Set requset message */
req_msg.msg_type = msg_type;
- req_msg.thumb_type = thumb_type;
req_msg.uid = uid;
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
@@ -585,7 +584,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
return FALSE;
}
-int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData, uid_t uid)
+int _media_thumb_request_async(int msg_type, const char *origin_path, thumbUserData *userData, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
int sock = -1;
@@ -623,8 +622,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
}
if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
- //source_id = g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData );
-
/* Create new channel to watch udp socket */
GSource *source = NULL;
source = g_io_create_watch(channel, G_IO_IN);
@@ -640,7 +637,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
pid = getpid();
req_msg.pid = pid;
req_msg.msg_type = msg_type;
- req_msg.thumb_type = thumb_type;
req_msg.uid = uid;
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
@@ -677,8 +673,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) {
g_io_channel_shutdown(channel, TRUE, NULL);
-
- //thumb_dbg("Cancel : %s[%d]", origin_path, sock);
__media_thumb_pop_req_queue(origin_path, TRUE);
} else if (msg_type == THUMB_REQUEST_DB_INSERT) {
if (g_request_queue == NULL) {
@@ -753,7 +747,6 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
pid = getpid();
req_msg.pid = pid;
req_msg.msg_type = msg_type;
- req_msg.thumb_type = MEDIA_THUMB_LARGE;
req_msg.request_id = request_id;
req_msg.thumb_width = width;
req_msg.thumb_height = height;
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index 5ed752d..04c92c4 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -52,12 +52,17 @@
#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
#define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
-int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
- int orig_w, int orig_h,
+int _media_thumb_resize_data(unsigned char *src_data,
+ int src_width,
+ int src_height,
+ mm_util_img_format src_format,
+ media_thumb_info *thumb_info,
+ int dst_width,
+ int dst_height);
+
+int _media_thumb_get_proper_thumb_size(int orig_w, int orig_h,
int *thumb_w, int *thumb_h)
{
- thumb_dbg("orig w: %d orig h: %d thumb type: %d", orig_w, orig_h, thumb_type);
-
BOOL portrait = FALSE;
double ratio;
@@ -67,23 +72,13 @@ int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
/* Set smaller length to default size */
if (portrait) {
- if (orig_w < _media_thumb_get_width(thumb_type)) {
+ if (orig_w < *thumb_w)
*thumb_w = orig_w;
- } else {
- *thumb_w = _media_thumb_get_width(thumb_type);
- }
-
ratio = (double)orig_h / (double)orig_w;
*thumb_h = *thumb_w * ratio;
-
} else {
-
- if (orig_h < _media_thumb_get_width(thumb_type)) {
+ if (orig_h < *thumb_h)
*thumb_h = orig_h;
- } else {
- *thumb_h = _media_thumb_get_width(thumb_type);
- }
-
ratio = (double)orig_w / (double)orig_h;
*thumb_w = *thumb_h * ratio;
}
@@ -138,27 +133,18 @@ int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value
return MS_MEDIA_ERR_NONE;
}
-int _media_thumb_get_thumb_from_exif(ExifData *ed,
- const char *file_full_path,
- int orientation,
- int required_width,
- int required_height,
- media_thumb_info *thumb_info, uid_t uid)
+static int _media_thumb_get_data_from_exif(ExifData *ed,
+ void **thumb_data,
+ int *thumb_size,
+ int *thumb_width,
+ int *thumb_height,
+ int *origin_width,
+ int *origin_height)
{
ExifEntry *entry;
ExifIfd ifd;
ExifTag tag;
- int err = -1;
- int size = 0;
- int thumb_width = 0;
- int thumb_height = 0;
- void *thumb = NULL;
-
- if (ed == NULL) {
- return -1;
- }
-
ExifByteOrder byte_order = exif_data_get_byte_order(ed);
ifd = EXIF_IFD_1;
@@ -182,241 +168,239 @@ int _media_thumb_get_thumb_from_exif(ExifData *ed,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ /* copy the real thumbnail data from exif data */
+ if (ed->data && ed->size) {
+ //thumb_dbg("Size: %d, thumb: 0x%x", ed->size, ed->data);
+ *thumb_data = (char *)malloc(ed->size);
+
+ if (*thumb_data == NULL) {
+ thumb_dbg("malloc failed!");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ memcpy(*thumb_data, (void *)ed->data, ed->size);
+ *thumb_size = ed->size;
+ } else {
+ thumb_dbg("data is NULL");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
/* Get width and height of thumbnail */
tag = EXIF_TAG_IMAGE_WIDTH;
entry = exif_content_get_entry(ed->ifd[ifd], tag);
if (entry) {
/* Get the contents of the tag in human-readable form */
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
+ char width[10] = {0,};
+ exif_entry_get_value(entry,width,10);
- thumb_width = value;
+ *thumb_width = atoi(width);
+ } else {
+ thumb_warn("EXIF_TAG_IMAGE_WIDTH does not exist");
+ *thumb_width = 0;
}
tag = EXIF_TAG_IMAGE_LENGTH;
entry = exif_content_get_entry(ed->ifd[ifd], tag);
if (entry) {
/* Get the contents of the tag in human-readable form */
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
-
- thumb_height = value;
- }
+ char height[10] = {0,};
+ exif_entry_get_value(entry,height,10);
- if (ed->data && ed->size) {
- //thumb_dbg("Size: %d, thumb: 0x%x\n", ed->size, ed->data);
- thumb = (char *)malloc(ed->size);
-
- if (thumb == NULL) {
- thumb_dbg("malloc failed!");
- return -1;
- }
-
- memcpy(thumb, (void *)ed->data, ed->size);
- size = ed->size;
+ *thumb_height = atoi(height);
} else {
- thumb_dbg("data is NULL");
- return -1;
+ thumb_warn("EXIF_TAG_IMAGE_LENGTH does not exist");
+ *thumb_height = 0;
}
+ thumb_dbg("thumb width : height [%d:%d]", *thumb_width, *thumb_height);
+
/* Get width and height of original image from exif */
ifd = EXIF_IFD_EXIF;
tag = EXIF_TAG_PIXEL_X_DIMENSION;
entry = exif_content_get_entry(ed->ifd[ifd], tag);
if (entry) {
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
- thumb_info->origin_width = value;
+ char width[10] = {0,};
+ exif_entry_get_value(entry,width,10);
+
+ *origin_width = atoi(width);
} else {
- thumb_dbg("entry is NULL");
+ thumb_warn("EXIF_TAG_PIXEL_X_DIMENSION does not exist");
+ *origin_width = 0;
}
tag = EXIF_TAG_PIXEL_Y_DIMENSION;
entry = exif_content_get_entry(ed->ifd[ifd], tag);
if (entry) {
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
- thumb_info->origin_height = value;
- } else {
- thumb_dbg("entry is NULL");
- }
-
- char thumb_path[1024];
+ char height[10] = {0,};
+ exif_entry_get_value(entry,height,10);
- err =
- _media_thumb_get_hash_name(file_full_path,
- thumb_path,
- sizeof(thumb_path), uid);
- if (err < 0) {
- thumb_dbg("_media_thumb_get_hash_name failed\n");
- SAFE_FREE(thumb);
- return err;
- }
-
- thumb_dbg("Thumb is :%s", thumb_path);
-
- int nwrite;
- int fd = open(thumb_path, O_RDWR | O_CREAT | O_EXCL | O_SYNC, 0644);
- if (fd < 0) {
- if (errno == EEXIST) {
- thumb_dbg("thumb alread exist!");
- } else {
- thumb_dbg("open failed\n");
- SAFE_FREE(thumb);
- return -1;
- }
+ *origin_height = atoi(height);
} else {
- nwrite = write(fd, thumb, size);
- if (nwrite < 0) {
- thumb_dbg("write failed\n");
- close(fd);
-
- SAFE_FREE(thumb);
- return -1;
- }
- close(fd);
+ thumb_warn("EXIF_TAG_PIXEL_Y_DIMENSION does not exist");
+ *origin_height = 0;
}
- SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_NONE;
+}
+int _media_thumb_get_thumb_from_exif(ExifData *ed,
+ const char *file_full_path,
+ const char *thumb_path,
+ int orientation,
+ int required_width,
+ int required_height,
+ media_thumb_info *thumb_info)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ int size = 0;
+ int thumb_width = 0;
+ int thumb_height = 0;
+ int origin_width = 0;
+ int origin_height = 0;
+ void *thumb = NULL;
+ bool is_rotated = (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) ? TRUE : FALSE;
mm_util_jpeg_yuv_data decoded = {0,};
- err = mm_util_decode_from_jpeg_file(&decoded, thumb_path, MM_UTIL_JPEG_FMT_RGB888);
- if (err < 0) {
- thumb_dbg("mm_util_decode_from_jpeg_turbo_memory failed : %d", err);
- return err;
+ if (ed == NULL) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- //thumb_dbg("size:%d, w:%d, h:%d\n", decoded.size, decoded.width, decoded.height);
-
- thumb_width = decoded.width;
- thumb_height = decoded.height;
-
- media_thumb_type thumb_type;
- int need_resize = 0;
- unsigned int buf_size = decoded.size;
-
- if (required_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
+ err = _media_thumb_get_data_from_exif(ed,
+ &thumb,
+ &size,
+ &thumb_width,
+ &thumb_height,
+ &origin_width,
+ &origin_height);
- if (thumb_type == MEDIA_THUMB_LARGE) {
- if (thumb_width < _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_dbg("Thumb data in exif is too small for MEDIA_THUMB_LARGE");
- SAFE_FREE(decoded.data);
- return -1;
- }
- } else {
- if (thumb_width > _media_thumb_get_width(MEDIA_THUMB_SMALL)) {
- need_resize = 1;
- }
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("There is no exif data");
+ return err;
}
- if (need_resize == 1) {
- int resized_w = _media_thumb_get_width(MEDIA_THUMB_LARGE);
- int resized_h = _media_thumb_get_height(MEDIA_THUMB_LARGE);
+ thumb_dbg("thumb width : height [%d:%d]", thumb_width, thumb_height);
+ thumb_dbg("origin width : height [%d:%d]", origin_width, origin_height);
+ thumb_info->origin_height = origin_height;
+ thumb_info->origin_width = origin_width;
- err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, resized_w, resized_h, &buf_size);
- if (err < 0) {
- thumb_dbg("mm_util_get_image_size failed : %d", err);
+ if (thumb_width < required_width) {
+ thumb_err("Thumb data in exif is too small");
+ SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
- SAFE_FREE(decoded.data);
+ if (is_rotated) {
+ err = mm_util_decode_from_jpeg_memory(&decoded, thumb, size, MM_UTIL_JPEG_FMT_RGB888);
+ SAFE_FREE(thumb);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_decode_from_jpeg_turbo_memory failed : %d", err);
return err;
}
- //thumb_dbg("size(RGB888) : %d", buf_size);
-
- unsigned char *dst = (unsigned char *)malloc(buf_size);
- if (dst == NULL) {
- thumb_err("Failed to allocate memory!");
- SAFE_FREE(decoded.data);
- return -1;
- }
+ thumb_width = decoded.width;
+ thumb_height = decoded.height;
- if (mm_util_resize_image(decoded.data, thumb_width,
- thumb_height, MM_UTIL_IMG_FMT_RGB888,
- dst, (unsigned int *)&resized_w,
- (unsigned int *)&resized_h) < 0) {
- thumb_err("Failed to resize the thumbnails");
+ if (is_rotated) {
+ /* Start to decode to rotate */
+ unsigned char *rotated = NULL;
+ unsigned int r_w = decoded.height;
+ unsigned int r_h = decoded.width;
+ unsigned int r_size = 0;
+ mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
- SAFE_FREE(decoded.data);
- SAFE_FREE(dst);
+ int i, rotate_cnt = 0;
- return -1;
- }
+ rot_type = MM_UTIL_ROTATE_90;
+ if (orientation == ROT_90) {
+ rotate_cnt = 1;
+ } else if (orientation == ROT_180) {
+ rotate_cnt = 2;
+ } else if (orientation == ROT_270) {
+ rotate_cnt = 3;
+ }
- SAFE_FREE(decoded.data);
- decoded.data = dst;
- decoded.width = thumb_width = resized_w;
- decoded.height = thumb_height = resized_h;
- }
+ for (i = 0; i < rotate_cnt; i++) {
+ if (i == 1) {
+ r_w = decoded.width;
+ r_h = decoded.height;
+ }
- if (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) {
- /* Start to decode to rotate */
- unsigned char *rotated = NULL;
- unsigned int r_w = decoded.height;
- unsigned int r_h = decoded.width;
- unsigned int r_size = 0;
- mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
+ err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_get_image_size failed : %d", err);
+ SAFE_FREE(decoded.data);
+ return err;
+ }
- if (orientation == ROT_90) {
- rot_type = MM_UTIL_ROTATE_90;
- } else if (orientation == ROT_180) {
- rot_type = MM_UTIL_ROTATE_180;
- r_w = decoded.width;
- r_h = decoded.height;
- } else if (orientation == ROT_270) {
- rot_type = MM_UTIL_ROTATE_270;
- }
+ rotated = (unsigned char *)malloc(r_size);
+ err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height,
+ MM_UTIL_IMG_FMT_RGB888,
+ rotated, &r_w, &r_h,
+ rot_type);
- err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
- if (err < 0) {
- thumb_dbg("mm_util_get_image_size failed : %d", err);
- SAFE_FREE(decoded.data);
- return err;
- }
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_rotate_image failed : %d", err);
+ SAFE_FREE(decoded.data);
+ SAFE_FREE(rotated);
+ return err;
+ } else {
+ thumb_err("mm_util_rotate_image succeed");
+ }
- //thumb_dbg("Size of Rotated : %d", r_size);
+ SAFE_FREE(decoded.data);
+ decoded.data = rotated;
+ decoded.width = r_w;
+ decoded.height = r_h;
+ }
- rotated = (unsigned char *)malloc(r_size);
- err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height,
- MM_UTIL_IMG_FMT_RGB888,
- rotated, &r_w, &r_h,
- rot_type);
-
- if (err < 0) {
- thumb_err("mm_util_rotate_image failed : %d", err);
- SAFE_FREE(decoded.data);
- SAFE_FREE(rotated);
- return err;
+ //thumb_dbg("Width : %d, Height : %d", r_w, r_h);
+ thumb_info->data = rotated;
+ thumb_info->size = r_size;
+ thumb_info->width = r_w;
+ thumb_info->height = r_h;
} else {
- thumb_dbg("mm_util_rotate_image succeed");
+ thumb_warn("Unknown orientation");
+ SAFE_FREE(decoded.data);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ }else {
+ /*in this case, just write raw data in file */
+ thumb_dbg_slog("Thumb is :%s", thumb_path);
+
+ int nwrite;
+ int fd = open(thumb_path, O_RDWR | O_CREAT | O_EXCL | O_SYNC, 0644);
+ if (fd < 0) {
+ if (errno == EEXIST) {
+ thumb_err("thumb alread exist!");
+ } else {
+ thumb_err("open failed");
+ SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ } else {
+ nwrite = write(fd, thumb, size);
+ if (nwrite < 0) {
+ thumb_err("write failed");
+ close(fd);
- SAFE_FREE(decoded.data);
+ SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ close(fd);
+ }
- //thumb_dbg("Width : %d, Height : %d", r_w, r_h);
- thumb_info->data = rotated;
- thumb_info->size = r_size;
- thumb_info->width = r_w;
- thumb_info->height = r_h;
- } else if (orientation == NORMAL) {
- thumb_info->data = decoded.data;
- thumb_info->size = buf_size;
+ SAFE_FREE(thumb);
+ thumb_info->data = NULL;
+ thumb_info->size = size;
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
- } else {
- thumb_warn("Unknown orientation");
- SAFE_FREE(decoded.data);
- return -1;
+ thumb_info->is_saved = TRUE;
}
- return 0;
+ return err;
}
int _media_thumb_resize_data(unsigned char *src_data,
@@ -455,8 +439,12 @@ int _media_thumb_resize_data(unsigned char *src_data,
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
thumb_info->data = malloc(buf_size);
- memcpy(thumb_info->data, dst, buf_size);
-
+ if(thumb_info->data != NULL) {
+ memcpy(thumb_info->data, dst, buf_size);
+ } else {
+ thumb_err("malloc fails");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
SAFE_FREE(dst);
return MS_MEDIA_ERR_NONE;
@@ -553,17 +541,8 @@ int _media_thumb_decode_with_evas(const char *origin_path,
//thumb_dbg("rotated - origin width:%d, origin height:%d", rotated_orig_w, rotated_orig_h);
int err = MS_MEDIA_ERR_NONE;
- media_thumb_type thumb_type;
-
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
- err = _media_thumb_get_proper_thumb_size(thumb_type,
- rotated_orig_w, rotated_orig_h,
- &thumb_width, &thumb_height);
+ err = _media_thumb_get_proper_thumb_size(rotated_orig_w, rotated_orig_h, &thumb_width, &thumb_height);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
ecore_evas_free(resize_img_ee);
@@ -755,7 +734,8 @@ int _media_thumb_convert_format(media_thumb_info *thumb_info,
}
int _media_thumb_agif(const char *origin_path,
- ImgImageInfo *image_info,
+ int image_width,
+ int image_height,
int thumb_width,
int thumb_height,
media_thumb_format format,
@@ -763,24 +743,15 @@ int _media_thumb_agif(const char *origin_path,
{
int err = MS_MEDIA_ERR_NONE;
unsigned int *thumb = NULL;
- media_thumb_type thumb_type;
- thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
+ thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_width, image_height);
if (!thumb) {
thumb_err("Frame data is NULL!!");
return MS_MEDIA_ERR_INTERNAL;
}
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
-
- err = _media_thumb_get_proper_thumb_size(thumb_type,
- thumb_info->origin_width, thumb_info->origin_height,
- &thumb_width, &thumb_height);
+ err = _media_thumb_get_proper_thumb_size(thumb_info->origin_width, thumb_info->origin_height, &thumb_width, &thumb_height);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
SAFE_FREE(thumb);
@@ -788,8 +759,8 @@ int _media_thumb_agif(const char *origin_path,
}
err = _media_thumb_resize_data((unsigned char *)thumb,
- image_info->width,
- image_info->height,
+ image_width,
+ image_height,
MM_UTIL_IMG_FMT_RGB888,
thumb_info,
thumb_width,
@@ -910,11 +881,11 @@ int _media_thumb_gif(const char *origin_path,
}
int _media_thumb_jpeg(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
ExifData *ed = NULL;
@@ -933,7 +904,7 @@ int _media_thumb_jpeg(const char *origin_path,
}
/* Second, Get thumb from exif */
- err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info, uid);
+ err = _media_thumb_get_thumb_from_exif(ed, origin_path, thumb_path, orientation, thumb_width, thumb_height, thumb_info);
if (err != MS_MEDIA_ERR_NONE) {
thumb_dbg("_media_thumb_get_thumb_from_exif failed");
@@ -941,18 +912,31 @@ int _media_thumb_jpeg(const char *origin_path,
thumb_done = 1;
thumb_dbg("_media_thumb_get_thumb_from_exif succeed");
- mm_util_img_format dst_format = _media_thumb_get_format(format);
+ /* The case that original image's size is not in exif header. Use evas to get w/h */
+ if (thumb_info->origin_width == 0 || thumb_info->origin_height == 0) {
+ thumb_warn("original image's size is not in exif header. Use evas to get w/h");
+ err = _media_thumb_get_wh_with_evas(origin_path, &(thumb_info->origin_width), &(thumb_info->origin_height));
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("Couldn't get w/h using evas : %s", origin_path);
+ } else {
+ thumb_dbg("origin w : %d, origin h : %d", thumb_info->origin_width, thumb_info->origin_height);
+ }
+ }
+
+ if (thumb_info->is_saved == FALSE) {
+ mm_util_img_format dst_format = _media_thumb_get_format(format);
- err = _media_thumb_convert_data(thumb_info,
- thumb_info->width,
- thumb_info->height,
- MM_UTIL_IMG_FMT_RGB888,
- dst_format);
+ err = _media_thumb_convert_data(thumb_info,
+ thumb_info->width,
+ thumb_info->height,
+ MM_UTIL_IMG_FMT_RGB888,
+ dst_format);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_convert_data failed : %d", err);
- exif_data_unref(ed);
- return err;
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_convert_data failed : %d", err);
+ exif_data_unref(ed);
+ return err;
+ }
}
}
@@ -980,11 +964,11 @@ int _media_thumb_jpeg(const char *origin_path,
}
int _media_thumb_jpeg_for_raw(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
int orientation = NORMAL;
@@ -1006,23 +990,26 @@ int _media_thumb_jpeg_for_raw(const char *origin_path,
}
int _media_thumb_image(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
media_thumb_info *thumb_info,
- bool is_raw,
- uid_t uid)
+ bool is_req_raw)
{
int err = MS_MEDIA_ERR_NONE;
- int image_type = 0;
- int origin_w = 0;
- int origin_h = 0;
- ImgImageInfo image_info = { 0 };
+ ImgCodecType image_type = 0;
+ unsigned int origin_w = 0;
+ unsigned int origin_h = 0;
- image_type = ImgGetInfoFile(origin_path, &image_info);
+ err = ImgGetImageInfoForThumb(origin_path, &image_type, &origin_w, &origin_h);
+
+ if (err != MS_MEDIA_ERR_NONE){
+ thumb_warn("Getting image info is failed err: %d", err);
+ }
- thumb_info->origin_width = origin_w = image_info.width;
- thumb_info->origin_height = origin_h = image_info.height;
+ thumb_info->origin_width = origin_w;
+ thumb_info->origin_height = origin_h;
//thumb_dbg("image type is %d, width:%d, height:%d", image_type, origin_w, origin_h);
@@ -1033,12 +1020,12 @@ int _media_thumb_image(const char *origin_path,
}
if (image_type == IMG_CODEC_AGIF) {
- err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info);
+ err = _media_thumb_agif(origin_path, origin_w, origin_h, thumb_width, thumb_height, format, thumb_info);
} else if (image_type == IMG_CODEC_JPEG) {
- if(is_raw) {
- err = _media_thumb_jpeg_for_raw(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
+ if(is_req_raw == TRUE) {
+ err = _media_thumb_jpeg_for_raw(origin_path, thumb_path, thumb_width, thumb_height, format, thumb_info);
} else {
- err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
+ err = _media_thumb_jpeg(origin_path, thumb_path, thumb_width, thumb_height, format, thumb_info);
}
} else if (image_type == IMG_CODEC_PNG) {
err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info);
@@ -1088,8 +1075,7 @@ int _media_thumb_video(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
@@ -1104,7 +1090,59 @@ int _media_thumb_video(const char *origin_path,
bool drm_type = FALSE;
is_drm = drm_type;
- err = mm_file_create_content_attrs(&content, origin_path);
+
+ /* Get Content Tag attribute for orientatin */
+ MMHandleType tag = (MMHandleType) NULL;
+ char *p = NULL;
+ int cdis_value = 0;
+ err = mm_file_create_tag_attrs(&tag, origin_path);
+ mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
+
+ if (err == MM_ERROR_NONE) {
+ err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
+ if (err == MM_ERROR_NONE && size >= 0) {
+ if (p == NULL) {
+ rot_type = MM_UTIL_ROTATE_0;
+ } else {
+ if (strncmp(p, "90", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_90;
+ } else if(strncmp(p, "180", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_180;
+ } else if(strncmp(p, "270", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_270;
+ } else {
+ rot_type = MM_UTIL_ROTATE_0;
+ }
+ }
+ thumb_dbg("There is tag rotate : %d", rot_type);
+ } else {
+ thumb_dbg("There is NOT tag rotate");
+ rot_type = MM_UTIL_ROTATE_0;
+ SAFE_FREE(err_msg);
+ }
+
+ err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
+ if (err != MM_ERROR_NONE) {
+ cdis_value = 0;
+ SAFE_FREE(err_msg);
+ }
+
+ } else {
+ rot_type = MM_UTIL_ROTATE_0;
+ cdis_value = 0;
+ }
+
+ err = mm_file_destroy_tag_attrs(tag);
+ if (err != MM_ERROR_NONE) {
+ thumb_err("fail to free tag attr - err(%x)", err);
+ }
+
+ if (cdis_value == 1) {
+ thumb_warn("This is CDIS vlaue 1");
+ err = mm_file_create_content_attrs_safe(&content, origin_path);
+ } else {
+ err = mm_file_create_content_attrs(&content, origin_path);
+ }
if (err != MM_ERROR_NONE) {
thumb_err("mm_file_create_content_attrs fails : %d", err);
@@ -1148,17 +1186,10 @@ int _media_thumb_video(const char *origin_path,
return MS_MEDIA_ERR_INTERNAL;
}
- media_thumb_type thumb_type;
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
-
thumb_info->origin_width = width;
thumb_info->origin_height = height;
- err = _media_thumb_get_proper_thumb_size(thumb_type, width, height, &thumb_width, &thumb_height);
+ err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
if (width > thumb_width || height > thumb_height) {
err = _media_thumb_resize_data(frame,
@@ -1180,48 +1211,15 @@ int _media_thumb_video(const char *origin_path,
thumb_info->width = width;
thumb_info->height = height;
thumb_info->data = malloc(size);
+ if (thumb_info->data == NULL) {
+ thumb_err("memory allcation failed" );
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
memcpy(thumb_info->data, frame, size);
}
mm_file_destroy_content_attrs(content);
-
- /* Get Content Tag attribute for orientatin */
- MMHandleType tag = (MMHandleType) NULL;
- char *p = NULL;
- int size = -1;
- err = mm_file_create_tag_attrs(&tag, origin_path);
- mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
-
- if (err == MM_ERROR_NONE) {
- err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
- if (err == MM_ERROR_NONE && size >= 0) {
-
- if (p == NULL) {
- rot_type = MM_UTIL_ROTATE_0;
- } else {
- if (strncmp(p, "90", size) == 0) {
- rot_type = MM_UTIL_ROTATE_90;
- } else if(strncmp(p, "180", size) == 0) {
- rot_type = MM_UTIL_ROTATE_180;
- } else if(strncmp(p, "270", size) == 0) {
- rot_type = MM_UTIL_ROTATE_270;
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- }
- }
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- SAFE_FREE(err_msg);
- }
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- }
-
- err = mm_file_destroy_tag_attrs(tag);
- if (err != MM_ERROR_NONE) {
- thumb_err("fail to free tag attr - err(%x)", err);
- }
-
if (rot_type == MM_UTIL_ROTATE_90 || rot_type == MM_UTIL_ROTATE_180 || rot_type == MM_UTIL_ROTATE_270) {
/* Start to decode to rotate */
unsigned char *rotated = NULL;
@@ -1281,24 +1279,6 @@ int _media_thumb_video(const char *origin_path,
return err;
}
-static int _mkdir(const char *dir, mode_t mode) {
- char tmp[256];
- char *p = NULL;
- size_t len;
-
- snprintf(tmp, sizeof(tmp),"%s",dir);
- len = strlen(tmp);
- if(tmp[len - 1] == '/')
- tmp[len - 1] = 0;
- for(p = tmp + 1; *p; p++)
- if(*p == '/') {
- *p = 0;
- mkdir(tmp, mode);
- *p = '/';
- }
- return mkdir(tmp, mode);
-}
-
static char* _media_thumb_mmc_get_path(uid_t uid)
{
char *result_psswd = NULL;
@@ -1333,8 +1313,6 @@ static char* _media_thumb_mmc_get_path(uid_t uid)
}
asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
}
-
- _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
return result_psswd;
}
@@ -1374,56 +1352,58 @@ static char* _media_thumb_phone_get_path(uid_t uid)
asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
}
- _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
-
return result_psswd;
}
int _media_thumb_get_hash_name(const char *file_full_path,
char *thumb_hash_path, size_t max_thumb_path, uid_t uid)
{
- char *hash_name;
- char *thumb_dir = NULL;
+ char *hash_name = NULL;
+ /*char *thumb_dir = NULL;*/
char file_ext[255] = { 0 };
+ int ret_len = 0;
media_thumb_store_type store_type = -1;
if (file_full_path == NULL || thumb_hash_path == NULL
|| max_thumb_path <= 0) {
thumb_err
("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0");
- return -1;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
_media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
store_type = _media_thumb_get_store_type_by_path(file_full_path);
- if (store_type == THUMB_PHONE) {
+ /*if (store_type == THUMB_PHONE) {
thumb_dir = _media_thumb_phone_get_path(uid);
} else if (store_type == THUMB_MMC) {
thumb_dir = _media_thumb_mmc_get_path(uid);
} else {
thumb_dir = _media_thumb_phone_get_path(uid);
- }
+ }*/
hash_name = _media_thumb_generate_hash_name(file_full_path);
+ if(hash_name == NULL)
+ {
+ thumb_err("_media_thumb_generate_hash_name fail");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
- int ret_len;
- ret_len =
- snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg",
- thumb_dir, file_ext, hash_name);
- if(thumb_dir)
- free(thumb_dir);
- if (ret_len < 0) {
- thumb_err("Error when snprintf");
- return -1;
- } else if (ret_len > max_thumb_path) {
- thumb_err("Error for the length of thumb pathname");
- return -1;
+ if (store_type == THUMB_PHONE) {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
+ } else if (store_type == THUMB_MMC) {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_mmc_get_path(uid), file_ext, hash_name);
+ } else {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
}
+ if ((ret_len < 0) || (ret_len > (int)max_thumb_path)) {
+ thumb_err("invalid hash path ret_len[%d]", ret_len);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
//thumb_dbg("thumb hash : %s", thumb_hash_path);
- return 0;
+ return MS_MEDIA_ERR_NONE;
}
@@ -1474,4 +1454,4 @@ int _media_thumb_save_to_file_with_evas(unsigned char *data,
ecore_evas_free(ee);
return MS_MEDIA_ERR_INTERNAL;
}
-} \ No newline at end of file
+}
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index 39d2ebf..e5f6c2b 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -24,77 +24,9 @@
#include "media-thumb-util.h"
#include "media-thumb-internal.h"
#include "media-thumb-ipc.h"
-//#include "media-thumb-db.h"
#include <glib.h>
-int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- //int need_update_db = 0;
- media_thumb_info thumb_info;
-
- if (origin_path == NULL || thumb_path == NULL) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (!g_file_test
- (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
- thumb_err("Original path(%s) doesn't exist.", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (max_length <= 0) {
- thumb_err("Length is invalid");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- int store_type = -1;
- store_type = _media_thumb_get_store_type_by_path(origin_path);
-
- if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) {
- thumb_err("origin path(%s) is invalid", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- thumb_dbg_slog("Path : %s", origin_path);
-
- /* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- if (origin_path == NULL || thumb_path == NULL) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- media_thumb_info thumb_info;
- char tmp_thumb_path[MAX_PATH_SIZE + 1] = {0,};
-
- strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
- tmp_thumb_path[sizeof(tmp_thumb_path) - 1] = '\0';
-
- /* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
@@ -133,7 +65,7 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat
thumb_dbg_slog("Path : %s", origin_path);
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, origin_path, thumb_path, max_length, &thumb_info, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -150,12 +82,11 @@ int thumbnail_request_extract_all_thumbs(uid_t uid)
int err = MS_MEDIA_ERR_NONE;
media_thumb_info thumb_info;
- media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
char tmp_origin_path[MAX_PATH_SIZE] = {0,};
char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -194,7 +125,7 @@ int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, voi
userData->user_data = user_data;
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData, uid);
+ err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, origin_path, userData, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
SAFE_FREE(userData);
@@ -246,14 +177,12 @@ int thumbnail_request_cancel_media(const char *origin_path, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
- media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
-
if (origin_path == NULL) {
thumb_err("Invalid parameter");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL, uid);
+ err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, origin_path, NULL, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -291,9 +220,9 @@ int thumbnail_request_cancel_all(bool is_raw_data, uid_t uid)
/* Request for thumb file to the daemon "Thumbnail generator" */
if(is_raw_data) {
- err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL_RAW_DATA, MEDIA_THUMB_LARGE, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL_RAW_DATA, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
} else {
- err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, MEDIA_THUMB_LARGE, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
}
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index 76c737e..0dceec7 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -257,6 +257,10 @@ int _media_thumb_update_thumb_path_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(thumbpath_string);
+ sqlite3_free(query_string);
+
return err;
}
@@ -285,6 +289,9 @@ int _media_thumb_update_wh_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(query_string);
+
return err;
}
@@ -314,6 +321,9 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(query_string);
+
return err;
}
diff --git a/src/util/media-thumb-debug.c b/src/util/media-thumb-debug.c
index a9ce049..9515505 100755
--- a/src/util/media-thumb-debug.c
+++ b/src/util/media-thumb-debug.c
@@ -27,7 +27,7 @@
#ifdef _PERFORMANCE_CHECK_
static long g_time_usec = 0L;
-#endif
+
#ifdef _USE_LOG_FILE_
static FILE *g_log_fp = NULL;
@@ -109,3 +109,4 @@ thumb_print_debug_time_ex(long start, long end, const char *func_name,
totaltime);
#endif
}
+#endif \ No newline at end of file
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
index 3ba1c06..c487b6e 100755
--- a/src/util/media-thumb-util.c
+++ b/src/util/media-thumb-util.c
@@ -27,52 +27,12 @@
#include <aul.h>
#include <string.h>
-int _media_thumb_get_width(media_thumb_type thumb_type)
-{
- if (thumb_type == MEDIA_THUMB_LARGE) {
- return THUMB_LARGE_WIDTH;
- } else if (thumb_type == MEDIA_THUMB_SMALL) {
- return THUMB_SMALL_WIDTH;
- } else {
- return -1;
- }
-}
-
-int _media_thumb_get_height(media_thumb_type thumb_type)
-{
- if (thumb_type == MEDIA_THUMB_LARGE) {
- return THUMB_LARGE_HEIGHT;
- } else if (thumb_type == MEDIA_THUMB_SMALL) {
- return THUMB_SMALL_HEIGHT;
- } else {
- return -1;
- }
-}
-
-int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
-{
- int i = 0;
-
- for (i = strlen(file_path); i >= 0; i--) {
- if ((file_path[i] == '.') && (i < strlen(file_path))) {
- strncpy(file_ext, &file_path[i + 1], max_len);
- return 0;
- }
-
- /* meet the dir. no ext */
- if (file_path[i] == '/') {
- return -1;
- }
- }
-
- return -1;
-}
-
int
_media_thumb_get_file_type(const char *file_full_path)
{
int ret = 0;
char mimetype[255] = {0,};
+ const char *unsupported_type = "image/tiff";
if (file_full_path == NULL)
return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -116,6 +76,10 @@ _media_thumb_get_file_type(const char *file_full_path)
/* categorize from mimetype */
if (strstr(mimetype, "image") != NULL) {
+ if (!strcmp(mimetype, unsupported_type)) {
+ thumb_warn("This is unsupport file type");
+ return THUMB_NONE_TYPE;
+ }
return THUMB_IMAGE_TYPE;
} else if (strstr(mimetype, "video") != NULL) {
return THUMB_VIDEO_TYPE;
@@ -149,4 +113,23 @@ int _media_thumb_remove_file(const char *path)
thumb_stderror("fail to remove file[%s] result");
return FALSE;
}
+}
+
+int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
+
+ 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;
+ }
+
+ /* meet the dir. no ext */
+ if (file_path[i] == '/') {
+ return -1;
+ }
+ }
+
+ return -1;
} \ No newline at end of file