summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/codec/IfegDecodeAGIF.c4169
-rw-r--r--src/codec/img-codec-osal.c166
-rw-r--r--src/codec/img-codec-parser.c887
-rw-r--r--src/codec/img-codec.c266
-rw-r--r--src/include/codec/AGifFrameInfo.h65
-rw-r--r--src/include/codec/IfegDecodeAGIF.h57
-rw-r--r--src/include/codec/img-codec-agif.h28
-rw-r--r--src/include/codec/img-codec-common.h304
-rw-r--r--src/include/codec/img-codec-config.h26
-rw-r--r--src/include/codec/img-codec-osal.h129
-rw-r--r--src/include/codec/img-codec-parser.h48
-rw-r--r--src/include/codec/img-codec.h49
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h125
-rwxr-xr-xsrc/include/media-thumb-internal.h81
-rwxr-xr-xsrc/include/util/media-thumb-db.h79
-rwxr-xr-xsrc/include/util/media-thumb-debug.h81
-rwxr-xr-xsrc/include/util/media-thumb-util.h146
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c634
-rwxr-xr-xsrc/media-thumb-internal.c1302
-rwxr-xr-xsrc/media-thumbnail.c288
-rwxr-xr-xsrc/util/media-thumb-db.c609
-rwxr-xr-xsrc/util/media-thumb-debug.c112
-rwxr-xr-xsrc/util/media-thumb-util.c374
23 files changed, 10025 insertions, 0 deletions
diff --git a/src/codec/IfegDecodeAGIF.c b/src/codec/IfegDecodeAGIF.c
new file mode 100644
index 0000000..dad124b
--- /dev/null
+++ b/src/codec/IfegDecodeAGIF.c
@@ -0,0 +1,4169 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-debug.h"
+#include "img-codec-common.h"
+#include "IfegDecodeAGIF.h"
+
+
+
+#define MAX_CODES 4096
+
+int __FastImgGetNextFrameAGIF_NoBuffer (AGifFrameInfo *pFrameData, BOOL bCenterAlign);
+int __FastImgGetNextFrameAGIF_UseBuffer (AGifFrameInfo *pFrameData, BOOL bCenterAlign);
+
+int image_left_pos_N = 0; /* left position of image in Logical screeen */
+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;
+ 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)))) {
+ return 0;
+ }
+
+ IfegMemset(pFrameData, 0, sizeof(AGifFrameInfo));
+
+ inputPos += 13;
+
+ 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);
+#else
+ thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt);
+ if ((pFrameData->logi_wdt > MAXWIDTH) || (pFrameData->logi_hgt > MAXHEIGHT)) {
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+#endif
+
+ /* save nReapeatCount assigned by content */
+
+ if ((pEncodedData[10]&0x80) == 0x80) {
+ header_temp = 3 * (1<<((pEncodedData[10] & 0x07) + 1));
+ } 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) {
+ pFrameData->nLoopCount = pEncodedData[30+8+header_temp]<<8 | pEncodedData[29+8+header_temp];
+ } 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);
+
+ 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 */
+ backcolor_parsing = ui_backcolor;
+ } else {
+ 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);
+ }
+
+ /* graphic extension block */
+ if (pEncodedData[14+header_temp] == 0xF9 || pEncodedData[14+19+header_temp] == 0xF9) {
+
+ if (transparent == 1 && backcolor_index == transIndex) {
+ image_backcolor = ui_backcolor;
+ } else if (transparent == 1 && backcolor_index != transIndex) {
+ image_backcolor = backcolor_parsing;
+ } else {
+ image_backcolor = backcolor_parsing;
+ }
+ } else {
+ image_backcolor = backcolor_parsing;
+ }
+
+#if MODE == 0
+ if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) {
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+ pFrameData->useBuffer = 0;
+#endif
+
+#if MODE == 1
+ if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned int)*pFrameData->logi_wdt*pFrameData->logi_hgt))) {
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+ pFrameData->useBuffer = 1;
+#endif
+
+
+#if MODE == 2
+ if (((pFrameData->logi_wdt <= width) && (pFrameData->logi_hgt <= height))) {
+ if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) {
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+ pFrameData->useBuffer = 0;
+ } else {
+ if (0 == (pFrameData->pPrevImg = IfegMemAlloc(sizeof(unsigned int)*pFrameData->logi_wdt*pFrameData->logi_hgt))) {
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+ pFrameData->useBuffer = 1;
+ }
+#endif
+
+ if (0 == (pFrameData->pOutBits = IfegMemAlloc(sizeof(unsigned char)*width*height*2))) {
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+
+ pFrameData->inputSize = file_size;
+ pFrameData->pEncodedData = pEncodedData;
+
+ if (0 == (pFrameData->pGlobal_table = IfegMemAlloc(sizeof(unsigned int)*256))) {
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+
+ if (pFrameData->pOutBits) {
+ IfegMemFree(pFrameData->pOutBits);
+ pFrameData->pOutBits = 0;
+ }
+
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+
+ if (0 == (pFrameData->pPrefix = IfegMemAlloc(sizeof(unsigned short)*4097))) {
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+ if (pFrameData->pOutBits) {
+ IfegMemFree(pFrameData->pOutBits);
+ pFrameData->pOutBits = 0;
+ }
+ if (pFrameData->pGlobal_table) {
+ IfegMemFree(pFrameData->pGlobal_table);
+ pFrameData->pGlobal_table = 0;
+ }
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+
+ if (0 == (pFrameData->pDstack = IfegMemAlloc(sizeof(unsigned char)*4097))) {
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+ if (pFrameData->pOutBits) {
+ IfegMemFree(pFrameData->pOutBits);
+ pFrameData->pOutBits = 0;
+ }
+ if (pFrameData->pGlobal_table) {
+ IfegMemFree(pFrameData->pGlobal_table);
+ pFrameData->pGlobal_table = 0;
+ }
+ if (pFrameData->pPrefix) {
+ IfegMemFree(pFrameData->pPrefix);
+ pFrameData->pPrefix = 0;
+ }
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+
+ if (0 == (pFrameData->pSuffix = IfegMemAlloc(sizeof(unsigned char)*4097))) {
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+ if (pFrameData->pOutBits) {
+ IfegMemFree(pFrameData->pOutBits);
+ pFrameData->pOutBits = 0;
+ }
+ if (pFrameData->pGlobal_table) {
+ IfegMemFree(pFrameData->pGlobal_table);
+ pFrameData->pGlobal_table = 0;
+ }
+ if (pFrameData->pPrefix) {
+ IfegMemFree(pFrameData->pPrefix);
+ pFrameData->pPrefix = 0;
+ }
+ if (pFrameData->pDstack) {
+ IfegMemFree(pFrameData->pDstack);
+ pFrameData->pDstack = 0;
+ }
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+ return 0;
+ }
+
+ pFrameData->width = width;
+ pFrameData->height = height;
+ pFrameData->imgCount = -1;
+ pFrameData->offset = 0;
+ pFrameData->backcolor = image_backcolor;
+ pFrameData->ui_backcolor = ui_backcolor;
+ pFrameData->delay = 10;
+ pFrameData->bLoop = bLoop;
+ return pFrameData;
+}
+
+void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData)
+{
+ if (pFrameData == NULL) {
+ return;
+ }
+
+ if (pFrameData->pPrevImg) {
+ IfegMemFree(pFrameData->pPrevImg);
+ pFrameData->pPrevImg = 0;
+ }
+
+ if (pFrameData->pEncodedData) {
+ IfegMemFree(pFrameData->pEncodedData);
+ pFrameData->pEncodedData = 0;
+ }
+ if (pFrameData->pOutBits) {
+ IfegMemFree(pFrameData->pOutBits);
+ pFrameData->pOutBits = 0;
+ }
+
+ if (pFrameData->pGlobal_table) {
+ IfegMemFree(pFrameData->pGlobal_table);
+ pFrameData->pGlobal_table = 0;
+ }
+
+ if (pFrameData->pPrefix) {
+ IfegMemFree(pFrameData->pPrefix);
+ pFrameData->pPrefix = 0;
+ }
+
+ if (pFrameData->pDstack) {
+ IfegMemFree(pFrameData->pDstack);
+ pFrameData->pDstack = 0;
+ }
+
+ if (pFrameData->pSuffix) {
+ IfegMemFree(pFrameData->pSuffix);
+ pFrameData->pSuffix = 0;
+ }
+
+ if (pFrameData) {
+ IfegMemFree(pFrameData);
+ pFrameData = 0;
+ }
+}
+
+/* macro */
+#define __get_next_code_first_nbits_left_0(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;\
+ } \
+ return -1;\
+ } \
+ } \
+ b1 = (pInputStream)[inputPos++];\
+ ret = b1;\
+ nbits_left = 8;\
+ --navail_bytes;\
+ } \
+}
+
+#define __get_next_code_first_nbits_left_not_0(pInputStream) \
+{\
+ {\
+ ret = b1 >> (8 - nbits_left); \
+ } \
+}
+
+#define __get_next_code_first_while(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;\
+ } \
+ 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) \
+{\
+ {\
+ b1 = (pInputStream)[inputPos++];\
+ ret = b1;\
+ nbits_left = 8;\
+ --navail_bytes;\
+ } \
+}
+
+#define __get_next_code_second_nbits_left_not_0(pInputStream) \
+{\
+ {\
+ ret = b1 >> (8 - nbits_left);\
+ } \
+}
+
+#define __get_next_code_second_while(pInputStream) \
+{\
+ while (curr_size > nbits_left) {\
+ b1 = (pInputStream)[inputPos++];\
+ ret |= b1 << nbits_left;\
+ nbits_left += 8;\
+ --navail_bytes;\
+ } \
+ nbits_left -= curr_size;\
+ ret &= (1 << curr_size)-1;\
+ c = ret;\
+}
+
+int FastImgGetNextFrameAGIF(AGifFrameInfo *pFrameData, BOOL bCenterAlign)
+{
+ if (pFrameData->useBuffer) {
+ return __FastImgGetNextFrameAGIF_UseBuffer(pFrameData, bCenterAlign);
+ } else {
+ return __FastImgGetNextFrameAGIF_NoBuffer(pFrameData, bCenterAlign);
+ }
+}
+
+int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAlign)
+{
+ unsigned int *pImage32, *pImage32_2;
+ unsigned short *pImage16;
+ unsigned char *sp;
+ unsigned char *bufptr;
+ unsigned int code, fc, oc, bufcnt;
+ unsigned char buffer[16];
+ unsigned char val1;
+ unsigned char *buf;
+ unsigned int *pDacbox;
+ unsigned char *decoderline = 0;
+ unsigned int size;
+
+ unsigned int c = 0;
+ unsigned int clear;
+ unsigned int ending;
+ unsigned int newcodes;
+ unsigned int top_slot;
+ unsigned int slot;
+
+ int numcolors;
+ int i, j, k;
+ int rowcount;
+ int orgwdt_1, orgwdt, orghgt;
+ int decwdt, dechgt;
+ int len;
+ int inter_step, interLaced;
+ int transparent = 0;
+ int startloc = 0;
+ int transIndex = 0;
+ int spCount = 0;
+ int logi_wdt; /* logical screen width */
+ int logi_hgt;
+ int logi_image_size;
+ int image_backcolor;
+ int ui_backcolor;
+ int backcolor;
+ int image_left_pos; /* left position of image in Logical screeen */
+ int image_top_pos;
+ int disposal_method = 0;
+ int margin_wdt1_2, margin_hgt1_2;
+ int inputPos;
+
+ unsigned int dacbox[256];
+
+ /* Variable for Resize */
+ unsigned int a_x, a_y;
+ unsigned int b_x, b_y;
+ unsigned int c_x, c_y;
+ unsigned int d_x, d_y;
+ int out_x = 0, out_y = 0;
+ int d1, d2;
+ int flag = 0;
+ unsigned int end;
+
+ int count = 0;
+
+ unsigned char *pDecBuf = 0;
+
+ int expected_width = pFrameData->width;
+ int expected_height = pFrameData->height;
+ int resized_width;
+ int resized_height;
+
+ /* macro */
+ register unsigned int curr_size;
+ register int navail_bytes = 0;
+ register unsigned int nbits_left = 0;
+ register unsigned int b1 = 0;
+ register unsigned int ret;
+
+ /* parameter */
+ int filesize = pFrameData->inputSize;
+ 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;
+
+ inputPos = pFrameData->offset;
+
+ 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));
+
+ image_backcolor = pFrameData->backcolor;
+ ui_backcolor = pFrameData->ui_backcolor;
+
+ backcolor = image_backcolor;
+
+ if (pFrameData->imgCount == -1) {
+ /* Input stream index set to 0 */
+ inputPos = 0;
+ inter_step = 1;
+ interLaced = 0;
+ transparent = 0;
+
+ /* read a GIF HEADER */
+ IfegMemcpy(buffer, pInputStream, 13);
+ inputPos += 13;
+
+ /* wheather GIF file or not */
+ if (buffer[0] != 'G' || buffer[1] != 'I' || buffer[2] != 'F' ||
+ buffer[3] < '0' || buffer[3] > '9' ||
+ buffer[4] < '0' || buffer[4] > '9' ||
+ buffer[5] < 'A' || buffer[5] > 'z') {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 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) {
+ resized_width = logi_wdt;
+ resized_height = logi_hgt;
+ pFrameData->flag = flag = 1;
+ } else {
+ if ((logi_wdt/(float)expected_width) >= (logi_hgt/(float)expected_height)) {
+ resized_height = logi_hgt * expected_width / logi_wdt;
+ resized_width = expected_width;
+ } else {
+ resized_width = logi_wdt * expected_height / logi_hgt;
+ resized_height = expected_height;
+ }
+ }
+ if (!resized_width || !resized_height) {
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+
+ /* ouput resized image size */
+ pFrameData->resizedwidth = resized_width;
+ pFrameData->resizedheight = resized_height;
+
+ /* Color Resolution */
+ IfegMemset(global_dacbox, 0, 1024);
+ numcolors = (buffer[10] & 0x7) + 1;
+ if ((buffer[10] & 0x80) == 0) { /* Global color table */
+ global_dacbox[0] = 0x000000;
+ global_dacbox[1] = 0x3f3f3f;
+ numcolors = 2;
+ } else { /* Global color table */
+ numcolors = 1 << numcolors;
+
+ /* Make color table */
+ for (i = 0 ; i < numcolors; i++) {
+ global_dacbox[i] = ((pInputStream[inputPos++] >> 2)<<16);
+ global_dacbox[i] |= ((pInputStream[inputPos++] >> 2)<<8);
+ global_dacbox[i] |= (pInputStream[inputPos++] >> 2);
+ }
+ }
+
+ /* Background Color */
+ pImage16 = (unsigned short *)pFrameData->pPrevImg;
+ for (i = 0; i < expected_width * expected_height; i++) {
+ *pImage16++ = ui_backcolor;
+ }
+
+ if (numcolors > 16) {
+ numcolors = 256;
+ }
+ if (numcolors > 2 && numcolors < 16) {
+ numcolors = 16;
+ }
+
+ pFrameData->global_numcol = numcolors;
+ pFrameData->imgCount++;
+ pFrameData->firstpos = inputPos;
+ } else {
+
+ logi_wdt = pFrameData->logi_wdt;
+ logi_hgt = pFrameData->logi_hgt;
+ resized_width = pFrameData->resizedwidth;
+ resized_height = pFrameData->resizedheight;
+
+ flag = pFrameData->flag ;
+
+ numcolors = pFrameData->global_numcol;
+ }
+
+
+ while (1) {
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ pFrameData->imgCount = 0;
+ pFrameData->offset = pFrameData->firstpos;
+
+ if (pFrameData->bLoop) {
+ /* Background Color */
+ pImage16 = (unsigned short *)pFrameData->pPrevImg;
+ for (i = 0; i < expected_width * expected_height; i++) {
+ *pImage16++ = ui_backcolor;
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ switch (pInputStream[inputPos++]) {
+ case 0x3b: /* End of the GIF dataset */
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ if (pFrameData->imgCount == 0) {
+ return -1;
+ }
+ pFrameData->imgCount = 0;
+ pFrameData->offset = pFrameData->firstpos;
+
+#ifdef INTERNAL_IMGCODEC
+ pFrameData->nRepeatCount++;
+ thumb_dbg("(no_buffer) bLoop : %d, nRepeatCount : %d, nLoopCount : %d" , pFrameData->bLoop, pFrameData->nRepeatCount , pFrameData->nLoopCount);
+
+ if (pFrameData->nLoopCount == -1) {
+ break;
+ } else if (pFrameData->bLoop || (pFrameData->nRepeatCount <= pFrameData->nLoopCount) || (pFrameData->nLoopCount == 0)) {
+ /* Background Color */
+ pImage16 = (unsigned short *)pFrameData->pPrevImg;
+
+ 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. */
+ return 2;
+ }
+#else
+ if (pFrameData->bLoop) {
+ /* Background Color */
+ pImage16 = (unsigned short *)pFrameData->pPrevImg;
+ for (i = 0; i < expected_width * expected_height; i++) {
+ *pImage16++ = backcolor;
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+#endif
+ break;
+ case 0x21: /* Extension Block */
+ switch (pInputStream[inputPos++]) {
+ case 0xf9: /* Graphic control extension block */
+ if (4 != pInputStream[inputPos++]) { /* data length : fixed 4 bytes */
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+
+ disposal_method = ((pInputStream[inputPos] & 0x1c) >> 2);
+ 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++];
+ inputPos++; /* block end */
+ break;
+
+ case 0x01: /* Plain Text block */
+ while ((i = pInputStream[inputPos++]) > 0) {/* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+
+ case 0xfe: /* Comment Extension block */
+ while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+
+ case 0xff: /* Appliation Extension block */
+ while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case 0x2c: /* Start of an image object. Read the image description. */
+
+ /* initialize */
+ IfegMemcpy(pOutBits, pFrameData->pPrevImg, expected_width * expected_height * 2);
+ pDacbox = global_dacbox;
+
+ IfegMemcpy(buffer, pInputStream+inputPos, 9);
+ inputPos += 9;
+
+ image_left_pos = (buffer[0] | (buffer[1]<<8));
+ image_top_pos = (buffer[2] | (buffer[3]<<8));
+ orgwdt_1 = orgwdt = (buffer[4] | (buffer[5] << 8));
+ orghgt = (buffer[6] | (buffer[7] << 8));
+
+#ifdef INTERNAL_IMGCODEC
+#else
+ if ((orgwdt > MAXWIDTH) || (orghgt > MAXHEIGHT)) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+#endif
+
+ /* Interlaced check */
+ interLaced = buffer[8] & 0x40;
+ if (interLaced) {
+ startloc = -8;
+ }
+
+ inter_step = 1;
+
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ }
+ decoderline = (unsigned char *)IfegMemAlloc(orgwdt);
+ if (!decoderline) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 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);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ }
+ pDecBuf = (unsigned char *)IfegMemAlloc(decwdt * dechgt * 4);
+ if (!pDecBuf) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+ IfegMemset(pDecBuf, 0, decwdt * dechgt * 4);
+
+ /* assign out_888_image plane */
+ pImage32 = (unsigned int *)(pDecBuf);
+
+ /* Initialize */
+ a_x = orgwdt>>2, a_y = orghgt>>2;
+ b_x = ((orgwdt*3)>>2), b_y = orghgt>>2;
+ c_x = orgwdt>>2, c_y = ((orghgt*3)>>2);
+ d_x = ((orgwdt*3)>>2), d_y = ((orghgt*3)>>2);
+
+ end = dechgt * orghgt;
+ out_x = 0, out_y = -dechgt;
+
+ /* Color Resolution */
+ if ((buffer[8] & 0x80) == 0) { /* Logical color table */
+ /* use global table */
+ } else { /* Logical color table */
+ IfegMemset(dacbox, 0, 1024);
+
+ 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);
+ dacbox[i] |= ((pInputStream[inputPos++] >> 2)<<8);
+ dacbox[i] |= (pInputStream[inputPos++] >> 2);
+ }
+ pDacbox = dacbox;
+ }
+
+ if (numcolors > 16) {
+ numcolors = 256;
+ }
+ if (numcolors > 2 && numcolors < 16) {
+ numcolors = 16;
+ }
+
+ /****************************************************************************
+ decoder(WDT, pInputStream, pBitmapElem->pBits);
+ int decoder(int linewidth, UCHAR* pInputStream, UCHAR *pBitmapElem->pBits)
+ ****************************************************************************/
+
+ size = pInputStream[inputPos++];
+ if (size < 2 || 9 < size) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+
+ rowcount = oc = fc = 0;
+ buf = decoderline;
+ sp = dstack;
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+
+ /************************
+ init_exp(size);
+ int init_exp(int size)
+ ************************/
+ curr_size = size + 1;
+ top_slot = 1 << curr_size;
+ clear = 1 << size;
+ ending = clear + 1;
+ slot = newcodes = ending + 1;
+ navail_bytes = nbits_left = 0;
+ /************************/
+
+
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0) {
+ __get_next_code_first_nbits_left_0(pInputStream)
+ } else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+ /**********************************************************/
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+ *sp++ = (unsigned char)c;
+ } else {
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+ *sp++ = (unsigned char)c;
+ }
+
+ while (rowcount < orghgt) {
+ if ((sp - dstack) > 0) {
+ spCount = sp - dstack;
+ }
+ /* Now that we've pushed the decoded string (in reverse order)
+ * onto the stack, lets pop it off and put it into our decode
+ * buffer... And when the decode buffer is full, write another
+ * line...
+ */
+ while (sp > dstack) {
+ --sp;
+ *bufptr++ = *sp;
+
+ if (--bufcnt == 0) {
+
+ /********************************************************************************
+ if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0)
+ ********************************************************************************/
+ rowcount++;
+ len = bufptr - buf;
+ if (len >= orgwdt) {
+ len = orgwdt;
+ }
+
+ if (interLaced == 0) { /* interlaced image */
+ if (!flag) {
+ out_x = 0, out_y += dechgt;
+ }
+ } else { /* interlaced image */
+ if (inter_step == 1) {
+ startloc += 8;
+ } else if (inter_step == 2) {
+ startloc += 8;
+ } else if (inter_step == 3) {
+ startloc += 4;
+ } else if (inter_step == 4) {
+ startloc += 2;
+ }
+
+ if (startloc >= orghgt) {
+ inter_step++;
+ if (inter_step == 2) {
+ startloc = 4;
+ } else if (inter_step == 3) {
+ startloc = 2;
+ } else if (inter_step == 4) {
+ startloc = 1;
+ }
+ }
+
+ /* gif to rgb 565 */
+ if (flag) {
+ pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt;
+ } else {
+ out_x = 0, out_y = startloc * dechgt;
+ a_x = orgwdt>>2;
+ b_x = ((orgwdt*3)>>2);
+ c_x = orgwdt>>2;
+ d_x = ((orgwdt*3)>>2);
+ if (out_y <= (orghgt >> 2)) {
+ a_y = orghgt>>2;
+ b_y = orghgt>>2;
+ c_y = ((orghgt*3)>>2);
+ d_y = ((orghgt*3)>>2);
+ } else {
+ if (((out_y%orghgt) - (orghgt>>2)) > 0) {
+ a_y = ((out_y/orghgt)+1) * orghgt + (orghgt>>2);
+ } else if (((out_y%orghgt) - (orghgt>>2)) < 0 || !(out_y%orghgt)) {
+ a_y = ((out_y/orghgt)) * orghgt + (orghgt>>2);
+ } else {
+ a_y = out_y;
+ }
+
+ if (((out_y % orghgt) - ((orghgt * 3) >> 2)) > 0) {
+ c_y = ((out_y/orghgt)+1) * orghgt + ((orghgt*3)>>2);
+ } else if (((out_y%orghgt) - ((orghgt*3)>>2)) < 0 || !(out_y%orghgt)) {
+ c_y = ((out_y/orghgt)) * orghgt + ((orghgt * 3) >> 2);
+ } else {
+ c_y = out_y;
+ }
+ b_y = a_y, d_y = c_y;
+ }
+ }
+ }
+
+ if (transparent == 1) {
+ if (flag) {
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ if (val1 == transIndex) {
+ *pImage32++ = 0x4000000; /* Set *pImage32 MSB 1 */
+ } else {
+ *pImage32++ = pDacbox[val1]<<2;
+ }
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt;
+
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/orgwdt)) += 0x1000000;
+ *(pImage32_2 + (c_x/orgwdt)) += 0x1000000;
+ a_x += orgwdt, c_x += orgwdt;
+ } else {
+ *(pImage32 + (a_x/orgwdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1];
+ a_x += orgwdt, c_x += orgwdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/orgwdt)) += 0x1000000;
+ *(pImage32_2 + (d_x/orgwdt)) += 0x1000000;
+ b_x += orgwdt, d_x += orgwdt;
+ } else {
+ *(pImage32 + (b_x/orgwdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1];
+ b_x += orgwdt, d_x += orgwdt;
+ }
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = orgwdt>>2, a_y += orghgt;
+ b_x = ((orgwdt*3)>>2), b_y += orghgt;
+ c_x = orgwdt>>2, c_y += orghgt;
+ d_x = ((orgwdt*3)>>2), d_y += orghgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt;
+
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/orgwdt)) += 0x1000000;
+ a_x += orgwdt;
+ } else {
+ *(pImage32 + (a_x/orgwdt)) += pDacbox[val1];
+ a_x += orgwdt;
+ }
+ } if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/orgwdt)) += 0x1000000;
+ b_x += orgwdt;
+ } else {
+ *(pImage32 + (b_x/orgwdt)) += pDacbox[val1];
+ b_x += orgwdt;
+ }
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = orgwdt>>2, a_y += orghgt;
+ b_x = ((orgwdt*3)>>2), b_y += orghgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt;
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (c_x/orgwdt)) += 0x1000000;
+ c_x += orgwdt;
+ } else {
+ *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1];
+ c_x += orgwdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (d_x/orgwdt)) += 0x1000000;
+ d_x += orgwdt;
+ } else {
+ *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1];
+ d_x += orgwdt;
+ }
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ c_x = orgwdt>>2, c_y += orghgt;
+ d_x = ((orgwdt*3)>>2), d_y += orghgt;
+ }
+ }
+ }
+ }
+ } else {
+ if (flag) {
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+ *pImage32++ = pDacbox[val1]<<2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt;
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/orgwdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1];
+ a_x += orgwdt, c_x += orgwdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/orgwdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1];
+ b_x += orgwdt, d_x += orgwdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = orgwdt>>2, a_y += orghgt;
+ b_x = ((orgwdt*3)>>2), b_y += orghgt;
+ c_x = orgwdt>>2, c_y += orghgt;
+ d_x = ((orgwdt*3)>>2), d_y += orghgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/orghgt) * decwdt;
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/orgwdt)) += pDacbox[val1];
+ a_x += orgwdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/orgwdt)) += pDacbox[val1];
+ b_x += orgwdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = orgwdt>>2, a_y += orghgt;
+ b_x = ((orgwdt*3)>>2), b_y += orghgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/orghgt) * decwdt;
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/orgwdt)) += pDacbox[val1];
+ c_x += orgwdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/orgwdt)) += pDacbox[val1];
+ d_x += orgwdt;
+ }
+ out_x += decwdt;
+ }
+
+ if (!interLaced) {
+ c_x = orgwdt>>2, c_y += orghgt;
+ d_x = ((orgwdt*3)>>2), d_y += orghgt;
+ }
+ }
+ }
+ }
+ }
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+ }
+ }
+
+ if (rowcount == orghgt) {
+ break;
+ }
+
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+ /*************************************************************/
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+ *sp++ = (unsigned char)c;
+ } else {
+ code = c;
+
+ if (code >= slot) {
+ code = oc;
+ *sp++ = (unsigned char)fc;
+ }
+ while (code >= newcodes) {
+ *sp++ = suffix[code];
+ code = prefix[code];
+ }
+
+ *sp++ = (unsigned char)code;
+ spCount++;
+ if (slot < top_slot) {
+ fc = code;
+ suffix[slot] = (unsigned char)fc;
+ prefix[slot++] = oc;
+ oc = c;
+ }
+ if (slot >= top_slot) {
+ if (curr_size < 12) {
+ top_slot <<= 1;
+ ++curr_size;
+ }
+ }
+ }
+ }
+ /*************************************************************/
+
+ if (bCenterAlign) {
+ margin_wdt1_2 = (expected_width - resized_width)>>1;
+ margin_hgt1_2 = (expected_height - resized_height)>>1;
+ } else {
+ margin_wdt1_2 = 0;
+ margin_hgt1_2 = 0;
+ }
+
+ pImage32 = (unsigned int *)(pDecBuf);
+
+ /* Only make a first image frame as a thumbnail */
+ image_left_pos = 0;
+ image_top_pos = 0;
+ len = decwdt;
+
+ if (orgwdt > logi_wdt) {
+ decwdt = resized_width;
+ }
+ if (orghgt > logi_hgt) {
+ dechgt = resized_height;
+ }
+
+ if ((image_left_pos + decwdt) > resized_width) {
+ decwdt = resized_width - image_left_pos;
+ if (decwdt < 0) {
+ decwdt = 0;
+ }
+ }
+ if ((image_top_pos+dechgt) > resized_height) {
+ dechgt = resized_height - image_top_pos;
+ if (dechgt < 0) {
+ dechgt = 0;
+ }
+ }
+
+ if (pFrameData->imgCount == 0) {
+ for (i = 0, k = margin_hgt1_2; i < resized_height; i++) {
+ pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((margin_wdt1_2 + expected_width * k) << 1));
+ for (j = 0; j < resized_width; j++) {
+ *pImage16++ = backcolor;
+ }
+ k++;
+ }
+ if (transparent == 1) {
+ for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) {
+ pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1));
+ for (j = 0; j < decwdt; j++) {
+ *pImage16++ = ui_backcolor;
+ }
+ k++;
+ }
+ }
+ }
+
+ for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) {
+ pImage16 = (unsigned short *)((unsigned char*)pOutBits + ((image_left_pos+margin_wdt1_2 + (expected_width) * k) << 1));
+ pImage32 = (unsigned int *)(pDecBuf) + (i * len);
+
+ for (j = 0; j < decwdt; j++) {
+ if ((*pImage32>>24) == 0) {
+ *(pImage16++) = ((*pImage32 & 0xf80000) >> 8) | ((*pImage32 & 0xfc00) >> 5) | ((*pImage32 & 0xf8) >> 3);
+ } else if ((*pImage32 >> 24) == 4) {
+ pImage16++;
+ } else if ((*pImage32 >> 24) == 3) {
+ *pImage16 =
+ (((*pImage32 & 0xf80000) >> 8)+(((((*pImage16) & 0xf800) * 3) >> 2) & 0xf800)) |
+ (((*pImage32 & 0xfc00) >> 5)+(((((*pImage16) & 0x07c0) * 3) >> 2) & 0x07c0)) |
+ (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) * 3) >> 2));
+ pImage16++;
+ } else if ((*pImage32 >> 24) == 1) {
+ *pImage16 =
+ (((*pImage32 & 0xf80000) >> 8)+((((*pImage16) & 0xf800) >> 2) & 0xf800)) |
+ (((*pImage32 & 0xfc00) >> 5)+((((*pImage16) & 0x07c0) >> 2) & 0x07c0)) |
+ (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) >> 2)));
+ pImage16++;
+ } else {
+ *pImage16 =
+ (((*pImage32 & 0xf80000) >> 8)+((((*pImage16) & 0xf800) >> 1) & 0xf800)) |
+ (((*pImage32 & 0xfc00) >> 5)+((((*pImage16) & 0x07c0) >> 1) & 0x07c0)) |
+ (((*pImage32 & 0xf8) >> 3)+((((*pImage16) & 0x001f) >> 1)));
+ pImage16++;
+ }
+ pImage32++;
+ }
+ k++;
+ }
+
+ switch (disposal_method) {
+ /* No disposal specified. The decoder is not required to take any action */
+ case 0:
+
+ /* Do not dispose. The graphic is to be left in place. */
+ case 1:
+ IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2);
+ break;
+
+ /* Restore to background color. The area used by the graphic must be restored to the background color. */
+ case 2:
+ IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2);
+
+ if (transparent == 1) {
+ for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) {
+ pImage16 = (unsigned short *)((pFrameData->pPrevImg) + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1));
+ for (j = 0; j < decwdt; j++) {
+ *pImage16++ = ui_backcolor;
+ }
+ k++;
+ }
+ } else {
+ for (i = 0, k = image_top_pos+margin_hgt1_2; i < dechgt; i++) {
+ pImage16 = (unsigned short *)((pFrameData->pPrevImg) + ((image_left_pos+margin_wdt1_2 + expected_width * k) << 1));
+ for (j = 0; j < decwdt; j++) {
+ *pImage16++ = image_backcolor;
+ }
+ k++;
+ }
+ }
+ break;
+
+ /* Restore to previous. The decoder is required to restore the area overwritten by the graphic with what was there prior to rendering the graphic.*/
+ case 3:
+ break;
+
+ default:
+ IfegMemcpy(pFrameData->pPrevImg, pOutBits, expected_width * expected_height * 2);
+ /* same with case 1 */
+ break;
+ }
+
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+
+ pFrameData->offset = inputPos;
+ pFrameData->imgCount++;
+
+ return 1;
+
+ break;
+
+ default:
+ break;
+
+ }
+ }
+}
+
+
+/* use buffer */
+int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAlign)
+{
+ unsigned int *pImage32, *pImage32_2, *backGround;
+ unsigned short *pImage16;
+ unsigned char *sp;
+ unsigned char *bufptr;
+ unsigned int code, fc, oc, bufcnt;
+ unsigned char buffer[16];
+ unsigned char val1;
+ unsigned char *buf;
+ unsigned int *pDacbox;
+ unsigned char *decoderline = 0;
+ unsigned int size;
+ unsigned int c = 0;
+
+ unsigned int clear;
+ unsigned int ending;
+ unsigned int newcodes;
+ unsigned int top_slot;
+ unsigned int slot;
+
+ int numcolors;
+ int i, j, k;
+ int rowcount;
+ int orgwdt_1, orgwdt, orghgt;
+ int decwdt, dechgt;
+ int len;
+ int inter_step, interLaced, intercount;
+ int transparent = 0;
+ int startloc = 0;
+ int backgroundIndex = 0;
+ int transIndex = 0;
+ 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 */
+ int image_top_pos;
+ int disposal_method = 0;
+ int margin_wdt1_2, margin_hgt1_2;
+
+ int inputPos;
+
+
+ unsigned int dacbox[256];
+
+ /* Variable for Resize */
+
+ unsigned int a_x, a_y;
+ unsigned int b_x, b_y;
+ unsigned int c_x, c_y;
+ unsigned int d_x, d_y;
+ int out_x = 0, out_y = 0;
+ int d1, d2;
+ int flag = 0;
+ unsigned int end;
+
+ int count = 0;
+
+ unsigned char *pDecBuf = 0;
+
+ int expected_width = pFrameData->width;
+ int expected_height = pFrameData->height;
+ int resized_width;
+ int resized_height;
+
+ /* macro */
+ register unsigned int curr_size;
+ register int navail_bytes = 0;
+ register unsigned int nbits_left = 0;
+ register unsigned int b1 = 0;
+ register unsigned int ret;
+
+ /* parameter */
+ 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;
+ int filesize = pFrameData->inputSize;
+
+ inputPos = pFrameData->offset;
+
+ 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));
+
+ ui_backcolor565 = pFrameData->ui_backcolor;
+ ui_backcolor888 =
+ ((ui_backcolor565&0xf800) << 6)|
+ ((ui_backcolor565&0x7e0) << 3)|
+ ((ui_backcolor565&0x1f) << 1);
+
+ backcolor565 = pFrameData->backcolor;
+ backcolor888 =
+ ((backcolor565&0xf800) << 6)|
+ ((backcolor565&0x7e0) << 3)|
+ ((backcolor565&0x1f) << 1);
+
+ backGround = (unsigned int *)pFrameData->pPrevImg;
+
+ intercount = 0;
+
+ if (pFrameData->imgCount == -1) {
+ /* Input stream index set to 0 */
+ inputPos = 0;
+ inter_step = 1;
+ interLaced = 0;
+ transparent = 0;
+
+ /* read a GIF HEADER */
+ IfegMemcpy(buffer, pInputStream, 13);
+ inputPos += 13;
+
+ /* wheather GIF file or not */
+ if (buffer[0] != 'G' || buffer[1] != 'I' || buffer[2] != 'F' ||
+ buffer[3] < '0' || buffer[3] > '9' ||
+ buffer[4] < '0' || buffer[4] > '9' ||
+ buffer[5] < 'A' || buffer[5] > 'z') {
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+
+ /* get Logical width, height */
+ 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;
+ resized_height = logi_hgt;
+ pFrameData->flag = flag = 1;
+ } else {
+ if ((logi_wdt/(float)expected_width) >= (logi_hgt/(float)expected_height)) {
+ resized_height = logi_hgt * expected_width / logi_wdt;
+ resized_width = expected_width;
+ } else {
+ resized_width = logi_wdt * expected_height / logi_hgt;
+ resized_height = expected_height;
+ }
+ }
+ if (!resized_width || !resized_height) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+
+ /* ouput resized image size */
+ pFrameData->resizedwidth = resized_width;
+ pFrameData->resizedheight = resized_height;
+
+ /* Color Resolution */
+ IfegMemset(global_dacbox, 0, 1024);
+ numcolors = (buffer[10] & 0x7) + 1;
+ if ((buffer[10] & 0x80) == 0) { /* Global color table */
+ global_dacbox[0] = 0x000000;
+ global_dacbox[1] = 0x3f3f3f;
+ numcolors = 2;
+ } else { /* Global color table */
+ numcolors = 1 << numcolors;
+
+ /* Make color table */
+ for (i = 0; i < numcolors; i++) {
+ global_dacbox[i] = ((pInputStream[inputPos++] >> 2) << 16);
+ global_dacbox[i] |= ((pInputStream[inputPos++] >> 2) << 8);
+ global_dacbox[i] |= (pInputStream[inputPos++] >> 2);
+ }
+ }
+
+ backgroundIndex = buffer[11];
+ /* Background Color */
+ backcolor888 = global_dacbox[backgroundIndex];
+ backcolor565 = pFrameData->backcolor = (((backcolor888 & 0xff0000) >> 17) << 11) | (((backcolor888 & 0x00ff00) >> 8) << 5) | (((backcolor888 & 0xff) >> 1));
+
+ pImage16 = pOutBits;
+
+ ui_backcolor565 = pFrameData->ui_backcolor ;
+ for (i = 0; i < expected_width * expected_height; i++) {
+ *pImage16++ = ui_backcolor565;
+ }
+
+ pImage32 = (unsigned int *)pFrameData->pPrevImg;
+
+ if (numcolors > 16) {
+ numcolors = 256;
+ }
+ if (numcolors > 2 && numcolors < 16) {
+ numcolors = 16;
+ }
+ pFrameData->global_numcol = numcolors;
+ pFrameData->imgCount++;
+ pFrameData->firstpos = inputPos;
+ } else {
+ logi_wdt = pFrameData->logi_wdt;
+ logi_hgt = pFrameData->logi_hgt;
+ resized_width = pFrameData->resizedwidth;
+ resized_height = pFrameData->resizedheight;
+ flag = pFrameData->flag ;
+
+ numcolors = pFrameData->global_numcol;
+ }
+
+ /* still gif image (image_cnt = 1) */
+ while (1) {
+ if (inputPos > filesize) {
+
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ pFrameData->imgCount = 0;
+ pFrameData->offset = pFrameData->firstpos;
+
+ if (pFrameData->bLoop) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ switch (pInputStream[inputPos++]) {
+ case 0x3b:/* End of the GIF dataset */
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ if (pFrameData->imgCount == 0) {
+ return -1;
+ }
+ pFrameData->imgCount = 0;
+ pFrameData->offset = pFrameData->firstpos;
+#ifdef INTERNAL_IMGCODEC
+ pFrameData->nRepeatCount++;
+
+ if (pFrameData->nLoopCount == -1) {
+ break;
+ } else if (pFrameData->bLoop || (pFrameData->nRepeatCount <= pFrameData->nLoopCount) || (pFrameData->nLoopCount == 0)) {
+ inputPos = pFrameData->offset;
+ continue;
+ } else {
+ return 2;
+ }
+#else
+ if (pFrameData->bLoop) {
+ return 1;
+ } else {
+ return 0;
+ }
+
+#endif
+ break;
+ case 0x21: /* Extension Block */
+ switch (pInputStream[inputPos++]) {
+ case 0xf9: /* Graphic control extension block */
+ if (4 != pInputStream[inputPos++]) { /* data length : fixed 4 bytes */
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+
+ disposal_method = ((pInputStream[inputPos] & 0x1c) >> 2);
+ 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++];
+ inputPos++; /* block end */
+
+ if (backgroundIndex == transIndex && transparent == 1) {
+ backcolor888 = 0x1000000;
+ backcolor565 = pFrameData->ui_backcolor;
+ }
+
+ break;
+ case 0x01: /* Plain Text block */
+ while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+ case 0xfe: /* Comment Extension block */
+ while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+ case 0xff: /* Appliation Extension block */
+
+ while ((i = pInputStream[inputPos++]) > 0) { /* get the data length */
+ inputPos += i;
+ if (inputPos > filesize) {
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ break;
+
+ case 0x2c: /* Start of an image object. Read the image description. */
+
+ /* initialize */
+ pDacbox = global_dacbox;
+
+ IfegMemcpy(buffer, pInputStream+inputPos, 9);
+ inputPos += 9;
+
+ if (pFrameData->imgCount == 0) {
+ image_left_pos_N = (buffer[0] | (buffer[1] << 8));
+ image_top_pos_N = (buffer[2] | (buffer[3] << 8));
+
+ image_left_pos = image_left_pos_N;
+ image_top_pos = image_top_pos_N;
+ }
+ image_left_pos = (buffer[0] | (buffer[1] << 8));
+ image_top_pos = (buffer[2] | (buffer[3] << 8));
+ orgwdt_1 = orgwdt = (buffer[4] | (buffer[5] << 8));
+ orghgt = (buffer[6] | (buffer[7] << 8));
+
+
+#ifdef INTERNAL_IMGCODEC
+#else
+ if ((orgwdt > MAXWIDTH) || (orghgt > MAXHEIGHT)) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+#endif
+
+ /* Initialize */
+ a_x = logi_wdt >> 2, a_y = logi_hgt >> 2;
+ b_x = ((logi_wdt*3) >> 2), b_y = logi_hgt >> 2;
+ c_x = logi_wdt >> 2, c_y = ((logi_hgt*3) >> 2);
+ d_x = ((logi_wdt*3) >> 2), d_y = ((logi_hgt*3) >> 2);
+
+ /* Interlaced check */
+ interLaced = buffer[8] & 0x40;
+ if (interLaced) {
+ startloc = -8+image_top_pos;
+ }
+
+ inter_step = 1;
+
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ }
+ decoderline = (unsigned char *)IfegMemAlloc(orgwdt);
+ if (!decoderline) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+ IfegMemset(decoderline, 0, orgwdt);
+
+ decwdt = resized_width;
+ dechgt = resized_height;
+
+ if (!decwdt || !dechgt) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ }
+ pDecBuf = (unsigned char *)IfegMemAlloc(decwdt * dechgt * 4);
+ if (!pDecBuf) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return 0;
+ }
+
+ IfegMemset(pDecBuf, 0, decwdt * dechgt * 4);
+
+ /* assign out_888_image plane */
+ pImage32 = (unsigned int *)(pDecBuf);
+
+ end = dechgt * logi_hgt;
+ out_x = 0, out_y = -dechgt;
+
+ /* Color Resolution */
+ if ((buffer[8] & 0x80) == 0) { /* Logical color table */
+ ;/* use global table */
+ } else { /* Logical color table */
+ IfegMemset(dacbox, 0, 1024);
+
+ 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);
+ dacbox[i] |= ((pInputStream[inputPos++] >> 2) << 8);
+ dacbox[i] |= (pInputStream[inputPos++] >> 2);
+ }
+ pDacbox = dacbox;
+ }
+
+ if (numcolors > 16) {
+ numcolors = 256;
+ }
+ if (numcolors > 2 && numcolors < 16) {
+ numcolors = 16;
+ }
+
+ if (logi_wdt < (image_left_pos + orgwdt)) {
+ if (image_left_pos > logi_wdt) {
+ image_left_pos = logi_wdt;
+ }
+ orgwdt = logi_wdt - image_left_pos;
+ flag = 0;
+ }
+ if (logi_hgt < (image_top_pos + orghgt)) {
+ flag = 0;
+ }
+
+ if (pFrameData->imgCount == 0) {
+ if (disposal_method == 3) {
+ pImage32 = (unsigned int *)pFrameData->pPrevImg;
+ for (i = 0; i < logi_wdt * logi_hgt; i++) {
+ *pImage32++ = 0x1000000;
+ }
+ } else {
+ pImage32 = (unsigned int *)pFrameData->pPrevImg;
+ for (i = 0; i < logi_wdt * logi_hgt; i++) {
+ *pImage32++ = backcolor888;
+ }
+ }
+ if (transparent == 1) {
+ /* Background Color */
+ pImage32 = (unsigned int *)pFrameData->pPrevImg;
+ pImage32 += image_top_pos * logi_wdt + image_left_pos;
+ if (logi_hgt < (image_top_pos + orghgt)) {
+ for (i = 0; i < logi_hgt - image_top_pos; i++) {
+ for (j = 0; j < orgwdt; j++) {
+ pImage32[j] = 0x1000000; /* set ui color */
+ }
+ pImage32 += logi_wdt;
+ }
+ } else {
+ for (i = 0; i < orghgt; i++) {
+ for (j = 0; j < orgwdt; j++) {
+ pImage32[j] = 0x1000000; /* set ui color */
+ }
+ pImage32 += logi_wdt;
+ }
+ }
+ }
+ }
+
+ /* assign out_888_image plane */
+ pImage32 = (unsigned int *)(pDecBuf);
+
+ for (rowcount = 0; rowcount < image_top_pos; rowcount++) {
+ if (flag) {
+ for (i = 0; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ out_x = 0, out_y += dechgt;
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ backGround += logi_wdt;
+ }
+
+
+ /***************************************************************************
+ decoder(WDT, pInputStream, pBitmapElem->pBits); //this does the grunt work
+ int decoder(int linewidth, UCHAR* pInputStream, UCHAR *pBitmapElem->pBits)
+ ***************************************************************************/
+
+ size = pInputStream[inputPos++];
+ if (size < 2 || 9 < size) {
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ return -1;
+ }
+ rowcount = oc = fc = 0;
+ buf = decoderline;
+ sp = dstack;
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+
+ /************************
+ init_exp(size);
+ int init_exp(int size)
+ ************************/
+ curr_size = size + 1;
+ top_slot = 1 << curr_size;
+ clear = 1 << size;
+ ending = clear + 1;
+ slot = newcodes = ending + 1;
+ navail_bytes = nbits_left = 0;
+ /************************/
+
+
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+ *sp++ = (unsigned char)c;
+ } else {
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+ *sp++ = (unsigned char)c;
+ }
+
+ switch (disposal_method) {
+
+ /* Restore to previous. The decoder is required to restore the area overwritten by the graphic with what was there prior to rendering the graphic. */
+ case 3:
+ while (rowcount < orghgt) {
+ if ((sp - dstack) > 0) {
+ spCount = sp - dstack;
+ }
+ /* Now that we've pushed the decoded string (in reverse order)
+ * onto the stack, lets pop it off and put it into our decode
+ * buffer... And when the decode buffer is full, write another
+ * line...
+ */
+ while (sp > dstack) {
+ --sp;
+ *bufptr++ = *sp;
+
+ if (--bufcnt == 0) {
+ /**********************************************************************************
+ if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0)
+ **********************************************************************************/
+ rowcount++;
+ len = bufptr - buf;
+ if (len >= orgwdt) {
+ len = orgwdt;
+ }
+
+ if (interLaced == 0) { /* interlaced image */
+ if (!flag) {
+ out_x = 0, out_y += dechgt;
+ }
+ } else { /* interlaced image */
+ if (inter_step == 1) {
+ startloc += 8;
+ intercount++;
+ } else if (inter_step == 2) {
+ startloc += 8;
+ intercount++;
+ } else if (inter_step == 3) {
+ startloc += 4;
+ intercount++;
+ } else if (inter_step == 4) {
+ startloc += 2;
+ intercount++;
+ }
+
+ if (startloc >= orghgt+image_top_pos) {
+ inter_step++;
+ if (inter_step == 2) {
+ startloc = 4+image_top_pos;
+ } else if (inter_step == 3) {
+ startloc = 2+image_top_pos;
+ } else if (inter_step == 4) {
+ startloc = 1+image_top_pos;
+ }
+ }
+
+ backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2));
+ /* gif to rgb 565 */
+ if (flag) {
+ pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt;
+ } else {
+ out_x = 0, out_y = startloc * dechgt;
+ a_x = logi_wdt >> 2;
+ b_x = ((logi_wdt*3) >> 2);
+ c_x = logi_wdt >> 2;
+ d_x = ((logi_wdt*3) >> 2);
+ if (out_y <= (logi_hgt >> 2)) {
+ a_y = logi_hgt >> 2;
+ b_y = logi_hgt >> 2;
+ c_y = ((logi_hgt*3) >> 2);
+ d_y = ((logi_hgt*3) >> 2);
+ } else {
+ if (((out_y % logi_hgt) - (logi_hgt >> 2)) > 0) {
+ a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2);
+ } else if (((out_y % logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) {
+ a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt>>2);
+ } else {
+ a_y = out_y;
+ }
+
+ if (((out_y % logi_hgt) - ((logi_hgt*3) >> 2)) > 0) {
+ c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2));
+ } else if (((out_y % logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y % logi_hgt)) {
+ c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2);
+ } else {
+ c_y = out_y;
+ }
+ b_y = a_y, d_y = c_y;
+ }
+ }
+ }
+
+ if (transparent == 1) {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i]<<2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ if (val1 == transIndex) {
+ *pImage32++ = backGround[i+image_left_pos] << 2;
+ } else {
+ *pImage32++ = pDacbox[val1] << 2;
+ }
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt, c_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt, d_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ }
+ out_x += decwdt;
+ }
+
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt>>2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ }
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ c_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ d_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ }
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ } else {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors - 1);
+ *pImage32++ = pDacbox[val1] << 2;
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ }
+
+ backGround += logi_wdt;
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+ }
+ }
+
+ if (rowcount == orghgt) {
+ break;
+ }
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+
+ *sp++ = (unsigned char)c;
+ } else {
+ code = c;
+
+ if (code >= slot) {
+ code = oc;
+ *sp++ = (unsigned char)fc;
+ }
+
+ while (code >= newcodes) {
+ *sp++ = suffix[code];
+ code = prefix[code];
+ }
+
+ *sp++ = (unsigned char)code;
+ spCount++;
+ if (slot < top_slot) {
+ fc = code;
+ suffix[slot] = (unsigned char)fc;
+ prefix[slot++] = oc;
+ oc = c;
+ }
+ if (slot >= top_slot) {
+ if (curr_size < 12) {
+ top_slot <<= 1;
+ ++curr_size;
+ }
+ }
+ }
+ }
+ break;
+
+ /* Restore to background color. The area used by the graphic must be restored to the background color. */
+ case 2:
+ while (rowcount < orghgt) {
+ if ((sp - dstack) > 0) {
+ spCount = sp - dstack;
+ }
+ while (sp > dstack) {
+ --sp;
+ *bufptr++ = *sp;
+
+ if (--bufcnt == 0) {
+ /********************************************************************************
+ if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0)
+ ********************************************************************************/
+ rowcount++;
+ len = bufptr - buf;
+ if (len >= orgwdt) {
+ len = orgwdt;
+ }
+
+ if (interLaced == 0) { /* interlaced image */
+ if (!flag) {
+ out_x = 0, out_y += dechgt;
+ }
+ } else { /* interlaced image */
+ if (inter_step == 1) {
+ startloc += 8;
+ } else if (inter_step == 2) {
+ startloc += 8;
+ } else if (inter_step == 3) {
+ startloc += 4;
+ } else if (inter_step == 4) {
+ startloc += 2;
+ }
+
+ if (startloc >= orghgt + image_top_pos) {
+ inter_step++;
+ if (inter_step == 2) {
+ startloc = 4 + image_top_pos;
+ } else if (inter_step == 3) {
+ startloc = 2+image_top_pos;
+ } else if (inter_step == 4) {
+ startloc = 1+image_top_pos;
+ }
+ }
+ backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2));
+ /* gif to rgb 565 */
+ if (flag) {
+ pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt;
+ } else {
+ out_x = 0, out_y = startloc * dechgt;
+ a_x = logi_wdt >> 2;
+ b_x = ((logi_wdt*3) >> 2);
+ c_x = logi_wdt>>2;
+ d_x = ((logi_wdt*3) >> 2);
+ if (out_y <= (logi_hgt >> 2)) {
+ a_y = logi_hgt>>2;
+ b_y = logi_hgt>>2;
+ c_y = ((logi_hgt*3)>>2);
+ d_y = ((logi_hgt*3)>>2);
+ } else {
+ if (((out_y % logi_hgt) - (logi_hgt >> 2)) > 0) {
+ a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2);
+ } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) {
+ a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2);
+ } else {
+ a_y = out_y;
+ }
+
+ if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) {
+ c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2));
+ } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) {
+ c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2);
+ } else {
+ c_y = out_y;
+ }
+ b_y = a_y, d_y = c_y;
+ }
+ }
+ }
+
+ if (transparent == 1) {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ if (val1 == transIndex) {
+ *pImage32++ = backGround[i+image_left_pos] << 2;
+ backGround[i+image_left_pos] = 0x1000000;
+ } else {
+ *pImage32++ = pDacbox[val1] << 2;
+ backGround[i+image_left_pos] = 0x1000000;
+ }
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt, c_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt, d_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ }
+ backGround[i+image_left_pos] = 0x1000000;
+ out_x += decwdt;
+ }
+
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ }
+ }
+ backGround[i+image_left_pos] = 0x1000000;
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ c_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ d_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ }
+ }
+ backGround[i+image_left_pos] = 0x1000000;
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ } else {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i]<<2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+ *pImage32++ = pDacbox[val1] << 2;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ backGround[i+image_left_pos] = backcolor888;
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ }
+
+ backGround += logi_wdt;
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+ }
+ }
+
+ if (rowcount == orghgt) {
+ break;
+ }
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+
+ *sp++ = (unsigned char)c;
+ } else {
+ code = c;
+
+ if (code >= slot) {
+ code = oc;
+ *sp++ = (unsigned char)fc;
+ }
+
+ while (code >= newcodes) {
+ *sp++ = suffix[code];
+ code = prefix[code];
+ }
+
+ *sp++ = (unsigned char)code;
+ spCount++;
+ if (slot < top_slot) {
+ fc = code;
+ suffix[slot] = (unsigned char)fc;
+ prefix[slot++] = oc;
+ oc = c;
+ }
+ if (slot >= top_slot) {
+ if (curr_size < 12) {
+ top_slot <<= 1;
+ ++curr_size;
+ }
+ }
+ }
+
+ }
+
+ break;
+
+
+ /* No disposal specified. The decoder is not required to take any action */
+ case 0:
+
+ /* Do not dispose. The graphic is to be left in place. */
+ case 1:
+
+ default:
+ while (rowcount < orghgt) {
+ if ((sp - dstack) > 0) {
+ spCount = sp - dstack;
+ }
+ /* Now that we've pushed the decoded string (in reverse order)
+ * onto the stack, lets pop it off and put it into our decode
+ * buffer... And when the decode buffer is full, write another
+ * line...
+ */
+ while (sp > dstack) {
+ --sp;
+ *bufptr++ = *sp;
+
+ if (--bufcnt == 0) {
+ /**********************************************************************************
+ if ((ret = put_line(rowcount++, bufptr - buf, WDT, buf, pBitmapElem->pBits)) < 0)
+ **********************************************************************************/
+ rowcount++;
+ len = bufptr - buf;
+ if (len >= orgwdt) {
+ len = orgwdt;
+ }
+
+ if (interLaced == 0) { /* interlaced image */
+ if (!flag) {
+ out_x = 0, out_y += dechgt;
+ }
+ } else { /* interlaced image */
+ if (inter_step == 1) {
+ startloc += 8;
+ intercount++;
+ } else if (inter_step == 2) {
+ startloc += 8;
+ intercount++;
+ } else if (inter_step == 3) {
+ startloc += 4;
+ intercount++;
+ } else if (inter_step == 4) {
+ startloc += 2;
+ intercount++;
+ }
+
+ if (startloc >= orghgt+image_top_pos) {
+ inter_step++;
+ if (inter_step == 2) {
+ startloc = 4+image_top_pos;
+ } else if (inter_step == 3) {
+ startloc = 2+image_top_pos;
+ } else if (inter_step == 4) {
+ startloc = 1+image_top_pos;
+ }
+ }
+
+ backGround = (unsigned int *)(pFrameData->pPrevImg + ((startloc * logi_wdt) << 2));
+ /* gif to rgb 565 */
+ if (flag) {
+ pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt;
+ } else {
+ out_x = 0, out_y = startloc * dechgt;
+ a_x = logi_wdt >> 2;
+ b_x = ((logi_wdt*3) >> 2);
+ c_x = logi_wdt >> 2;
+ d_x = ((logi_wdt*3) >> 2);
+ if (out_y <= (logi_hgt >> 2)) {
+ a_y = logi_hgt >> 2;
+ b_y = logi_hgt >> 2;
+ c_y = ((logi_hgt*3) >> 2);
+ d_y = ((logi_hgt*3) >> 2);
+ } else {
+ if (((out_y%logi_hgt) - (logi_hgt >> 2)) > 0) {
+ a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2);
+ } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) {
+ a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2);
+ } else {
+ a_y = out_y;
+ }
+
+ if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) {
+ c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2));
+ } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) {
+ c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2);
+ } else {
+ c_y = out_y;
+ }
+ b_y = a_y, d_y = c_y;
+ }
+ }
+ }
+
+ if (transparent == 1) {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ if (val1 == transIndex) {
+ *pImage32++ = backGround[i+image_left_pos] << 2; /* Set *pImage32 MSB 1 */
+ } else {
+ *pImage32++ = pDacbox[val1] << 2;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt, c_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt, d_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ out_x += decwdt;
+ }
+
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i+image_left_pos];
+ a_x += logi_wdt;
+ } else {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i+image_left_pos];
+ b_x += logi_wdt;
+ } else {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i+image_left_pos];
+ c_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ if (val1 == transIndex) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i+image_left_pos];
+ d_x += logi_wdt;
+ } else {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ } else {
+ if (flag) {
+ for (i = 0; i < image_left_pos; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ for (i = 0; i < len; i++) {
+ val1 = buf[i] & (numcolors-1);
+ *pImage32++ = pDacbox[val1] << 2;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ for (i = orgwdt+image_left_pos; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt, c_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt, d_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += pDacbox[val1];
+ a_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += pDacbox[val1];
+ b_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ if (!interLaced) {
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ }
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < image_left_pos; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ for (i = 0; i < orgwdt; i++) {
+ val1 = buf[i] & (numcolors-1);
+
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += pDacbox[val1];
+ c_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += pDacbox[val1];
+ d_x += logi_wdt;
+ backGround[i+image_left_pos] = pDacbox[val1];
+ }
+ out_x += decwdt;
+ }
+ for (i = image_left_pos+orgwdt; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+
+ }
+ if (!interLaced) {
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ }
+ }
+
+ backGround += logi_wdt;
+ bufptr = buf;
+ bufcnt = orgwdt_1;
+ }
+ }
+ if (rowcount == orghgt) {
+ break;
+ }
+ /* __get_next_code(pInputStream) */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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;
+ }
+
+ if (c == clear) {
+ curr_size = size + 1;
+ slot = newcodes;
+ top_slot = 1 << curr_size;
+
+ do {
+ /* __get_next_code(pInputStream); */
+ if (navail_bytes < 2) {
+ if (nbits_left == 0)
+ __get_next_code_first_nbits_left_0(pInputStream)
+ else
+ __get_next_code_first_nbits_left_not_0(pInputStream)
+ __get_next_code_first_while(pInputStream)
+ } else {
+ 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) {
+ break;
+ }
+
+ if (c >= slot) {
+ c = 0;
+ }
+
+ oc = fc = c;
+
+ *sp++ = (unsigned char)c;
+ } else {
+ code = c;
+
+ if (code >= slot) {
+ code = oc;
+ *sp++ = (unsigned char)fc;
+ }
+
+ while (code >= newcodes) {
+ *sp++ = suffix[code];
+ code = prefix[code];
+ }
+
+ *sp++ = (unsigned char)code;
+ spCount++;
+ if (slot < top_slot) {
+ fc = code;
+ suffix[slot] = (unsigned char)fc;
+ prefix[slot++] = oc;
+ oc = c;
+ }
+ if (slot >= top_slot) {
+ if (curr_size < 12) {
+ top_slot <<= 1;
+ ++curr_size;
+ }
+ }
+ }
+ }
+
+ break;
+ }
+
+ if (interLaced) {
+ startloc = orghgt+image_top_pos;
+ pImage32 = (unsigned int *)(pDecBuf) + startloc * decwdt;
+ if (!flag) {
+ out_x = 0, out_y = startloc * dechgt;
+ a_x = logi_wdt >> 2;
+ b_x = ((logi_wdt*3) >> 2);
+ c_x = logi_wdt >> 2;
+ d_x = ((logi_wdt*3) >> 2);
+ if (out_y <= (logi_hgt >> 2)) {
+ a_y = logi_hgt >> 2;
+ b_y = logi_hgt >> 2;
+ c_y = ((logi_hgt*3) >> 2);
+ d_y = ((logi_hgt*3) >> 2);
+ } else {
+ if (((out_y%logi_hgt) - (logi_hgt >> 2)) > 0) {
+ a_y = ((out_y/logi_hgt)+1) * logi_hgt + (logi_hgt >> 2);
+ } else if (((out_y%logi_hgt) - (logi_hgt >> 2)) < 0 || !(out_y%logi_hgt)) {
+ a_y = ((out_y/logi_hgt)) * logi_hgt + (logi_hgt >> 2);
+ } else {
+ a_y = out_y;
+ }
+
+ if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) > 0) {
+ c_y = ((out_y/logi_hgt+1) * logi_hgt + ((logi_hgt*3) >> 2));
+ } else if (((out_y%logi_hgt) - ((logi_hgt*3) >> 2)) < 0 || !(out_y%logi_hgt)) {
+ c_y = ((out_y/logi_hgt)) * logi_hgt + ((logi_hgt*3) >> 2);
+ } else {
+ c_y = out_y;
+ }
+ b_y = a_y, d_y = c_y;
+ }
+ }
+ out_y -= dechgt;
+ }
+
+ backGround = (unsigned int *)(pFrameData->pPrevImg + (((image_top_pos+orghgt) * logi_wdt) << 2));
+ for (rowcount = image_top_pos+orghgt; rowcount < logi_hgt; rowcount++) {
+ if (flag) {
+ for (i = 0; i < logi_wdt; i++) {
+ *pImage32++ = backGround[i] << 2;
+ }
+ } else {
+ out_x = 0, out_y += dechgt;
+ if (c_y < end) {
+ d1 = a_y - out_y;
+ d2 = c_y - out_y;
+ if ((0 <= d1 && d1 < dechgt) && 0 <= d2 && d2 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt, c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt, d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ } else if (0 <= d1 && d1 < dechgt) {
+ pImage32 = (unsigned int *)(pDecBuf) + (a_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = a_x - out_x;
+ d2 = b_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32 + (a_x/logi_wdt)) += backGround[i];
+ a_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32 + (b_x/logi_wdt)) += backGround[i];
+ b_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ a_x = logi_wdt >> 2, a_y += logi_hgt;
+ b_x = ((logi_wdt*3) >> 2), b_y += logi_hgt;
+ } else if (0 <= d2 && d2 < dechgt) {
+ pImage32_2 = (unsigned int *)(pDecBuf) + (c_y/logi_hgt) * decwdt;
+ for (i = 0; i < logi_wdt; i++) {
+ d1 = c_x - out_x;
+ d2 = d_x - out_x;
+ if (0 <= d1 && d1 < decwdt) {
+ *(pImage32_2 + (c_x/logi_wdt)) += backGround[i];
+ c_x += logi_wdt;
+ }
+ if (0 <= d2 && d2 < decwdt) {
+ *(pImage32_2 + (d_x/logi_wdt)) += backGround[i];
+ d_x += logi_wdt;
+ }
+ out_x += decwdt;
+ }
+ c_x = logi_wdt >> 2, c_y += logi_hgt;
+ d_x = ((logi_wdt*3) >> 2), d_y += logi_hgt;
+ }
+ }
+ }
+ backGround += logi_wdt;
+ }
+
+
+ if (bCenterAlign) {
+ margin_wdt1_2 = (expected_width - resized_width) >> 1;
+ margin_hgt1_2 = (expected_height - resized_height) >> 1;
+ } else {
+ margin_wdt1_2 = 0;
+ margin_hgt1_2 = 0;
+ }
+
+
+ /* 565 Conversion */
+ pImage32 = (unsigned int *)(pDecBuf);
+
+ for (i = 0, k = margin_hgt1_2; i < dechgt; i++) {
+ pImage16 = (unsigned short *)((unsigned char *)pOutBits + ((margin_wdt1_2 + (expected_width) * k) << 1));
+ for (j = 0; j < decwdt; j++) {
+ if ((*pImage32>>24) == 0) {
+ *(pImage16++) = ((*pImage32 & 0xf80000) >> 8) | ((*pImage32 & 0xfc00) >> 5) | ((*pImage32 & 0xf8) >> 3);
+ } else if ((*pImage32 >> 24) == 1) {
+ *(pImage16++) = (((*pImage32 & 0xf80000) >> 6) / 3) | (((*pImage32 & 0xfc00) >> 3)/3) | (((*pImage32 & 0xf8) >> 1)/3);
+ } else if ((*pImage32 >> 24) == 2) {
+ *(pImage16++) = ((*pImage32 & 0xf80000) >> 7) | ((*pImage32 & 0xfc00) >> 4) | ((*pImage32 & 0xf8) >> 2);
+ } else {
+ *(pImage16++) = ui_backcolor565;
+ }
+ pImage32++;
+ }
+ k++;
+ }
+
+ if (decoderline) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+
+ pFrameData->offset = inputPos;
+ pFrameData->imgCount++;
+
+ return 1;
+
+ break;
+
+ default:
+ break;
+
+ }
+ }
+}
diff --git a/src/codec/img-codec-osal.c b/src/codec/img-codec-osal.c
new file mode 100644
index 0000000..46eb130
--- /dev/null
+++ b/src/codec/img-codec-osal.c
@@ -0,0 +1,166 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-debug.h"
+#include "img-codec-osal.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+//#include <drm-service.h>
+#include <drm_client.h>
+
+void *IfegMemAlloc(unsigned int size)
+{
+ void *pmem;
+ pmem = malloc(size);
+ return pmem;
+}
+
+void IfegMemFree(void *pMem)
+{
+ free(pMem);
+ pMem = 0;
+}
+
+void *IfegMemcpy(void *dest, const void *src, unsigned int count)
+{
+ return memcpy(dest, src, count);
+}
+
+void *IfegMemset(void *dest, int c, unsigned int count)
+{
+ return memset(dest, c, count);
+}
+
+ULONG IfegGetAvailableMemSize(void)
+{
+ return 1;
+}
+
+int IfegMemcmp(const void *pMem1, const void *pMem2, size_t length)
+{
+ return memcmp(pMem1, pMem2, length);
+}
+
+static BOOL _is_real_drm = FALSE;
+
+HFile DrmOpenFile(const char *szPathName)
+{
+ int ret = 0;
+ drm_bool_type_e drm_type;
+
+ ret = drm_is_drm_file(szPathName, &drm_type);
+ if (ret < 0) {
+ thumb_err("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ if (drm_type == DRM_TRUE) {
+ _is_real_drm = TRUE;
+ } else {
+ _is_real_drm = FALSE;
+ }
+
+ if (!_is_real_drm) {
+ FILE *fp = fopen(szPathName, "rb");
+
+ if (fp == NULL) {
+ return (HFile) INVALID_HOBJ;
+ thumb_err("file open error: %s", szPathName);
+ }
+
+ return fp;
+
+ } else {
+ return (HFile) INVALID_HOBJ;
+ }
+}
+
+BOOL DrmReadFile(HFile hFile, void *pBuffer, ULONG bufLen, ULONG * pReadLen)
+{
+ size_t readCnt = -1;
+
+ if (!_is_real_drm) {
+ readCnt = fread(pBuffer, sizeof(char), bufLen, hFile);
+ *pReadLen = (ULONG) readCnt;
+ } else {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+long DrmTellFile(HFile hFile)
+{
+ if (!_is_real_drm) {
+ return ftell(hFile);
+ } else {
+ return -1;
+ }
+}
+
+BOOL DrmSeekFile(HFile hFile, long position, long offset)
+{
+ int ret = 0;
+
+ if (position < 0) {
+ return FALSE;
+ }
+ if (!_is_real_drm) {
+ ret = fseek(hFile, offset, position);
+ if (ret < 0) {
+ thumb_err("fseek failed : %s", strerror(errno));
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+BOOL DrmGetFileAttributes(const char *szPathName, FmFileAttribute * pFileAttr)
+{
+ FILE *f = NULL;
+
+ f = fopen(szPathName, "r");
+
+ if (f == NULL) {
+ return FALSE;
+ }
+
+ fseek(f, 0, SEEK_END);
+ pFileAttr->fileSize = ftell(f);
+ fclose(f);
+
+ return TRUE;
+}
+
+BOOL DrmCloseFile(HFile hFile)
+{
+ if (!_is_real_drm) {
+ fclose(hFile);
+ } else {
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
new file mode 100644
index 0000000..26027b9
--- /dev/null
+++ b/src/codec/img-codec-parser.c
@@ -0,0 +1,887 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_PERFORMANCE_CHECK_)
+#include <time.h>
+#include <sys/time.h>
+#endif
+
+#include "media-thumb-debug.h"
+#include "img-codec-common.h"
+#include "img-codec-parser.h"
+
+#define FILE_READ_SIZE 4096
+typedef struct _stream {
+ HFile fd;
+ unsigned int buffpos;
+ unsigned int filepos;
+ unsigned int filesize;
+ unsigned int buffend;
+ unsigned int debugpos;
+ 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 gIfegJPEGHeader[] = { 0xFF, 0xD8 };
+static unsigned char gIfegGIFHeader[] = { "GIF" };
+static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
+
+static int _CheckBuffer(IFEGSTREAMCTRL *pIfegstreamctrl, unsigned int size)
+{
+ unsigned long fileread;
+
+ if ((size + pIfegstreamctrl->buffpos) > pIfegstreamctrl->buffend) {
+ if (pIfegstreamctrl->filepos == pIfegstreamctrl->filesize) {
+ return 0;
+ }
+
+ if (pIfegstreamctrl->buffpos == 0) {
+ if (DrmReadFile
+ (pIfegstreamctrl->fd, pIfegstreamctrl->buffer,
+ FILE_READ_SIZE, &fileread) == FALSE) {
+ return 0;
+ }
+ if (fileread == 0) {
+ return 0;
+ }
+ pIfegstreamctrl->buffend = fileread;
+ pIfegstreamctrl->filepos += fileread;
+ pIfegstreamctrl->buffpos = 0;
+ } else {
+
+ if (size >= 2048
+ || pIfegstreamctrl->buffend -
+ pIfegstreamctrl->buffpos > FILE_READ_SIZE) {
+ return 0;
+ }
+ AcMemcpy(pIfegstreamctrl->buffer,
+ &pIfegstreamctrl->buffer[pIfegstreamctrl->
+ buffpos],
+ pIfegstreamctrl->buffend -
+ pIfegstreamctrl->buffpos);
+ if (DrmReadFile
+ (pIfegstreamctrl->fd,
+ &pIfegstreamctrl->buffer[pIfegstreamctrl->buffend -
+ pIfegstreamctrl->buffpos],
+ pIfegstreamctrl->buffpos, &fileread) == FALSE) {
+ return 0;
+ }
+ if (fileread == 0) {
+ return 0;
+ }
+ pIfegstreamctrl->buffend =
+ pIfegstreamctrl->buffend -
+ pIfegstreamctrl->buffpos + fileread;
+ pIfegstreamctrl->buffpos = 0;
+ pIfegstreamctrl->filepos += fileread;
+ }
+ return 1;
+ }
+ return 2;
+}
+
+static unsigned int _IfegReadUINT(unsigned char *pBuffer)
+{
+ return (((*pBuffer) << 24) | ((*(pBuffer + 1)) << 16) |
+ ((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
+}
+
+ImgCodecType ImgGetInfo(unsigned char *pEncodedData, unsigned long fileSize,
+ ImgImageInfo *imgInfo)
+{
+ 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);
+
+ /*********************** PNG *************************/
+ if (AcMemcmp(pEncodedData, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
+ unsigned char tmp;
+
+ if (fileSize < 40) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ /* Get Image Width */
+ width = _IfegReadUINT((pEncodedData + 16));
+
+ /* Get Image Height */
+ height = _IfegReadUINT((pEncodedData + 20));
+
+ /* Read Interlace byte */
+ tmp = *(pEncodedData + 28);
+ /* If image is interlaced then multiple should be 2 */
+ if (tmp) {
+ thumb_dbg("Interlaced PNG Image.");
+ }
+
+ thumb_dbg("type: IMG_CODEC_PNG");
+
+ if (imgInfo) {
+ imgInfo->width = width;
+ imgInfo->height = height;
+ }
+ return IMG_CODEC_PNG;
+ }
+ /*********************** 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;
+
+ }
+ /*********************** 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;
+ }
+ }
+
+ inputPos += 13;
+ finished = 0;
+
+ /* still gif image (image_cnt = 1) */
+ while (!finished) {
+ if ((unsigned int)inputPos > fileSize)
+ break;
+
+ switch (pEncodedData[inputPos++]) {
+ case 0x3b: /* End of the GIF dataset */
+ finished = 1;
+ break;
+
+ 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 */
+ 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;
+
+ default:
+ 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;
+ }
+ }
+
+ 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;
+ }
+ } while (length);
+
+ if (!imagecount)
+ imagecount++;
+ else {
+ if (imgInfo)
+ imgInfo->numberOfFrame = 2;
+ return IMG_CODEC_AGIF;
+ }
+ 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;
+ }
+ /*********************** PNG *************************/
+ 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;
+ }
+ if (fileread < 32) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ /* Get Image Width */
+ if (pWidth) {
+ *pWidth = _IfegReadUINT((EncodedDataBuffer + 8));
+ }
+
+ /* Get Image Height */
+ if (pHeight) {
+ *pHeight = _IfegReadUINT((EncodedDataBuffer + 12));
+ }
+
+ /* Read Interlace byte */
+ tmp = *(EncodedDataBuffer + 20);
+ /* If image is interlaced then multiple should be 2 */
+ if (tmp) {
+ thumb_dbg("Interlaced PNG Image.\n");
+ }
+ thumb_dbg("IMG_CODEC_PNG\n");
+ return IMG_CODEC_PNG;
+ }
+ /*********************** BMP *************************/
+ 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) {
+ thumb_err("DrmReadFile was failed");
+ return IMG_CODEC_NONE;
+ }
+ 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;
+ }
+ if (pWidth) {
+ *pWidth =
+ EncodedDataBuffer[18] | (EncodedDataBuffer[19] << 8)
+ | (EncodedDataBuffer[20] << 16) |
+ (EncodedDataBuffer[21] << 24);
+ }
+ if (pHeight) {
+ *pHeight =
+ EncodedDataBuffer[22] | (EncodedDataBuffer[23] << 8)
+ | (EncodedDataBuffer[24] << 16) |
+ (EncodedDataBuffer[25] << 24);
+ }
+
+ thumb_dbg("IMG_CODEC_BMP");
+ return IMG_CODEC_BMP;
+ }
+ /*********************** GIF *************************/
+ else if (AcMemcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH)
+ == 0) {
+ unsigned int tablelength = 0;
+ unsigned int imagecount = 0;
+ int finished = 0;
+ unsigned char temp;
+ unsigned int length;
+ IFEGSTREAMCTRL ifegstreamctrl;
+
+ if (13 > fileSize) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (DrmReadFile(hFile, &EncodedDataBuffer[8], 5, &fileread) ==
+ FALSE) {
+ thumb_err("DrmReadFile was failed");
+
+ return IMG_CODEC_NONE;
+ }
+ if (fileread < 5) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I'
+ || EncodedDataBuffer[2] != 'F' || EncodedDataBuffer[3] < '0'
+ || EncodedDataBuffer[3] > '9' || EncodedDataBuffer[4] < '0'
+ || EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A'
+ || EncodedDataBuffer[5] > 'z') {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (!(pWidth && pHeight)) {
+ return IMG_CODEC_UNKNOWN_TYPE;
+ } else {
+ *pWidth =
+ EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
+ *pHeight =
+ EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
+ }
+
+ thumb_dbg("Logical width : %d, Height : %d", *pWidth,
+ *pHeight);
+
+ if ((EncodedDataBuffer[10] & 0x80) != 0) { /* Global color table */
+ temp = (EncodedDataBuffer[10] & 0x7) + 1;
+ tablelength = (1 << temp) * 3;
+
+ if ((tablelength * sizeof(char)) >
+ sizeof(EncodedDataBuffer)) {
+ thumb_warn
+ ("_ImgGetInfoStreaming :table length is more than buffer length");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (13 + tablelength > fileSize) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ /* coverity[ -tainted_data_argument : EncodedDataBuffer ] */
+ if (DrmReadFile
+ (hFile, EncodedDataBuffer, tablelength,
+ &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+
+ return IMG_CODEC_NONE;
+ }
+ if (fileread < tablelength) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ }
+
+ fileleft = fileSize - 13 - tablelength;
+
+ ifegstreamctrl.fd = hFile;
+ ifegstreamctrl.filesize = fileleft;
+ ifegstreamctrl.filepos = 0;
+ ifegstreamctrl.buffpos = 0;
+ ifegstreamctrl.buffend = 0;
+ ifegstreamctrl.buffer = EncodedDataBuffer;
+
+ while (!finished) {
+ if (ifegstreamctrl.buffpos > ifegstreamctrl.buffend)
+ break;
+ if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
+
+ case 0x3b: /* End of the GIF dataset */
+ finished = 1;
+ break;
+
+ case 0x21: /* Extension Block */
+ if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ switch (EncodedDataBuffer
+ [ifegstreamctrl.buffpos++]) {
+
+ case 0xf9: /* Graphic control extension block */
+ if (_CheckBuffer(&ifegstreamctrl, 6) ==
+ 0) {
+ thumb_warn
+ ("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
+ return 0;
+ }
+ ifegstreamctrl.buffpos += 4;
+ ifegstreamctrl.buffpos++; /* block end */
+ break;
+
+ case 0x01: /* Plain Text block */
+ case 0xfe: /* Comment Extension block */
+ case 0xff: /* Appliation Extension block */
+ if (_CheckBuffer(&ifegstreamctrl, 1) ==
+ 0) {
+ thumb_warn
+ ("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ if (ifegstreamctrl.buffpos >
+ sizeof(EncodedDataBuffer)) {
+ thumb_warn
+ ("buffer position exceeds buffer max length ");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ 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;
+ }
+
+ /* Check integer overflow */
+ if (ifegstreamctrl.buffpos > 0xffffffff - length) {
+ thumb_err("Prevent integer overflow..");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ ifegstreamctrl.buffpos +=
+ (length);
+ /* File End Check */
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ break;
+
+ case 0x2c: /* Start of an image object. Read the image description. */
+
+ if (_CheckBuffer(&ifegstreamctrl, 9) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+#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);
+
+ *pWidth = img_block_w;
+ *pHeight = img_block_h;
+ }
+#endif
+ /* Color Resolution */
+ if ((EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x80) != 0) { /* Logical color table */
+ 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;
+ }
+
+ ifegstreamctrl.buffpos += length;
+ /* File End Check */
+ }
+
+ ifegstreamctrl.buffpos += 9;
+
+ if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ temp =
+ EncodedDataBuffer[ifegstreamctrl.buffpos++];
+ if (temp < 2 || 9 < temp) {
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ do {
+ if (_CheckBuffer(&ifegstreamctrl, 1) ==
+ 0) {
+ thumb_warn
+ ("_CheckBuffer was failed");
+ return IMG_CODEC_UNKNOWN_TYPE;
+ }
+
+ length =
+ EncodedDataBuffer[ifegstreamctrl.
+ buffpos++];
+ if ((length + ifegstreamctrl.buffpos) > ifegstreamctrl.buffend) {
+ length =
+ length +
+ ifegstreamctrl.buffpos -
+ 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;
+ }
+ return
+ IMG_CODEC_UNKNOWN_TYPE;
+ }
+ ifegstreamctrl.filepos +=
+ length;
+ ifegstreamctrl.buffpos = 0;
+ ifegstreamctrl.buffend = 0;
+ } else {
+ ifegstreamctrl.buffpos +=
+ length;
+ }
+
+ /* File End Check */
+ } while (length);
+ if (!imagecount)
+ imagecount++;
+ else {
+ if (pNumberOfFrames)
+ *pNumberOfFrames = 2;
+ thumb_dbg("IMG_CODEC_AGIF");
+ return IMG_CODEC_AGIF;
+ }
+ break;
+
+ default:
+ finished = 0;
+ break;
+
+ }
+ }
+ if (pNumberOfFrames) {
+ *pNumberOfFrames = 1;
+ }
+ thumb_dbg("IMG_CODEC_GIF");
+ return IMG_CODEC_GIF;
+ }
+
+ /*********************** 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);
+
+ rewind(hFile);
+ if (DrmReadFile(hFile, img_buf, fileSize, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+
+ return IMG_CODEC_NONE;
+ }
+
+ unsigned short block_length = img_buf[4] * 256 + img_buf[5];
+ thumb_dbg("block length : %d", block_length);
+ int i = 4;
+
+ while (i < fileSize) {
+ i += block_length;
+ if (i >= fileSize) {
+ thumb_warn
+ ("Failed to get w / h from jpeg at index [%d]",
+ i);
+ break;
+ }
+
+ if (img_buf[i] != 0xFF) {
+ thumb_warn
+ ("Failed to get w / h from jpeg at index [%d]",
+ i);
+ break;
+ }
+
+ 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
+
+#endif /* End of Get w / h from jpeg header */
+
+ thumb_dbg("IMG_CODEC_JPEG");
+ return IMG_CODEC_JPEG;
+ }
+ return IMG_CODEC_UNKNOWN_TYPE;
+}
diff --git a/src/codec/img-codec.c b/src/codec/img-codec.c
new file mode 100644
index 0000000..fadd8c2
--- /dev/null
+++ b/src/codec/img-codec.c
@@ -0,0 +1,266 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-debug.h"
+#include "img-codec.h"
+#include <string.h>
+#include <mm_util_imgp.h>
+
+unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
+ ImgImageInfo *image_info)
+{
+ AGifFrameInfo *pFrameInfo = 0;
+ void *pDecodedRGB888Buf = 0;
+ unsigned char *raw_data = NULL;
+
+ if (szFileName == NULL) {
+ thumb_err
+ ("ImgGetFirstFrameAGIFAtSize: Input File Name is NULL");
+ return NULL;
+ }
+
+ if (image_info == NULL) {
+ thumb_err
+ ("ImgGetFirstFrameAGIFAtSize: Input ImgImageInfo is NULL");
+ return NULL;
+ }
+
+ pFrameInfo =
+ ImgCreateAGIFFrame(szFileName, image_info->width,
+ image_info->height, 0, FALSE);
+
+ if (pFrameInfo && pFrameInfo->pOutBits) {
+ ImgGetNextAGIFFrame(pFrameInfo, TRUE);
+
+ if (ImgConvertRGB565ToRGB888
+ (pFrameInfo->pOutBits, &pDecodedRGB888Buf,
+ pFrameInfo->width, pFrameInfo->height)) {
+ if (pDecodedRGB888Buf) {
+ free(pFrameInfo->pOutBits);
+ pFrameInfo->pOutBits = pDecodedRGB888Buf;
+ unsigned char *src =
+ ((unsigned char *)(pFrameInfo->pOutBits));
+
+ unsigned int i = 0;
+
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, image_info->width, image_info->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);
+ memset(raw_data, 0, i);
+ unsigned char *dest = raw_data;
+ while (i--) {
+ if (dest != NULL) {
+ *dest =
+ *((unsigned char *)(src));
+ dest++;
+ src++;
+ }
+ }
+ }
+ }
+ } else {
+ thumb_warn("ImgDecodeAGIFToPixbufFromFile :: Error");
+ }
+
+ if (pFrameInfo) {
+ ImgDestroyAGIFFrame(pFrameInfo);
+ }
+
+ return (unsigned int *)raw_data;
+}
+
+int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width,
+ int height)
+{
+ unsigned short *rgb565buf = 0;
+ unsigned char *rgb888Buf = 0;
+ unsigned char red, green, blue;
+ int i;
+ unsigned int size;
+
+ rgb565buf = (unsigned short *)pBuf_rgb565;
+ if (rgb565buf == NULL) {
+ thumb_err("rgb565buf is NULL: Error !!!");
+ return FALSE;
+ }
+
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, width, height, &size) < 0) {
+ thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size");
+ return FALSE;
+ }
+
+ rgb888Buf = (unsigned char *)malloc(size);
+
+ if (rgb888Buf == NULL) {
+ thumb_err("rgb888Buf is NULL: Error !!!");
+ return FALSE;
+ }
+
+ memset(rgb888Buf, 0, size);
+
+ for (i = 0; i < width * height; i++) {
+ red = ((rgb565buf[i] >> 11) & 0x1F) << 3;
+ green = ((rgb565buf[i] >> 5) & 0x3F) << 2;
+ blue = (rgb565buf[i] & 0x1F) << 3;
+ rgb888Buf[3 * i] = red;
+ rgb888Buf[3 * i + 1] = green;
+ rgb888Buf[3 * i + 2] = blue;
+ }
+
+ *pBuf_rgb888 = (void *)rgb888Buf;
+
+ return TRUE;
+}
+
+/**
+ * This function is wrapper function for "ImgFastCreateAGIFFrameData".
+ *
+ * @param szFileName[in] Specifies the read image data.
+ * @param width[in] Specifies a width of the image to be created.
+ * @param height[in] Specifies a height of the image to be created.
+ * @param bgColor[in] Specifies background color of output buffer.
+ * @param bLoop[in] Specifies looping condition whether infinte or once play.
+ * @return This fucntion returns AGifFrameInfo Structure's pointer.
+ * @see ImgFastCreateAGIFFrameData.
+ */
+
+AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width,
+ unsigned int height, unsigned int bgColor,
+ BOOL bLoop)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ unsigned long size;
+ unsigned char *pEncodedData = NULL;
+ int cFileSize;
+ int mem_alloc_size;
+
+ if (szFileName == NULL) {
+ thumb_err("Input File Name is NULL");
+ return FALSE;
+ }
+
+ SysRequireEx(szFileName != NULL, FALSE);
+
+ hFile = DrmOpenFile(szFileName);
+ if (hFile == (HFile) INVALID_HOBJ) {
+ thumb_err("ImgCreateAGIFFrame: Cannot open file");
+ return NULL;
+ }
+
+ DrmGetFileAttributes(szFileName, &fileAttrib);
+
+ if (fileAttrib.fileSize == 0) {
+ thumb_err("Zero File Size");
+ DrmCloseFile(hFile);
+ return NULL;
+ }
+
+ 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;
+
+ if ((pEncodedData = (unsigned char *)malloc(mem_alloc_size)) == NULL) {
+ thumb_err("Memory Allocation to pEncodedData failed");
+ DrmCloseFile(hFile);
+ return NULL;
+ }
+ /* coverity[ -tainted_data_argument : pEncodedData ] */
+ if (DrmReadFile(hFile, pEncodedData, mem_alloc_size, &size) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ DrmCloseFile(hFile);
+
+ if (pEncodedData) {
+ free(pEncodedData);
+ pEncodedData = NULL;
+ }
+
+ return NULL;
+ }
+
+ thumb_dbg("ImgCreateAGIFFrame: file (%s) read...", szFileName);
+
+ DrmCloseFile(hFile);
+
+ return FastImgCreateAGIFFrameData(width, height, pEncodedData,
+ cFileSize, bgColor, bLoop);
+}
+
+/**
+ * This function is wrapper function for "ImgFastDestroyAGIFFrameData".
+ *
+ * @param pFrameData[in]
+ * @return void
+ * @see ImgFastDestroyAGIFFrameData.
+ * @see ImgFastDestroyAGIFFrameData.
+ *
+ * @note ImgFastDestroyAGIFFrameData function set free all memory in AGifFrameInfo structure
+ * even pEncodedData
+ *
+ * @author rubric(sinjae4b.lee@samsung.com)
+ */
+
+void ImgDestroyAGIFFrame(AGifFrameInfo *pFrameData)
+{
+ SysAssert(pFrameData);
+
+ FastImgDestroyAGIFFrameData(pFrameData);
+}
+
+/**
+ * This function is wrapper function for "ImgFastGetNextFrameAGIF".
+ *
+ * @param pFrameData[in]
+ * @param bCenterAlign Specifies true if you want center align in output buffer, else left top align
+ * @return This fucntion returns True or False as decoding result.
+ * @see ImgFastGetNextFrameAGIF.
+ *
+ * @note This function returns one frame data it decoded.
+ * next time, returns next decoded frame data... and so on.
+ *
+ * @author rubric(sinjae4b.lee@samsung.com)
+ */
+
+ImgFastCodecInfo ImgGetNextAGIFFrame(AGifFrameInfo *gFrameData,
+ BOOL bCenterAlign)
+{
+ int iResult;
+
+ if (gFrameData == NULL) {
+ thumb_err("Input gFrameData is NULL");
+ return IMG_INFO_DECODING_FAIL;
+ }
+
+ iResult = FastImgGetNextFrameAGIF(gFrameData, bCenterAlign);
+
+ if (iResult == 1) {
+ return IMG_INFO_DECODING_SUCCESS;
+ } else if (iResult == 2) {
+ return IMG_INFO_AGIF_LAST_FRAME;
+ } else {
+ return IMG_INFO_DECODING_FAIL;
+ }
+
+}
diff --git a/src/include/codec/AGifFrameInfo.h b/src/include/codec/AGifFrameInfo.h
new file mode 100644
index 0000000..0f5aa81
--- /dev/null
+++ b/src/include/codec/AGifFrameInfo.h
@@ -0,0 +1,65 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _AGIFFRAMEINFO_H_
+#define _AGIFFRAMEINFO_H_
+
+typedef struct tagFrameInfo
+{
+ int height;
+ int width;
+ unsigned int backcolor;
+ unsigned int ui_backcolor;
+ int imgCount;
+ int inputSize;
+
+ unsigned char *pEncodedData;
+ void *pOutBits;
+
+ unsigned char *pPrevImg;
+ unsigned int *pGlobal_table;
+ unsigned short *pPrefix;
+ unsigned char *pDstack;
+ unsigned char *pSuffix;
+
+ int flag;
+ int size;
+ int useBuffer;
+ int bLoop;
+ int global_numcol;
+ int resizedwidth;
+ int resizedheight;
+ int logi_wdt;
+ int logi_hgt;
+ int offset;
+ int firstpos;
+
+ unsigned short delay;
+
+#ifdef INTERNAL_IMGCODEC
+ unsigned int nRepeatCount;
+ unsigned int nLoopCount;
+
+ unsigned char bOneFrame;
+#endif
+}AGifFrameInfo;
+
+#endif // _AGIFFRAMEINFO_H_
diff --git a/src/include/codec/IfegDecodeAGIF.h b/src/include/codec/IfegDecodeAGIF.h
new file mode 100644
index 0000000..9510c64
--- /dev/null
+++ b/src/include/codec/IfegDecodeAGIF.h
@@ -0,0 +1,57 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IFEG_DECODE_GIF_H_
+#define _IFEG_DECODE_GIF_H_
+
+
+
+#include "AGifFrameInfo.h"
+#include "img-codec-common.h"
+
+
+
+#define MODE 0
+
+#define MAX_GIF_HEADER_SIZE 4096
+
+#if MODE == 2
+#define MAXBUFFMEMORY 330000
+#endif
+
+#define MAXWIDTH 4096
+#define MAXHEIGHT 4096
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+int FastImgGetNextFrameAGIF (AGifFrameInfo* pFrameData, BOOL bCenterAlign);
+AGifFrameInfo* FastImgCreateAGIFFrameData(unsigned int width, unsigned int height, unsigned char *pEncodedData, unsigned int file_size, unsigned int ui_backcolor, BOOL bLoop);
+void FastImgDestroyAGIFFrameData(AGifFrameInfo* pFrameData);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /*_IFEG_DECODER_H_*/
diff --git a/src/include/codec/img-codec-agif.h b/src/include/codec/img-codec-agif.h
new file mode 100644
index 0000000..4480bd8
--- /dev/null
+++ b/src/include/codec/img-codec-agif.h
@@ -0,0 +1,28 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_AGIF_H_
+#define _IMGCODEC_AGIF_H_
+
+#include "IfegDecodeAGIF.h"
+
+#endif /*_IMGCODEC_AGIF_H_*/
+
diff --git a/src/include/codec/img-codec-common.h b/src/include/codec/img-codec-common.h
new file mode 100644
index 0000000..4cb8922
--- /dev/null
+++ b/src/include/codec/img-codec-common.h
@@ -0,0 +1,304 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_COMMON_H_
+#define _IMGCODEC_COMMON_H_
+
+#include "img-codec-config.h"
+#include "img-codec-osal.h"
+#include <stdio.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+//////////////////////////////////////////////////////////////
+
+/* Maximum Image File Size Supported */
+#define IMG_MAX_IMAGE_FILE_SIZE (10 * 1024 * 1024)
+
+//////////////////////////////////////////////////////////////
+#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 SysAssert(expr)
+#else
+#define SysRequireEx(expr, retValue)
+#define SysDebug(expr, retValue)
+#define SysAssert(expr)
+#endif
+
+//////////////////////////////////////////////////////////////
+
+
+typedef enum
+{
+ IMG_INFO_DECODING_FAIL = 0,
+ IMG_INFO_DECODING_SUCCESS = 1,
+ IMG_INFO_AGIF_LAST_FRAME = 2,
+ IMG_INFO_TOO_BIG_FILE_SIZE = -1,
+ IMG_INFO_TOO_LARGE_SCALE = -2,
+ IMG_INFO_TOO_BIG_PROGRESSIVE= -3,
+ IMG_INFO_UNKNOWN_FORMAT = -4,
+ IMG_INFO_FILE_ERR = -5,
+ 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,
+ IMG_RGB_OUTPUT = 0x0002,
+ IMG_YUV_OUTPUT = 0x0005
+}ImgInputFlag;
+
+typedef enum resize
+{
+ /* During resizing aspect ratio will be maintained */
+ IMG_RESIZE_MAINTAIN_ASPECT_RATIO = 0x0001,
+ IMG_RESIZE = 0x0002
+} ImgResizeInput;
+
+
+typedef struct tagImgImageInfo
+{
+ unsigned int width;
+ unsigned int height;
+ unsigned int numberOfFrame;
+ unsigned int delay; //deprecated.
+ unsigned int bOrientation; //deprecated.
+}ImgImageInfo;
+
+typedef struct tagImgBitmap
+{
+ int width;
+ int height;
+ UCHAR bitsPerPixel; /* For TIF it should be 8 or 4 or 1 always
+ * If coming directly from camera and
+ * bitsperpixel is 16 then its assumed as 8
+ * & color type as RGBC and compression
+ * type as NO_COMP and encode it.
+ */
+
+ void *pBits;
+ BOOL bChromaKeyFlag; /* Flag to indicate chroma key
+ * Default: FALSE
+ */
+ ULONG chromaKey; /* This is the colour which needs to be (or is) transparent.
+ * This colour will be in 5, 5, 5 RGB format as below.
+ * First 16 MS Bits 0, R (5), G (5), 0 (1), B (5)
+ */
+ UCHAR disposal; /* Disposal action to take during
+ * display of current flag
+ * Default: 0
+ */
+ USHORT delay; /* Delay before display of
+ * next frame. Default: 0
+ */
+ BOOL inputFlag; /* User input required befflag used
+ * Default: FALSE
+ */
+
+ BOOL interlace; /* Interlace indicator flag
+ * Default: FALSE
+ */
+ BYTE *pLocalColorMap;/* Local color palette pointer
+ * Default: NULL
+ */
+ /* For TIF :Should be given if PALETTE color type.
+ */
+ USHORT localColorMapSize;
+ /* Local color palette size */
+ /* In TIF: Should be given if PALETTE color type.
+ */
+ void *pAlphaChannel; /* An alpha channel, representing transparency
+ * information on a per-pixel basis
+ */
+ BYTE colorType ; /* Indicates the color type of image. It can be
+ * GRAY, COLOR, PALETTED, GRAY_WITH_ALPHA_CHANNEL or
+ * COLOR_WITH_ALPHA_CHANNEL
+ */
+ /* For TIF: IT could be TIF_COLORTYPE_BILEVEL,
+ * TIF_COLORTYPE_GRAY ,TIF_COLORTYPE_RGB,
+ * TIF_COLORTYPE_PALETTE or
+ * TIF_COLORTYPE_RGBPALETTE.
+ */
+ BYTE filter ; /* Type of filter to apply. Could be one of NONE,
+ * SUB, UP, AVERAGE or PAETH
+ */
+ BYTE compressionMethod ; /* Type of compression in zLib to apply. Could be
+ * one of NONE, FIXED or DYANMIC
+ */
+ /* For TIF : IT could be TIF_COMP_NOCOMP ,
+ * TIF_COMP_PACKBIT or TIF_COMP_HUFFMAN (only for bilevel)
+ */
+
+ UCHAR colorConversion; /* Indicates whether color conversion has to
+ * be done or not
+ */
+ /* For TIF :This represents white is zero or
+ * black is zero in case of bilevel & gray.
+ */
+ UCHAR downSampling; /* Indicates whether down sampling needs to
+ * be done or not
+ */
+
+ UCHAR downSamplingMethod[3];
+ /* Down sampling offsets for every component. Possible
+ * combinations are
+ * 1, 1, 1
+ * 1, 2, 1
+ * 1, 2, 2
+ */
+} ImgBitmap;
+
+typedef struct tagImgCodecColor
+{
+ UINT16 red;
+ UINT16 green;
+ UINT16 blue;
+} ImgCodecColor;
+
+
+typedef struct
+{
+ int width, height, bpp;
+
+ BOOL tRNSFlag;
+ ImgCodecColor tRNSColor;
+
+ BOOL bKGDFlag;
+ ImgCodecColor bKGDColor;
+
+ BOOL AlphaChannelFlag;
+ unsigned short *pAlphaChannel;
+} ImgTrnsInfo;
+
+typedef struct tagImgBitmapElem ImgBitmapElem;
+
+struct tagImgBitmapElem
+{
+ int x;
+ int y;
+ ImgBitmap *pbmBitmap;
+ ImgBitmapElem *pNext;
+};
+
+typedef struct gifDecode ImgGIFFrame ;
+
+typedef struct tagImgImage
+{
+ int dataSize; /* Holds the total number of bytes required
+ * to hold the image
+ */
+ int width;
+ int height;
+
+ USHORT flag; /* This contains flags as defined
+ * in ImgCodecFlagType
+ */
+ ULONG backGroundColor; /* The backgroundColor specifies a default background
+ * color to present the image against.
+ * Note that viewers are not bound to honor this color.
+ * A viewer can choose to use a different background.
+ */
+ BYTE *pGlobalColorMap; /* Global color palette pointer
+ * Default: NULL
+ */
+ USHORT globalColorMapSize; /* Local color palette size */
+ ULONG gamma; /* The value is encoded as a 4-byte unsigned integer,
+ * representing gamma times 100000. For example, a
+ * gamma of 0.45 would be stored as the integer 45000.
+ */
+ int bitmapCount; /* This will hold the number of bitmaps in the
+ * ImgImage structure
+ */
+ BYTE function ; /* This will be set as TRUE if this structure is
+ * used for encoder
+ */
+
+ ImgBitmapElem *pHead;
+ ImgBitmapElem *pTail;
+
+
+ ULONG decodedSize ; /* 1 => Same as in the encoded stream
+ * 0 => Resize to QQVGA if size is more
+ * than 176 x 144
+ */
+
+ BOOL memAllocEx ; /* TRUE => MemAllocEx is used,
+ * FALSE => MemAlloc is used
+ */
+
+ USHORT loopCount ; /* This will contain the number of times to repeat
+ * the animation
+ */
+ BOOL bLoopCount ; /* If GIF LoopCount is present then this will be
+ * TRUE, otherwise it will be false
+ */
+
+ ImgGIFFrame *pGifFrame ; /* Stores the intermediate GIF Frame */
+
+ ImgInputFlag inputFlag;
+ ImgResizeInput resizeMethod ;
+
+ /* Flag to identify whether image is AGIF or not */
+ BOOL bAGIFImage ;
+ unsigned char *pEncodedData ;
+ INT32 cFileSize ;
+ BOOL bFirstFrame ;
+ BOOL bReservedMemoryFlag;
+ unsigned int offset ;
+} ImgImage;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // _IMGCODEC_COMMON_H_
diff --git a/src/include/codec/img-codec-config.h b/src/include/codec/img-codec-config.h
new file mode 100644
index 0000000..a918e16
--- /dev/null
+++ b/src/include/codec/img-codec-config.h
@@ -0,0 +1,26 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_CONFIG_H_
+#define _IMGCODEC_CONFIG_H_
+#define INTERNAL_IMGCODEC
+
+#endif // _IMGCODEC_CONFIG_H_
diff --git a/src/include/codec/img-codec-osal.h b/src/include/codec/img-codec-osal.h
new file mode 100644
index 0000000..67b6921
--- /dev/null
+++ b/src/include/codec/img-codec-osal.h
@@ -0,0 +1,129 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_OSAL_H_
+#define _IMGCODEC_OSAL_H_
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef BOOL
+
+#define BOOL bool//unsigned short
+#endif
+
+#ifndef UCHAR
+
+#define UCHAR unsigned char
+#endif
+
+#ifndef BYTE
+
+#define BYTE unsigned char
+#endif
+
+#ifndef USHORT
+
+#define USHORT unsigned short
+#endif
+
+#ifndef UINT16
+
+#define UINT16 unsigned short
+#endif
+
+#ifndef UINT32
+
+#define UINT32 unsigned short
+#endif
+
+#ifndef UINT
+
+#define UINT unsigned int
+#endif
+
+#ifndef INT32
+
+#define INT32 unsigned int
+#endif
+
+#ifndef ULONG
+
+#define ULONG unsigned long
+#endif
+
+#ifndef TRUE
+#define TRUE true
+#endif
+
+#ifndef FALSE
+#define FALSE false
+#endif
+
+#ifndef INVALID_HOBJ
+//#define INVALID_HOBJ (-1)
+#define INVALID_HOBJ NULL
+#endif
+
+
+typedef void* HFile;
+
+#define AcMemalloc IfegMemAlloc
+#define AcMemfree IfegMemFree
+#define AcMemcmp IfegMemcmp
+#define AcMemset IfegMemset
+#define AcMemcpy IfegMemcpy
+
+typedef struct
+{
+ ULONG fileSize; // File size
+ ULONG* startAddr; // Only used at LFS
+ ULONG attribute; // file attribute like directory or file, hidden, readonly, system, ...
+ int iVol; // positioned volume
+ ULONG allocatedSize; // real allocated size of file & directory in sub System
+} FmFileAttribute;
+
+void * IfegMemAlloc(unsigned int size);
+void IfegMemFree(void* pMem);
+void * IfegMemcpy( void *dest, const void *src, unsigned int count );
+void * IfegMemset( void *dest, int c, unsigned int count );
+int IfegMemcmp(const void* pMem1, const void* pMem2, size_t length);
+
+ULONG IfegGetAvailableMemSize(void);
+
+HFile DrmOpenFile(const char* szPathName);
+BOOL DrmReadFile(HFile hFile, void* pBuffer, ULONG bufLen, ULONG* pReadLen);
+long DrmTellFile(HFile hFile);
+BOOL DrmSeekFile(HFile hFile, long position, long offset);
+BOOL DrmGetFileAttributes(const char* szPathName, FmFileAttribute* pFileAttr);
+BOOL DrmCloseFile(HFile hFile);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // _IMGCODEC_OSAL_H_
+
+
diff --git a/src/include/codec/img-codec-parser.h b/src/include/codec/img-codec-parser.h
new file mode 100644
index 0000000..097f24d
--- /dev/null
+++ b/src/include/codec/img-codec-parser.h
@@ -0,0 +1,48 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_PARSER_H_
+#define _IMGCODEC_PARSER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#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 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);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
diff --git a/src/include/codec/img-codec.h b/src/include/codec/img-codec.h
new file mode 100644
index 0000000..07f3a6b
--- /dev/null
+++ b/src/include/codec/img-codec.h
@@ -0,0 +1,49 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _IMGCODEC_H_
+#define _IMGCODEC_H_
+
+#include "img-codec-common.h"
+#include "img-codec-parser.h"
+#include "img-codec-agif.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, ImgImageInfo *image_info);
+
+int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width, int height);
+
+
+AGifFrameInfo* ImgCreateAGIFFrame(const char *szFileName, unsigned int width, unsigned int height, unsigned int bgColor, BOOL bLoop);
+
+void ImgDestroyAGIFFrame(AGifFrameInfo* pFrameData);
+
+ImgFastCodecInfo ImgGetNextAGIFFrame (AGifFrameInfo *gFrameData, BOOL bCenterAlign);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif // _IMGCODEC_H_
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
new file mode 100755
index 0000000..f91925f
--- /dev/null
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -0,0 +1,125 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include "media-thumb-error.h"
+#include "media-thumb-debug.h"
+#include "media-thumb-types.h"
+#include "media-thumb-internal.h"
+
+#ifdef _USE_MEDIA_UTIL_
+#include "media-util-ipc.h"
+#include "media-server-ipc.h"
+#endif
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#ifndef _MEDIA_THUMB_IPC_H_
+#define _MEDIA_THUMB_IPC_H_
+
+#ifndef _USE_MEDIA_UTIL_
+#define THUMB_DAEMON_PORT 10000
+#endif
+#define MAX_PATH_SIZE 4096
+
+#ifndef _USE_MEDIA_UTIL_
+#define TIMEOUT_SEC 10
+#endif
+
+#define MAX_TRIES 3
+
+enum {
+ THUMB_REQUEST_DB_INSERT,
+ THUMB_REQUEST_SAVE_FILE,
+ THUMB_REQUEST_ALL_MEDIA,
+ THUMB_REQUEST_CANCEL_MEDIA,
+ THUMB_REQUEST_CANCEL_ALL,
+ THUMB_REQUEST_KILL_SERVER,
+ THUMB_RESPONSE
+};
+
+enum {
+ THUMB_SUCCESS,
+ THUMB_FAIL
+};
+
+#ifndef _USE_MEDIA_UTIL_
+enum {
+ CLIENT_SOCKET,
+ SERVER_SOCKET
+};
+
+typedef struct _thumbMsg{
+ int msg_type;
+ media_thumb_type thumb_type;
+ int status;
+ int pid;
+ int thumb_size;
+ int thumb_width;
+ int thumb_height;
+ int origin_width;
+ int origin_height;
+ int origin_path_size;
+ int dest_path_size;
+ char org_path[MAX_PATH_SIZE];
+ char dst_path[MAX_PATH_SIZE];
+} thumbMsg;
+#endif
+
+int
+_media_thumb_create_socket(int sock_type, int *sock);
+
+int
+_media_thumb_create_udp_socket(int *sock);
+
+int
+_media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg);
+
+int
+_media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size);
+
+int
+_media_thumb_set_buffer(thumbMsg *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,
+ media_thumb_info *thumb_info);
+
+int
+_media_thumb_request_async(int msg_type,
+ media_thumb_type thumb_type,
+ const char *origin_path,
+ thumbUserData *userData);
+
+int
+_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg);
+
+#endif /*_MEDIA_THUMB_IPC_H_*/
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
new file mode 100755
index 0000000..0180a29
--- /dev/null
+++ b/src/include/media-thumb-internal.h
@@ -0,0 +1,81 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include "media-thumbnail.h"
+#include "media-thumb-error.h"
+#include "media-thumb-types.h"
+#include "media-thumb-debug.h"
+
+#ifndef _MEDIA_THUMB_INTERNAL_H_
+#define _MEDIA_THUMB_INTERNAL_H_
+
+#define THUMB_WIDTH_MAX
+/* The maximum of resolution to be able to get thumbnail is 3000 x 3000, except for only jpeg */
+#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 9000000
+
+#define THUMB_LARGE_WIDTH 320
+#define THUMB_LARGE_HEIGHT 240
+#define THUMB_SMALL_WIDTH 160
+#define THUMB_SMALL_HEIGHT 120
+
+typedef struct {
+ int size;
+ int width;
+ int height;
+ int origin_width;
+ int origin_height;
+ int alpha;
+ unsigned char *data;
+} media_thumb_info;
+
+enum Exif_Orientation {
+ NOT_AVAILABLE=0,
+ NORMAL =1,
+ HFLIP =2,
+ ROT_180 =3,
+ VFLIP =4,
+ TRANSPOSE =5,
+ ROT_90 =6,
+ TRANSVERSE =7,
+ ROT_270 =8
+};
+
+typedef struct {
+ ThumbFunc func;
+ void *user_data;
+} thumbUserData;
+
+int
+_media_thumb_image(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info);
+
+int
+_media_thumb_video(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info);
+
+#endif /*_MEDIA_THUMB_INTERNAL_H_*/
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
new file mode 100755
index 0000000..f8e37f9
--- /dev/null
+++ b/src/include/util/media-thumb-db.h
@@ -0,0 +1,79 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sqlite3.h>
+#include <media-util.h>
+#include "media-thumb-error.h"
+#include "media-thumb-types.h"
+#include "media-thumb-debug.h"
+
+#ifndef _MEDIA_THUMB_DB_H_
+#define _MEDIA_THUMB_DB_H_
+
+#define MEDIA_DATABASE_NAME MEDIA_DB_NAME /* defined in media-util.h */
+
+#ifndef _USE_NEW_MEDIA_DB_
+#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from visual_media where thumbnail_path='' and valid=1;"
+#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM visual_media WHERE path='%q';"
+#define SELECT_TYPE_BY_PATH "SELECT content_type FROM visual_media WHERE path='%q';"
+#define UPDATE_THUMB_BY_PATH "UPDATE visual_media SET thumbnail_path = '%q' WHERE path='%q';"
+#define UPDATE_WH_BY_PATH "UPDATE image_meta SET width=%d,height=%d WHERE visual_uuid=(SELECT visual_uuid FROM visual_media WHERE path='%q');"
+
+#else
+#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from media where thumbnail_path is null and validity=1 and (media_type=0 or media_type=1);"
+#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM media WHERE path='%q';"
+#define SELECT_TYPE_BY_PATH "SELECT media_type FROM media WHERE path='%q';"
+#define SELECT_WH_BY_PATH "SELECT width, height FROM media WHERE path='%q';"
+#define UPDATE_THUMB_BY_PATH "UPDATE media SET thumbnail_path = '%q' WHERE path='%q';"
+#define UPDATE_WH_BY_PATH "UPDATE media SET width=%d,height=%d WHERE path='%q';"
+#define UPDATE_THUMB_WH_BY_PATH "UPDATE media SET thumbnail_path = '%q', width=%d,height=%d WHERE path='%q';"
+#endif
+
+sqlite3 *_media_thumb_db_get_handle();
+
+int
+_media_thumb_db_connect();
+
+int
+_media_thumb_db_disconnect();
+
+int
+_media_thumb_get_thumb_from_db(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db);
+
+int
+_media_thumb_get_thumb_from_db_with_size(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db,
+ int *width,
+ int *height);
+
+int
+_media_thumb_update_db(const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height);
+
+#endif /*_MEDIA_THUMB_DB_H_*/
+
diff --git a/src/include/util/media-thumb-debug.h b/src/include/util/media-thumb-debug.h
new file mode 100755
index 0000000..65ca53f
--- /dev/null
+++ b/src/include/util/media-thumb-debug.h
@@ -0,0 +1,81 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_THUMB_DEBUG_H_
+#define _MEDIA_THUMB_DEBUG_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlog.h>
+
+#include <unistd.h>
+#include <asm/unistd.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+
+#define _PERFORMANCE_CHECK_
+
+
+#define LOG_TAG "MEDIA_THUMBNAIL"
+
+static pid_t gettid(void)
+{
+ return syscall(__NR_gettid);
+}
+
+#define FONT_COLOR_RESET "\033[0m"
+#define FONT_COLOR_RED "\033[31m"
+#define FONT_COLOR_GREEN "\033[32m"
+#define FONT_COLOR_YELLOW "\033[33m"
+#define FONT_COLOR_BLUE "\033[34m"
+#define FONT_COLOR_PURPLE "\033[35m"
+#define FONT_COLOR_CYAN "\033[36m"
+#define FONT_COLOR_GRAY "\033[37m"
+
+#define thumb_dbg(fmt, arg...) LOGD(FONT_COLOR_RESET"[%d] " fmt "\n", gettid(), ##arg)
+#define thumb_warn(fmt, arg...) LOGW(FONT_COLOR_GREEN"[%d] " fmt "\n", gettid(), ##arg)
+#define thumb_err(fmt, arg...) LOGE(FONT_COLOR_RED"[%d] " fmt "\n", gettid(), ##arg)
+
+#ifdef _USE_LOG_FILE_
+void thumb_init_file_debug();
+void thumb_close_file_debug();
+FILE* get_fp();
+#define thumb_file_dbg(fmt,arg...) fprintf( get_fp(), "[%s: %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
+
+#endif
+
+
+#ifdef _PERFORMANCE_CHECK_
+long
+thumb_get_debug_time(void);
+void
+thumb_reset_debug_time(void);
+void
+thumb_print_debug_time(char* time_string);
+void
+thumb_print_debug_time_ex(long start, long end, const char* func_name, char* time_string);
+#endif
+
+#endif /*_MEDIA_THUMB_DEBUG_H_*/
+
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
new file mode 100755
index 0000000..335c4a5
--- /dev/null
+++ b/src/include/util/media-thumb-util.h
@@ -0,0 +1,146 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-error.h"
+#include "media-thumb-types.h"
+#include "media-thumb-debug.h"
+#include "media-util.h"
+
+#ifndef _MEDIA_THUMB_UTIL_H_
+#define _MEDIA_THUMB_UTIL_H_
+
+#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
+
+#ifndef _USE_NEW_MEDIA_DB_
+#define THUMB_NONE_TYPE 0x00000000 /* None */
+#define THUMB_IMAGE_TYPE 0x00000001 /* Image */
+#define THUMB_VIDEO_TYPE 0x00000002 /* Video */
+#else
+#define THUMB_NONE_TYPE -1 /* None */
+#define THUMB_IMAGE_TYPE 0 /* Image */
+#define THUMB_VIDEO_TYPE 1 /* Video */
+#endif
+
+#define THUMB_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL /**< File path prefix of files stored in phone */
+#define THUMB_PATH_MMC MEDIA_ROOT_PATH_SDCARD /**< File path prefix of files stored in mmc card */
+
+#define THUMB_PHONE_PATH MEDIA_DATA_PATH"/.thumb/phone"
+#define THUMB_MMC_PATH MEDIA_DATA_PATH"/.thumb/mmc"
+
+#define THUMB_DEFAULT_PATH MEDIA_DATA_PATH"/.thumb/thumb_default.png"
+
+typedef enum
+{
+ THUMB_PHONE, /**< Stored only in phone */
+ 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);
+
+int
+_media_thumb_save_to_file_with_evas(unsigned char *data,
+ int w,
+ int h,
+ int alpha,
+ char *thumb_path);
+
+int
+_media_thumb_get_width(media_thumb_type thumb_type);
+
+int
+_media_thumb_get_height(media_thumb_type thumb_type);
+
+/**
+ * _thumbnail_get_data:
+ * This function generates thumbnail raw data, which is wanted by user
+ * This api is closed for a while until being independent from evas object to be thread-safe
+ *
+ * @return This function returns zero(MEDIA_THUMB_ERROR_NONE) on success, or negative value with error code.
+ * Please refer 'media-thumb-error.h' to know the exact meaning of the error.
+ * @param[in] origin_path The path of the original image
+ * @param[in] thumb_type The type of the returned thumbnail data
+ * @param[in] format The format of the returned data
+ * @param[out] data The data of generated thumbnail.
+ * @param[out] size The size of generated thumbnail.
+ * @param[out] width The width of generated thumbnail.
+ * @param[out] height The height of generated thumbnail.
+ * @param[out] origin_width The width of original image.
+ * @param[out] origin_height The height of original image.
+ * @see None.
+ * @pre None.
+ * @post None.
+ * @remark None.
+ * @par example
+ * @code
+
+#include <media-thumbnail.h>
+
+void test_get_thumb_data()
+{
+ int ret = MEDIA_THUMB_ERROR_NONE;
+ int thumb_type = 0;
+ const char *origin_path = "/opt/usr/media/test.jpg";
+ void *data = NULL;
+
+
+ ret = _thumbnail_get_data(origin_path, thumb_type, thumb_path, &data);
+
+ if (ret < 0)
+ {
+ printf( "_thumbnail_get_data fails. error code->%d", ret);
+ }
+
+ return;
+}
+
+ * @endcode
+*/
+int _thumbnail_get_data(const char *origin_path,
+ media_thumb_type thumb_type,
+ media_thumb_format format,
+ unsigned char **data,
+ int *size,
+ int *width,
+ int *height,
+ int *origin_width,
+ int *origin_height,
+ int *alpha);
+
+#endif /*_MEDIA_THUMB_UTIL_H_*/
+
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
new file mode 100755
index 0000000..67f22bd
--- /dev/null
+++ b/src/ipc/media-thumb-ipc.c
@@ -0,0 +1,634 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumbnail.h"
+#include "media-thumb-ipc.h"
+#include "media-thumb-util.h"
+#include "media-thumb-db.h"
+#include <glib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+
+
+int
+_media_thumb_create_socket(int sock_type, int *sock)
+{
+ int sock_fd = 0;
+
+ if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ thumb_err("socket failed: %s", strerror(errno));
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ if (sock_type == CLIENT_SOCKET) {
+
+#ifdef _USE_MEDIA_UTIL_
+ struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 };
+#else
+ struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
+#endif
+
+ if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
+ thumb_err("setsockopt failed: %s", strerror(errno));
+ close(sock_fd);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+ } else if (sock_type == SERVER_SOCKET) {
+
+ int n_reuse = 1;
+
+ if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
+ thumb_err("setsockopt failed: %s", strerror(errno));
+ close(sock_fd);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+ }
+
+ *sock = sock_fd;
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+
+int
+_media_thumb_create_udp_socket(int *sock)
+{
+ int sock_fd = 0;
+
+ if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ thumb_err("socket failed: %s", strerror(errno));
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+#ifdef _USE_MEDIA_UTIL_
+ struct timeval tv_timeout = { MS_TIMEOUT_SEC_10, 0 };
+#else
+ struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
+#endif
+
+ if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
+ thumb_err("setsockopt failed: %s", strerror(errno));
+ close(sock_fd);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ *sock = sock_fd;
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int _media_thumb_get_error()
+{
+ if (errno == EWOULDBLOCK) {
+ thumb_err("Timeout. Can't try any more");
+ return MEDIA_THUMB_ERROR_TIMEOUT;
+ } else {
+ thumb_err("recvfrom failed : %s", strerror(errno));
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+}
+
+int
+_media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
+{
+ int recv_msg_len = 0;
+ unsigned char *buf = NULL;
+
+ buf = (unsigned char*)malloc(header_size);
+
+ if ((recv_msg_len = recv(sock, buf, header_size, 0)) <= 0) {
+ thumb_err("recvfrom failed : %s", strerror(errno));
+ SAFE_FREE(buf);
+ return _media_thumb_get_error();
+ }
+
+ memcpy(msg, buf, header_size);
+ //thumb_dbg("origin_path_size : %d, dest_path_size : %d", msg->origin_path_size, msg->dest_path_size);
+
+ SAFE_FREE(buf);
+
+ buf = (unsigned char*)malloc(msg->origin_path_size);
+
+ if ((recv_msg_len = recv(sock, buf, msg->origin_path_size, 0)) < 0) {
+ thumb_err("recvfrom failed : %s", strerror(errno));
+ SAFE_FREE(buf);
+ return _media_thumb_get_error();
+ }
+
+ strncpy(msg->org_path, (char*)buf, msg->origin_path_size);
+ //thumb_dbg("original path : %s", msg->org_path);
+
+ SAFE_FREE(buf);
+ buf = (unsigned char*)malloc(msg->dest_path_size);
+
+ if ((recv_msg_len = recv(sock, buf, msg->dest_path_size, 0)) < 0) {
+ thumb_err("recvfrom failed : %s", strerror(errno));
+ SAFE_FREE(buf);
+ return _media_thumb_get_error();
+ }
+
+ strncpy(msg->dst_path, (char*)buf, msg->dest_path_size);
+ //thumb_dbg("destination path : %s", msg->dst_path);
+
+ SAFE_FREE(buf);
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+
+int
+_media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size)
+{
+ int recv_msg_len = 0;
+ unsigned int from_addr_size = sizeof(struct sockaddr_in);
+ unsigned char *buf = NULL;
+
+ buf = (unsigned char*)malloc(sizeof(thumbMsg));
+
+ if ((recv_msg_len = recvfrom(sock, buf, sizeof(thumbMsg), 0, (struct sockaddr *)from_addr, &from_addr_size)) < 0) {
+ thumb_err("recvfrom failed : %s", strerror(errno));
+ SAFE_FREE(buf);
+ return _media_thumb_get_error();
+ }
+
+ memcpy(msg, buf, header_size);
+
+ if (msg->origin_path_size <= 0 || msg->origin_path_size > MAX_PATH_SIZE) {
+ SAFE_FREE(buf);
+ thumb_err("msg->origin_path_size is invalid %d", msg->origin_path_size );
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ strncpy(msg->org_path, (char*)buf + header_size, msg->origin_path_size);
+ //thumb_dbg("original path : %s", msg->org_path);
+
+ if (msg->dest_path_size <= 0 || msg->dest_path_size > MAX_PATH_SIZE) {
+ SAFE_FREE(buf);
+ thumb_err("msg->origin_path_size is invalid %d", msg->dest_path_size );
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ strncpy(msg->dst_path, (char*)buf + header_size + msg->origin_path_size, msg->dest_path_size);
+ //thumb_dbg("destination path : %s", msg->dst_path);
+
+ SAFE_FREE(buf);
+ *from_size = from_addr_size;
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
+{
+ if (req_msg == NULL || buf == NULL) {
+ return -1;
+ }
+
+ int org_path_len = 0;
+ int dst_path_len = 0;
+ int size = 0;
+ int header_size = 0;
+
+ header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2;
+ org_path_len = strlen(req_msg->org_path) + 1;
+ dst_path_len = strlen(req_msg->dst_path) + 1;
+
+ //thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
+
+ size = header_size + org_path_len + dst_path_len;
+ *buf = malloc(size);
+ memcpy(*buf, req_msg, header_size);
+ memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
+ memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
+
+ *buf_size = size;
+
+ return 0;
+}
+
+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)
+{
+ int sock;
+ const char *serv_ip = "127.0.0.1";
+ struct sockaddr_in serv_addr;
+
+ int recv_str_len = 0;
+ int err;
+ int pid;
+
+
+#ifdef _USE_MEDIA_UTIL_
+ if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) {
+ thumb_err("ms_ipc_create_client_socket failed");
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+#else
+ /* Creaete a TCP socket */
+ if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) {
+ thumb_err("_media_thumb_create_socket failed");
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+#endif
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
+#ifdef _USE_MEDIA_UTIL_
+ serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT);
+#else
+ serv_addr.sin_port = htons(THUMB_DAEMON_PORT);
+#endif
+
+ /* Connecting to the thumbnail server */
+ if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ thumb_err("connect error : %s", strerror(errno));
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ thumbMsg req_msg;
+ thumbMsg recv_msg;
+
+ memset((void *)&req_msg, 0, sizeof(thumbMsg));
+ memset((void *)&recv_msg, 0, sizeof(thumbMsg));
+
+ /* Get PID of client*/
+ pid = getpid();
+ req_msg.pid = pid;
+
+ /* Set requset message */
+ req_msg.msg_type = msg_type;
+ req_msg.thumb_type = thumb_type;
+ strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
+ req_msg.org_path[strlen(req_msg.org_path)] = '\0';
+
+ if (msg_type == THUMB_REQUEST_SAVE_FILE) {
+ strncpy(req_msg.dst_path, thumb_path, sizeof(req_msg.dst_path));
+ req_msg.dst_path[strlen(req_msg.dst_path)] = '\0';
+ }
+
+ req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
+ req_msg.dest_path_size = strlen(req_msg.dst_path) + 1;
+
+ if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
+ thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ unsigned char *buf = NULL;
+ int buf_size = 0;
+ int header_size = 0;
+
+ header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2;
+ _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
+
+ if (send(sock, buf, buf_size, 0) != buf_size) {
+ thumb_err("sendto failed: %d\n", errno);
+ SAFE_FREE(buf);
+ close(sock);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ thumb_dbg("Sending msg to thumbnail daemon is successful");
+
+ SAFE_FREE(buf);
+
+ if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
+ thumb_err("_media_thumb_recv_msg failed ");
+ close(sock);
+ return err;
+ }
+
+ recv_str_len = strlen(recv_msg.org_path);
+ thumb_dbg("recv %s(%d) from thumb daemon is successful", recv_msg.org_path, recv_str_len);
+
+ close(sock);
+
+ if (recv_str_len > max_length) {
+ thumb_err("user buffer is too small. Output's length is %d", recv_str_len);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (recv_msg.status == THUMB_FAIL) {
+ thumb_err("Failed to make thumbnail");
+ return -1;
+ }
+
+ if (msg_type != THUMB_REQUEST_SAVE_FILE) {
+ strncpy(thumb_path, recv_msg.dst_path, max_length);
+ }
+
+ thumb_info->origin_width = recv_msg.origin_width;
+ thumb_info->origin_height = recv_msg.origin_height;
+
+ return 0;
+}
+
+int
+_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
+{
+ int err = -1;
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+ int origin_w = 0;
+ int origin_h = 0;
+ int max_length = 0;
+ char *thumb_path = NULL;
+ int need_update_db = 0;
+ int alpha = 0;
+
+ if (req_msg == NULL || res_msg == NULL) {
+ thumb_err("Invalid msg!");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ int msg_type = req_msg->msg_type;
+ media_thumb_type thumb_type = req_msg->thumb_type;
+ const char *origin_path = req_msg->org_path;
+
+ media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+
+ thumb_path = res_msg->dst_path;
+ thumb_path[0] = '\0';
+ max_length = sizeof(res_msg->dst_path);
+
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ if (msg_type == THUMB_REQUEST_DB_INSERT) {
+ err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
+ if (err == 0) {
+ res_msg->origin_width = origin_w;
+ res_msg->origin_height = origin_h;
+ _media_thumb_db_disconnect();
+ return MEDIA_THUMB_ERROR_NONE;
+ } else {
+ if (strlen(thumb_path) == 0) {
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
+ return err;
+ }
+
+ thumb_path[strlen(thumb_path)] = '\0';
+ }
+ }
+
+ } else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
+ strncpy(thumb_path, req_msg->dst_path, max_length);
+
+ } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
+ return err;
+ }
+
+ thumb_path[strlen(thumb_path)] = '\0';
+ }
+
+ thumb_dbg("Thumb path : %s", thumb_path);
+
+ if (g_file_test(thumb_path,
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ thumb_warn("thumb path already exists in file system.. remove the existed file");
+ _media_thumb_remove_file(thumb_path);
+ }
+
+ err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha);
+ if (err < 0) {
+ thumb_err("_thumbnail_get_data failed - %d\n", err);
+ SAFE_FREE(data);
+
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ _media_thumb_db_disconnect();
+ return err;
+ }
+
+ //thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
+ //thumb_dbg("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
+ //thumb_dbg("Thumb : %s", thumb_path);
+
+ res_msg->msg_type = THUMB_RESPONSE;
+ res_msg->thumb_size = thumb_size;
+ res_msg->thumb_width = thumb_w;
+ res_msg->thumb_height = thumb_h;
+ res_msg->origin_width = origin_w;
+ res_msg->origin_height = origin_h;
+
+ /* If the image is transparent PNG format, make png file as thumbnail of this image */
+ if (alpha) {
+ char file_ext[10];
+ err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
+ if (strncasecmp(file_ext, "png", 3) == 0) {
+ int len = strlen(thumb_path);
+ thumb_path[len - 3] = 'p';
+ thumb_path[len - 2] = 'n';
+ thumb_path[len - 1] = 'g';
+ }
+ thumb_dbg("Thumb path is changed : %s", thumb_path);
+ }
+
+ err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, alpha, thumb_path);
+ if (err < 0) {
+ thumb_err("save_to_file_with_evas failed - %d\n", err);
+ SAFE_FREE(data);
+
+ if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA)
+ strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+
+ _media_thumb_db_disconnect();
+ return err;
+ } else {
+ thumb_dbg("file save success\n");
+ }
+
+ /* fsync */
+ int fd = 0;
+ fd = open(thumb_path, O_WRONLY);
+ if (fd < 0) {
+ thumb_warn("open failed");
+ } else {
+ err = fsync(fd);
+ if (err == -1) {
+ thumb_warn("fsync failed");
+ }
+
+ close(fd);
+ }
+ /* End of fsync */
+
+ SAFE_FREE(data);
+
+ /* DB update if needed */
+ if (need_update_db == 1) {
+ err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ }
+ }
+
+ _media_thumb_db_disconnect();
+
+ return 0;
+}
+
+gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
+{
+ thumb_err("_media_thumb_write_socket is called");
+
+ thumbMsg recv_msg;
+ int header_size = 0;
+ int recv_str_len = 0;
+ int sock = 0;
+ int err = MEDIA_THUMB_ERROR_NONE;
+
+ memset((void *)&recv_msg, 0, sizeof(thumbMsg));
+ sock = g_io_channel_unix_get_fd(src);
+
+ header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2;
+
+ if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
+ thumb_err("_media_thumb_recv_msg failed ");
+ g_io_channel_shutdown(src, TRUE, NULL);
+ return err;
+ }
+
+ recv_str_len = strlen(recv_msg.dst_path);
+ thumb_dbg("recv %s(%d) from thumb daemon is successful", recv_msg.dst_path, recv_str_len);
+
+ g_io_channel_shutdown(src, TRUE, NULL);
+
+ if (recv_msg.status == THUMB_FAIL) {
+ thumb_err("Failed to make thumbnail");
+ err = MEDIA_THUMB_ERROR_UNSUPPORTED;
+ goto callback;
+ }
+
+callback:
+ if (data) {
+ thumbUserData* cb = (thumbUserData*)data;
+ cb->func(err, recv_msg.dst_path, cb->user_data);
+ free(cb);
+ cb = NULL;
+ }
+
+ return FALSE;
+}
+
+int
+_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData)
+{
+ int sock;
+ const char *serv_ip = "127.0.0.1";
+ struct sockaddr_in serv_addr;
+
+ int pid;
+
+
+#ifdef _USE_MEDIA_UTIL_
+ if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock) < 0) {
+ thumb_err("ms_ipc_create_client_socket failed");
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+#else
+ /* Creaete a TCP socket */
+ if (_media_thumb_create_socket(CLIENT_SOCKET, &sock) < 0) {
+ thumb_err("_media_thumb_create_socket failed");
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+#endif
+
+ GIOChannel *channel = NULL;
+ channel = g_io_channel_unix_new(sock);
+
+ if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
+ g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData );
+ }
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
+#ifdef _USE_MEDIA_UTIL_
+ serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT);
+#else
+ serv_addr.sin_port = htons(THUMB_DAEMON_PORT);
+#endif
+
+ /* Connecting to the thumbnail server */
+ if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ thumb_err("connect error : %s", strerror(errno));
+ g_io_channel_shutdown(channel, TRUE, NULL);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ thumbMsg req_msg;
+ memset((void *)&req_msg, 0, sizeof(thumbMsg));
+
+ pid = getpid();
+ req_msg.pid = pid;
+ req_msg.msg_type = msg_type;
+ req_msg.thumb_type = thumb_type;
+ strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
+ req_msg.org_path[strlen(req_msg.org_path)] = '\0';
+
+ req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
+ req_msg.dest_path_size = strlen(req_msg.dst_path) + 1;
+
+ if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
+ thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
+ g_io_channel_shutdown(channel, TRUE, NULL);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ unsigned char *buf = NULL;
+ int buf_size = 0;
+ _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
+
+ //thumb_dbg("buffer size : %d", buf_size);
+
+ if (send(sock, buf, buf_size, 0) != buf_size) {
+ thumb_err("sendto failed: %d\n", errno);
+ SAFE_FREE(buf);
+ g_io_channel_shutdown(channel, TRUE, NULL);
+ return MEDIA_THUMB_ERROR_NETWORK;
+ }
+
+ SAFE_FREE(buf);
+ thumb_dbg("Sending msg to thumbnail daemon is successful");
+
+ if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) {
+ g_io_channel_shutdown(channel, TRUE, NULL);
+ }
+
+ return 0;
+}
+
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
new file mode 100755
index 0000000..c809ead
--- /dev/null
+++ b/src/media-thumb-internal.c
@@ -0,0 +1,1302 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-debug.h"
+#include "media-thumb-util.h"
+#include "media-thumb-internal.h"
+
+#include "AGifFrameInfo.h"
+#include "IfegDecodeAGIF.h"
+#include "img-codec.h"
+#include "img-codec-agif.h"
+#include "img-codec-common.h"
+#include "img-codec-osal.h"
+#include "img-codec-parser.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+//#include <drm-service.h>
+#include <drm_client.h>
+#include <mm_file.h>
+#include <mm_error.h>
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+#include <Evas.h>
+#include <Ecore_Evas.h>
+#include <libexif/exif-data.h>
+
+#define MEDA_THUMB_ROUND_UP_4(num) (((num)+3)&~3)
+
+int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
+ 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;
+
+ if (orig_w < orig_h) {
+ portrait = TRUE;
+ }
+
+#if 0
+ /* Set Lager length to default size */
+ if (portrait) {
+ if (orig_h < _media_thumb_get_width(thumb_type)) {
+ *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;
+ } else {
+ if (orig_w < _media_thumb_get_width(thumb_type)) {
+ *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
+ /* Set smaller length to default size */
+ if (portrait) {
+ if (orig_w < _media_thumb_get_width(thumb_type)) {
+ *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)) {
+ *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;
+ }
+#endif
+
+ /* The width of RGB888 raw data has to be rounded by 4 */
+ *thumb_w = MEDA_THUMB_ROUND_UP_4(*thumb_w);
+
+ thumb_dbg("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
+
+ return 0;
+}
+
+int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value,
+ int ifdtype, long tagtype)
+{
+ ExifEntry *entry;
+ ExifIfd ifd;
+ ExifTag tag;
+
+ if (ed == NULL) {
+ return -1;
+ }
+
+ ifd = ifdtype;
+ tag = tagtype;
+
+ entry = exif_content_get_entry(ed->ifd[ifd], tag);
+ if (entry) {
+ if (tag == EXIF_TAG_ORIENTATION ||
+ tag == EXIF_TAG_PIXEL_X_DIMENSION ||
+ tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
+
+ if (value == NULL) {
+ thumb_dbg("value is NULL");
+ return -1;
+ }
+
+ ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
+ short exif_value = exif_get_short(entry->data, mByteOrder);
+ thumb_dbg("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
+ *value = (int)exif_value;
+ } else {
+ /* Get the contents of the tag in human-readable form */
+ if (buf == NULL) {
+ thumb_dbg("buf is NULL");
+ return -1;
+ }
+ exif_entry_get_value(entry, buf, max_size);
+ buf[strlen(buf)] = '\0';
+
+ if (*buf) {
+ thumb_dbg("%s: %s\n",
+ exif_tag_get_name_in_ifd(tag, ifd), buf);
+ }
+ }
+ }
+
+ return 0;
+}
+
+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)
+{
+ 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;
+ tag = EXIF_TAG_COMPRESSION;
+
+ 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);
+
+ if (value == 6) {
+ thumb_dbg("There's jpeg thumb in this image");
+ } else {
+ thumb_dbg("There's NO jpeg thumb in this image");
+ return -1;
+ }
+ } else {
+ thumb_dbg("entry is NULL");
+ return -1;
+ }
+
+ /* 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);
+
+ thumb_width = value;
+ }
+
+ 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;
+ }
+
+ 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;
+ } else {
+ thumb_dbg("data is NULL");
+ return -1;
+ }
+
+ /* 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;
+ } else {
+ thumb_dbg("entry is NULL");
+ }
+
+ 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];
+
+ err =
+ _media_thumb_get_hash_name(file_full_path,
+ thumb_path,
+ sizeof(thumb_path));
+ 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;
+ }
+ } else {
+ nwrite = write(fd, thumb, size);
+ if (nwrite < 0) {
+ thumb_dbg("write failed\n");
+ close(fd);
+
+ SAFE_FREE(thumb);
+ return -1;
+ }
+ close(fd);
+ }
+
+ SAFE_FREE(thumb);
+
+ 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;
+ }
+
+ //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;
+ }
+
+ 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 (need_resize == 1) {
+ int resized_w = _media_thumb_get_width(MEDIA_THUMB_LARGE);
+ int resized_h = _media_thumb_get_height(MEDIA_THUMB_LARGE);
+
+ 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);
+
+ SAFE_FREE(decoded.data);
+ 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;
+ }
+
+ 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");
+
+ SAFE_FREE(decoded.data);
+ SAFE_FREE(dst);
+
+ return -1;
+ }
+
+ SAFE_FREE(decoded.data);
+ decoded.data = dst;
+ decoded.width = thumb_width = resized_w;
+ decoded.height = thumb_height = resized_h;
+ }
+
+ 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;
+
+ 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;
+ }
+
+ 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;
+ }
+
+ //thumb_dbg("Size of Rotated : %d", r_size);
+
+ 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;
+ } else {
+ thumb_dbg("mm_util_rotate_image succeed");
+ }
+
+ SAFE_FREE(decoded.data);
+
+ //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;
+ thumb_info->width = thumb_width;
+ thumb_info->height = thumb_height;
+ } else {
+ thumb_warn("Unknown orientation");
+ SAFE_FREE(decoded.data);
+ return -1;
+ }
+
+ return 0;
+}
+
+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 thumb_width = dst_width;
+ int thumb_height = dst_height;
+ unsigned int buf_size = 0;
+
+ if (mm_util_get_image_size(src_format, thumb_width,
+ thumb_height, &buf_size) < 0) {
+ thumb_err("Failed to get buffer size");
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ thumb_dbg("mm_util_get_image_size : %d", buf_size);
+
+ unsigned char *dst = (unsigned char *)malloc(buf_size);
+
+ if (mm_util_resize_image((unsigned char *)src_data, src_width,
+ src_height, src_format,
+ dst, (unsigned int *)&thumb_width,
+ (unsigned int *)&thumb_height) < 0) {
+ thumb_err("Failed to resize the thumbnails");
+
+ SAFE_FREE(dst);
+
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ thumb_info->size = buf_size;
+ thumb_info->width = thumb_width;
+ thumb_info->height = thumb_height;
+ thumb_info->data = malloc(buf_size);
+ memcpy(thumb_info->data, dst, buf_size);
+
+ SAFE_FREE(dst);
+
+ return 0;
+}
+
+int _media_thumb_get_wh_with_evas(const char *origin_path, int *width, int *height)
+{
+ /* using evas to get w/h */
+ Ecore_Evas *ee =
+ ecore_evas_buffer_new(0, 0);
+ if (!ee) {
+ thumb_err("ecore_evas_new fails");
+ return -1;
+ }
+ Evas *evas = ecore_evas_get(ee);
+ if (!evas) {
+ thumb_err("ecore_evas_get fails");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ Evas_Object *image_object =
+ evas_object_image_add(evas);
+ if (!image_object) {
+ thumb_err
+ ("evas_object_image_add fails");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ evas_object_image_file_set(image_object,
+ origin_path,
+ NULL);
+ evas_object_image_size_get(image_object,
+ width, height);
+
+ thumb_dbg("Width:%d, Height:%d", *width, *height);
+
+ ecore_evas_free(ee);
+
+ return 0;
+}
+
+int _media_thumb_decode_with_evas(const char *origin_path,
+ int thumb_width, int thumb_height,
+ media_thumb_info *thumb_info, int need_scale, int orientation)
+{
+ Ecore_Evas *resize_img_ee;
+ resize_img_ee =
+ ecore_evas_buffer_new(thumb_width, thumb_height);
+
+ if (!resize_img_ee) {
+ thumb_err("Failed to create a new ecore evas buffer\n");
+ return -1;
+ }
+
+ Evas *resize_img_e = ecore_evas_get(resize_img_ee);
+ if (!resize_img_e) {
+ thumb_err("Failed to ecore_evas_get\n");
+ ecore_evas_free(resize_img_ee);
+ return -1;
+ }
+
+ Evas_Object *source_img = evas_object_image_add(resize_img_e);
+ if (!source_img) {
+ thumb_err("evas_object_image_add failed\n");
+ ecore_evas_free(resize_img_ee);
+ return -1;
+ }
+
+ evas_object_image_file_set(source_img, origin_path, NULL);
+
+ /* Get w/h of original image */
+ int width = 0;
+ int height = 0;
+
+ evas_object_image_size_get(source_img, &width, &height);
+ thumb_info->origin_width = width;
+ thumb_info->origin_height = height;
+ //thumb_dbg("origin width:%d, origin height:%d", width, height);
+
+ if ((need_scale == 1) && (width * height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
+ thumb_dbg("This is too large image. so this's scale is going to be down");
+ evas_object_image_load_scale_down_set(source_img, 10);
+ }
+
+ evas_object_image_load_orientation_set(source_img, 1);
+
+ int rotated_orig_w = 0;
+ int rotated_orig_h = 0;
+
+ if (orientation == ROT_90 || orientation == ROT_270) {
+ rotated_orig_w = height;
+ rotated_orig_h = width;
+ } else {
+ rotated_orig_w = width;
+ rotated_orig_h = height;
+ }
+
+ //thumb_dbg("rotated - origin width:%d, origin height:%d", rotated_orig_w, rotated_orig_h);
+
+ int err = -1;
+ 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
+ ecore_evas_free(resize_img_ee);
+ return err;
+ }
+
+ ecore_evas_resize(resize_img_ee, thumb_width, thumb_height);
+
+ evas_object_image_load_size_set(source_img, thumb_width, thumb_height);
+ evas_object_image_fill_set(source_img,
+ 0, 0,
+ thumb_width,
+ thumb_height);
+
+ evas_object_image_filled_set(source_img, 1);
+ evas_object_resize(source_img,
+ thumb_width,
+ thumb_height);
+ evas_object_show(source_img);
+
+ /* Set alpha from original */
+ thumb_info->alpha = evas_object_image_alpha_get(source_img);
+
+ /* Create target buffer and copy origin resized img to it */
+ Ecore_Evas *target_ee = ecore_evas_buffer_new(
+ thumb_width, thumb_height);
+ if (!target_ee) {
+ thumb_err("Failed to create a ecore evas\n");
+ ecore_evas_free(resize_img_ee);
+ return -1;
+ }
+
+ Evas *target_evas = ecore_evas_get(target_ee);
+ if (!target_evas) {
+ thumb_err("Failed to ecore_evas_get\n");
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_free(target_ee);
+ return -1;
+ }
+
+ Evas_Object *ret_image =
+ evas_object_image_add(target_evas);
+
+ evas_object_image_size_set(ret_image,
+ thumb_width,
+ thumb_height);
+
+ evas_object_image_fill_set(ret_image, 0,
+ 0,
+ thumb_width,
+ thumb_height);
+
+ evas_object_image_filled_set(ret_image, EINA_TRUE);
+ evas_object_image_data_set(ret_image,
+ (int *)ecore_evas_buffer_pixels_get(resize_img_ee));
+ evas_object_image_data_update_add(ret_image, 0, 0, thumb_width,
+ thumb_height);
+
+ unsigned int buf_size = 0;
+
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_width,
+ thumb_height, &buf_size) < 0) {
+ thumb_err("Failed to get buffer size");
+
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_free(target_ee);
+
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ //thumb_dbg("mm_util_get_image_size : %d", buf_size);
+
+ thumb_info->size = buf_size;
+ thumb_info->width = thumb_width;
+ thumb_info->height = thumb_height;
+ thumb_info->data = malloc(buf_size);
+ memcpy(thumb_info->data, evas_object_image_data_get(ret_image, 1), buf_size);
+
+ ecore_evas_free(target_ee);
+ ecore_evas_free(resize_img_ee);
+
+ return 0;
+}
+
+mm_util_img_format _media_thumb_get_format(media_thumb_format src_format)
+{
+ switch(src_format) {
+ case MEDIA_THUMB_BGRA:
+ return MM_UTIL_IMG_FMT_BGRA8888;
+ case MEDIA_THUMB_RGB888:
+ return MM_UTIL_IMG_FMT_RGB888;
+ default:
+ return -1;
+ }
+}
+
+
+int _media_thumb_convert_data(media_thumb_info *thumb_info,
+ int thumb_width,
+ int thumb_height,
+ mm_util_img_format src_format,
+ mm_util_img_format dst_format)
+{
+ int err = -1;
+ unsigned int buf_size = 0;
+ unsigned char *src_data = thumb_info->data;
+ unsigned char *dst_data = NULL;
+
+ thumb_dbg("src format:%d, dst format:%d", src_format, dst_format);
+
+ if (mm_util_get_image_size(dst_format, thumb_width,
+ thumb_height, &buf_size) < 0) {
+ thumb_err("Failed to get buffer size");
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ thumb_dbg("mm_util_get_image_size : %d", buf_size);
+
+ dst_data = (unsigned char *)malloc(buf_size);
+
+ if (src_format == MM_UTIL_IMG_FMT_RGB888 &&
+ dst_format == MM_UTIL_IMG_FMT_BGRA8888) {
+
+ int i = 0, j;
+ for (j = 0; j < thumb_width * 3 * thumb_height;
+ j += 3) {
+ dst_data[i++] = (src_data[j + 2]);
+ dst_data[i++] = (src_data[j + 1]);
+ dst_data[i++] = (src_data[j]);
+ dst_data[i++] = 0x0;
+ }
+
+ } else {
+ err = mm_util_convert_colorspace(src_data,
+ thumb_width,
+ thumb_height,
+ src_format,
+ dst_data,
+ dst_format);
+
+ if (err < 0) {
+ thumb_err("Failed to change from rgb888 to argb8888 %d", err);
+ SAFE_FREE(dst_data);
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+ }
+
+ SAFE_FREE(thumb_info->data);
+ thumb_info->data = dst_data;
+ thumb_info->size = buf_size;
+
+ thumb_dbg("_media_thumb_convert_data success");
+
+ return 0;
+}
+
+int _media_thumb_convert_format(media_thumb_info *thumb_info,
+ media_thumb_format src_format,
+ media_thumb_format dst_format)
+{
+ int err = -1;
+
+ if (src_format == dst_format) {
+ //thumb_dbg("src_format == dst_format");
+ return 0;
+ }
+
+ mm_util_img_format src_mm_format;
+ mm_util_img_format dst_mm_format;
+
+ src_mm_format = _media_thumb_get_format(src_format);
+ dst_mm_format = _media_thumb_get_format(dst_format);
+
+ if (src_mm_format == -1 || dst_mm_format == -1) {
+ thumb_err("Format is invalid");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ err = _media_thumb_convert_data(thumb_info,
+ thumb_info->width,
+ thumb_info->height,
+ src_mm_format,
+ dst_mm_format);
+
+ if (err < 0) {
+ thumb_err("media_thumb_convert_format failed : %d", err);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_agif(const char *origin_path,
+ ImgImageInfo *image_info,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ unsigned int *thumb = NULL;
+ media_thumb_type thumb_type;
+
+ thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
+
+ if (!thumb) {
+ thumb_err("Frame data is NULL!!");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
+ SAFE_FREE(thumb);
+ return err;
+ }
+
+ err = _media_thumb_resize_data((unsigned char *)thumb,
+ image_info->width,
+ image_info->height,
+ MM_UTIL_IMG_FMT_RGB888,
+ thumb_info,
+ thumb_width,
+ thumb_height);
+
+ if (err < 0) {
+ thumb_err("_media_thumb_resize_data failed: %d", err);
+ SAFE_FREE(thumb);
+ return err;
+ }
+
+ SAFE_FREE(thumb);
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_png(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+
+ if (err < 0) {
+ thumb_err("decode_with_evas failed : %d", err);
+ return err;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_bmp(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+
+ if (err < 0) {
+ thumb_err("decode_with_evas failed : %d", err);
+ return err;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_wbmp(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+
+ if (err < 0) {
+ thumb_err("decode_with_evas failed : %d", err);
+ return err;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_gif(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+
+ if (err < 0) {
+ thumb_err("decode_with_evas failed : %d", err);
+ return err;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+
+ return 0;
+}
+
+int _media_thumb_jpeg(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ ExifData *ed = NULL;
+ int thumb_done = 0;
+ int orientation = NORMAL;
+
+ /* Load an ExifData object from an EXIF file */
+ ed = exif_data_new_from_file(origin_path);
+
+ if (ed) {
+ /* First, Get orientation from exif */
+ err = _media_thumb_get_exif_info(ed, NULL, 0, &orientation, EXIF_IFD_0, EXIF_TAG_ORIENTATION);
+
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_exif_info failed");
+ }
+
+ /* Second, Get thumb from exif */
+ err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info);
+
+ if (err < 0) {
+ thumb_dbg("_media_thumb_get_thumb_from_exif failed");
+ } else {
+ thumb_done = 1;
+ thumb_dbg("_media_thumb_get_thumb_from_exif succeed");
+
+ 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);
+
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_data failed : %d", err);
+ exif_data_unref(ed);
+ return err;
+ }
+ }
+
+ exif_data_unref(ed);
+ }
+
+ if (!thumb_done) {
+
+ err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, orientation);
+
+ if (err < 0) {
+ thumb_err("decode_with_evas failed : %d", err);
+ return err;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+ }
+
+ return 0;
+}
+
+int
+_media_thumb_image(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+ int image_type = 0;
+ int origin_w = 0;
+ int origin_h = 0;
+ ImgImageInfo image_info = { 0 };
+
+ image_type = ImgGetInfoFile(origin_path, &image_info);
+
+ thumb_info->origin_width = origin_w = image_info.width;
+ thumb_info->origin_height = origin_h = image_info.height;
+
+ thumb_dbg("image type is %d\n", image_type);
+
+ if ((image_type != IMG_CODEC_JPEG) &&
+ (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
+ thumb_warn("This original image is too big");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ if (image_type == IMG_CODEC_AGIF) {
+ err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info);
+ } else if (image_type == IMG_CODEC_JPEG) {
+ err = _media_thumb_jpeg(origin_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);
+ } else if (image_type == IMG_CODEC_GIF) {
+ err = _media_thumb_gif(origin_path, thumb_width, thumb_height, format, thumb_info);
+ } else if (image_type == IMG_CODEC_BMP) {
+ err = _media_thumb_bmp(origin_path, thumb_width, thumb_height, format, thumb_info);
+ } else {
+ char file_ext[10];
+ err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
+ } else {
+ if (strcasecmp(file_ext, "wbmp") == 0) {
+ image_type = IMG_CODEC_WBMP;
+ int wbmp_width = 0;
+ int wbmp_height = 0;
+
+ err = _media_thumb_get_wh_with_evas(origin_path, &wbmp_width, &wbmp_height);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_wh_with_evas in WBMP : %d", err);
+ return err;
+ }
+
+ if (wbmp_width * wbmp_height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB) {
+ thumb_warn("This original image is too big");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ thumb_info->origin_width = wbmp_width;
+ thumb_info->origin_height = wbmp_height;
+
+ err = _media_thumb_wbmp(origin_path, thumb_width, thumb_height, format, thumb_info);
+
+ return err;
+ }
+ }
+
+ thumb_warn("Unsupported image type");
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ return err;
+}
+
+int
+_media_thumb_video(const char *origin_path,
+ int thumb_width,
+ int thumb_height,
+ media_thumb_format format,
+ media_thumb_info *thumb_info)
+{
+ int err = -1;
+
+ MMHandleType content = (MMHandleType) NULL;
+ void *frame = NULL;
+ int video_track_num = 0;
+ char *err_msg = NULL;
+ int is_drm = 0;
+ int size = 0;
+ int width = 0;
+ int height = 0;
+ int ret = 0;
+ drm_bool_type_e drm_type;
+
+ ret = (drm_is_drm_file(origin_path, &drm_type) == 1);
+ if (ret < 0) {
+ thumb_err("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ is_drm = drm_type;
+ err = mm_file_create_content_attrs(&content, origin_path);
+
+ if (err < 0) {
+ thumb_err("mm_file_create_content_attrs fails : %d", err);
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ err =
+ mm_file_get_attrs(content, &err_msg,
+ MM_FILE_CONTENT_VIDEO_TRACK_COUNT,
+ &video_track_num, NULL);
+
+ if (err != 0) {
+ thumb_err("mm_file_get_attrs fails : %s", err_msg);
+ SAFE_FREE(err_msg);
+ mm_file_destroy_content_attrs(content);
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ /* MMF api handle both normal and DRM video */
+ if (video_track_num > 0 || is_drm) {
+
+ err = mm_file_get_attrs(content, &err_msg,
+ MM_FILE_CONTENT_VIDEO_WIDTH,
+ &width,
+ MM_FILE_CONTENT_VIDEO_HEIGHT,
+ &height,
+ MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
+ &size, NULL);
+
+ if (err != 0) {
+ thumb_err("mm_file_get_attrs fails : %s", err_msg);
+ SAFE_FREE(err_msg);
+ mm_file_destroy_content_attrs(content);
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ thumb_dbg("video width: %d", width);
+ thumb_dbg("video height: %d", height);
+ thumb_dbg("thumbnail size=%d", size);
+ thumb_dbg("frame = 0x%x", frame);
+
+ if (frame == NULL || width == 0 || height == 0) {
+ thumb_err("Failed to get frame data");
+ mm_file_destroy_content_attrs(content);
+ return MEDIA_THUMB_ERROR_MM_UTIL;
+ }
+
+ 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);
+
+ if (width > thumb_width || height > thumb_height) {
+ err = _media_thumb_resize_data(frame,
+ width,
+ height,
+ MM_UTIL_IMG_FMT_RGB888,
+ thumb_info,
+ thumb_width,
+ thumb_height);
+
+ if (err < 0) {
+ thumb_err("_media_thumb_resize_data failed - %d", err);
+ SAFE_FREE(thumb_info->data);
+ mm_file_destroy_content_attrs(content);
+ return err;
+ }
+ } else {
+
+ thumb_info->size = size;
+ thumb_info->width = width;
+ thumb_info->height = height;
+ thumb_info->data = malloc(size);
+ 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;
+ unsigned int r_w = thumb_info->height;
+ unsigned int r_h = thumb_info->width;
+ unsigned int r_size = 0;
+
+ if (rot_type == MM_UTIL_ROTATE_180) {
+ r_w = thumb_info->width;
+ r_h = thumb_info->height;
+ }
+
+ 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(thumb_info->data);
+ return err;
+ }
+
+ //thumb_dbg("Size of Rotated : %d", r_size);
+ rotated = (unsigned char *)malloc(r_size);
+ err = mm_util_rotate_image(thumb_info->data, thumb_info->width, thumb_info->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(thumb_info->data);
+ SAFE_FREE(rotated);
+ return err;
+ } else {
+ thumb_dbg("mm_util_rotate_image succeed");
+ }
+
+ SAFE_FREE(thumb_info->data);
+
+ thumb_info->data = rotated;
+ thumb_info->size = r_size;
+ thumb_info->width = r_w;
+ thumb_info->height = r_h;
+ }
+
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ if (err < 0) {
+ thumb_err("_media_thumb_convert_format falied: %d", err);
+ SAFE_FREE(thumb_info->data);
+ return err;
+ }
+ } else {
+ thumb_dbg("no contents information\n");
+ frame = NULL;
+ mm_file_destroy_content_attrs(content);
+
+ return MEDIA_THUMB_ERROR_UNSUPPORTED;
+ }
+
+ return 0;
+}
+
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
new file mode 100755
index 0000000..11bcc0b
--- /dev/null
+++ b/src/media-thumbnail.c
@@ -0,0 +1,288 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumbnail.h"
+#include "media-thumb-debug.h"
+#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)
+{
+ int err = -1;
+ //int need_update_db = 0;
+ media_thumb_info thumb_info;
+
+ if (origin_path == NULL || thumb_path == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (max_length <= 0) {
+ thumb_err("Length is invalid");
+ return MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_err("Path : %s", origin_path);
+/*
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ err = _media_thumb_get_thumb_from_db(origin_path, thumb_path, max_length, &need_update_db);
+ if (err == 0) {
+ _media_thumb_db_disconnect();
+ return MEDIA_THUMB_ERROR_NONE;
+ }
+*/
+ /* 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ //_media_thumb_db_disconnect();
+ return err;
+ }
+/*
+ // Need to update DB once generating thumb is done
+ if (need_update_db) {
+ err = _media_thumb_update_db(origin_path, thumb_path, thumb_info.origin_width, thumb_info.origin_height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ }
+ }
+
+ _media_thumb_db_disconnect();
+*/
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path)
+{
+ int err = -1;
+
+ if (origin_path == NULL || thumb_path == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ media_thumb_info thumb_info;
+ char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
+
+ strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
+
+ /* 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height)
+{
+ int err = -1;
+ //int need_update_db = 0;
+ media_thumb_info thumb_info;
+
+ if (origin_path == NULL || thumb_path == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (origin_width == NULL || origin_height == NULL) {
+ thumb_err("Invalid parameter ( width or height )");
+ return MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (max_length <= 0) {
+ thumb_err("Length is invalid");
+ return MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_err("Path : %s", origin_path);
+/*
+ err = _media_thumb_db_connect();
+ if (err < 0) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &width, &height);
+ if (err == 0) {
+ _media_thumb_db_disconnect();
+ return MEDIA_THUMB_ERROR_NONE;
+ }
+*/
+ /* 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ //_media_thumb_db_disconnect();
+ return err;
+ }
+
+ *origin_width = thumb_info.origin_width;
+ *origin_height = thumb_info.origin_height;
+
+ //_media_thumb_db_disconnect();
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_extract_all_thumbs(void)
+{
+ int err = -1;
+
+ 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data)
+{
+ int err = -1;
+
+ if (origin_path == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_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 MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_err("Path : %s", origin_path);
+
+ thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
+ userData->func = (ThumbFunc)func;
+ 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);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ SAFE_FREE(userData);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int _media_thumbnail_cancel_cb(int error_code, char* path, void* data)
+{
+ thumb_dbg("Error code : %d", error_code);
+ if (path) thumb_dbg("Cancel : %s", path);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_cancel_media(const char *origin_path)
+{
+ int err = -1;
+
+ media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
+
+ if (origin_path == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int thumbnail_request_cancel_all()
+{
+ int err = -1;
+
+ 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_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_request failed : %d", err);
+ return err;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
new file mode 100755
index 0000000..e3ca193
--- /dev/null
+++ b/src/util/media-thumb-db.c
@@ -0,0 +1,609 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-db.h"
+#include "media-thumb-util.h"
+
+#include <glib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util-func.h>
+
+
+#ifdef _USE_MEDIA_UTIL_
+static __thread MediaDBHandle *db_handle;
+#else
+static __thread sqlite3 *db_handle;
+#endif
+
+static int _media_thumb_busy_handler(void *pData, int count)
+{
+ usleep(50000);
+ thumb_dbg("_media_thumb_busy_handler called : %d\n", count);
+
+ return 100 - count;
+}
+
+sqlite3 *_media_thumb_db_get_handle()
+{
+ return db_handle;
+}
+
+int
+_media_thumb_sqlite_connect(sqlite3 **handle)
+{
+ int err = -1;
+
+ err = db_util_open(MEDIA_DATABASE_NAME, handle,
+ DB_UTIL_REGISTER_HOOK_METHOD);
+
+ if (SQLITE_OK != err) {
+ *handle = NULL;
+ return -1;
+ }
+
+ /*Register busy handler*/
+ if (*handle) {
+ err = sqlite3_busy_handler(*handle, _media_thumb_busy_handler, NULL);
+ if (SQLITE_OK != err) {
+ if (*handle) {
+ thumb_err("[sqlite] %s\n", sqlite3_errmsg(*handle));
+ db_util_close(*handle);
+ }
+ *handle = NULL;
+
+ return -1;
+ }
+ } else {
+ *handle = NULL;
+ return -1;
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_sqlite_disconnect(sqlite3 *handle)
+{
+ int err = -1;
+ if (handle != NULL) {
+ err = db_util_close(handle);
+
+ if (SQLITE_OK != err) {
+ handle = NULL;
+ return -1;
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_type_from_db(sqlite3 *handle,
+ const char *origin_path,
+ int *type)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ *type = sqlite3_column_int(stmt, 0);
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+
+int _media_thumb_get_wh_from_db(sqlite3 *handle,
+ const char *origin_path,
+ int *width,
+ int *height)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ *width = sqlite3_column_int(stmt, 0);
+ *height = sqlite3_column_int(stmt, 1);
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_thumb_path_from_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path,
+ int max_length)
+{
+ thumb_dbg("Origin path : %s", origin_path);
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string);
+
+ thumb_dbg("Query: %s", query_string);
+
+ err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ thumb_err("prepare error [%s]\n", sqlite3_errmsg(handle));
+ return -1;
+ }
+
+ err = sqlite3_step(stmt);
+ if (err != SQLITE_ROW) {
+ thumb_err("end of row [%s]\n", sqlite3_errmsg(handle));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+
+ if (sqlite3_column_text(stmt, 0))
+ strncpy(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length);
+ else
+ thumb_path[0] = '\0';
+
+ sqlite3_finalize(stmt);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_thumb_path_to_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *thumbpath_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ thumbpath_string = sqlite3_mprintf("%s", thumb_path);
+ query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string);
+
+#ifndef _USE_MEDIA_UTIL_
+ char *err_msg = NULL;
+ err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg);
+
+ thumb_dbg("Query : %s", query_string);
+
+ sqlite3_free(query_string);
+ sqlite3_free(thumbpath_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ if (err_msg) {
+ thumb_err("Failed to query[ %s ]", err_msg);
+ sqlite3_free(err_msg);
+ err_msg = NULL;
+ }
+
+ return -1;
+ }
+
+ if (err_msg)
+ sqlite3_free(err_msg);
+#else
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+#endif
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_wh_to_db(sqlite3 *handle,
+ const char *origin_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string);
+
+#ifndef _USE_MEDIA_UTIL_
+ char *err_msg = NULL;
+ err = sqlite3_exec(handle, query_string, NULL, NULL, &err_msg);
+
+ thumb_dbg("Query : %s", query_string);
+
+ sqlite3_free(query_string);
+ sqlite3_free(path_string);
+
+ if (SQLITE_OK != err) {
+ if (err_msg) {
+ thumb_err("Failed to query[ %s ]", err_msg);
+ sqlite3_free(err_msg);
+ err_msg = NULL;
+ }
+
+ return -1;
+ }
+
+ if (err_msg)
+ sqlite3_free(err_msg);
+#else
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+#endif
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
+ const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+ char *path_string = NULL;
+ char *query_string = NULL;
+
+ if (handle == NULL) {
+ thumb_err("DB handle is NULL");
+ return -1;
+ }
+
+ path_string = sqlite3_mprintf("%s", origin_path);
+ query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string);
+
+ err = media_db_request_update_db(query_string);
+ if (err < 0) {
+ thumb_err("media_db_request_update_db failed : %d", err);
+ return err;
+ }
+
+ thumb_dbg("Query success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_db_connect()
+{
+ int err = -1;
+/*
+ err = media_svc_connect(&mb_svc_handle);
+ if (err < 0) {
+ thumb_err("media_svc_connect failed: %d", err);
+ mb_svc_handle = NULL;
+ return err;
+ }
+*/
+#ifndef _USE_MEDIA_UTIL_
+ err = _media_thumb_sqlite_connect(&db_handle);
+ if (err < 0) {
+ thumb_err("_media_thumb_sqlite_connect failed: %d", err);
+ db_handle = NULL;
+ return err;
+ }
+#else
+ err = media_db_connect(&db_handle);
+ if (err < 0) {
+ thumb_err("media_db_connect failed: %d", err);
+ db_handle = NULL;
+ return MEDIA_THUMB_ERROR_DB;
+ }
+#endif
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_db_disconnect()
+{
+ int err = -1;
+/*
+ err = media_svc_disconnect(mb_svc_handle);
+
+ if (err < 0) {
+ thumb_err("media_svc_disconnect failed: %d", err);
+ }
+
+ mb_svc_handle = NULL;
+*/
+#ifndef _USE_MEDIA_UTIL_
+ err = _media_thumb_sqlite_disconnect(db_handle);
+ if (err < 0) {
+ thumb_err("_media_thumb_sqlite_disconnect failed: %d", err);
+ db_handle = NULL;
+ return err;
+ }
+#else
+ err = media_db_disconnect(db_handle);
+ if (err < 0) {
+ thumb_err("media_db_disconnect failed: %d", err);
+ db_handle = NULL;
+ return MEDIA_THUMB_ERROR_DB;
+ }
+#endif
+
+ db_handle = NULL;
+ return err;
+}
+
+int
+_media_thumb_get_thumb_from_db(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db)
+{
+ thumb_dbg("");
+ int err = -1;
+
+ //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
+ err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_warn("Original path doesn't exist in DB");
+ return -1;
+ }
+
+ if (strlen(thumb_path) == 0) {
+ thumb_warn("thumb path doesn't exist in DB");
+ *need_update_db = 1;
+ return -1;
+ }
+
+ thumb_dbg("Thumb path in DB is %s", thumb_path);
+
+ if (!g_file_test(thumb_path,
+ G_FILE_TEST_EXISTS)) {
+ thumb_warn("thumb path doesn't exist in file system");
+ *need_update_db = 1;
+ return -1;
+ } else {
+ thumb_dbg("This thumb path already exist");
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_get_thumb_from_db_with_size(const char *origin_path,
+ char *thumb_path,
+ int max_length,
+ int *need_update_db,
+ int *width,
+ int *height)
+{
+ thumb_dbg("");
+ int err = -1;
+
+ //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
+ err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
+ if (err < 0) {
+ thumb_warn("Original path doesn't exist in DB");
+ return -1;
+ }
+
+ if (strlen(thumb_path) == 0) {
+ thumb_warn("thumb path doesn't exist in DB");
+ *need_update_db = 1;
+ return -1;
+ }
+
+ thumb_dbg("Thumb path in DB is %s", thumb_path);
+
+ if (!g_file_test(thumb_path,
+ G_FILE_TEST_EXISTS)) {
+ thumb_warn("thumb path doesn't exist in file system");
+ *need_update_db = 1;
+ return -1;
+ } else {
+ thumb_dbg("This thumb path already exist");
+ int orig_w = 0;
+ int orig_h = 0;
+
+ err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_wh_from_db failed : %d", err);
+ } else {
+ thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h);
+ *width = orig_w;
+ *height = orig_h;
+ }
+ }
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
+int
+_media_thumb_update_db(const char *origin_path,
+ char *thumb_path,
+ int width,
+ int height)
+{
+ thumb_dbg("");
+ int err = -1;
+
+#if 0
+ Mitem *item = NULL;
+
+ err = minfo_get_item(mb_svc_handle, origin_path, &item);
+ if (err < 0) {
+ thumb_err("minfo_get_item (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ err = minfo_update_media_thumb(mb_svc_handle, item->uuid, thumb_path);
+ if (err < 0) {
+ thumb_err("minfo_update_media_thumb (ID:%s, %s) failed: %d",
+ item->uuid, thumb_path, err);
+ minfo_destroy_mtype_item(item);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ if (item->type == MINFO_ITEM_IMAGE) {
+ err = minfo_update_image_meta_info_int(mb_svc_handle, item->uuid,
+ MINFO_IMAGE_META_WIDTH, width,
+ MINFO_IMAGE_META_HEIGHT, height, -1);
+
+ if (err < 0) {
+ thumb_err("minfo_update_image_meta_info_int failed: %d", err);
+ minfo_destroy_mtype_item(item);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+
+ err = minfo_destroy_mtype_item(item);
+#endif
+
+ int media_type = THUMB_NONE_TYPE;
+ err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type);
+ if (err < 0) {
+ thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+#if 0
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+
+ if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
+ err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+#else
+ if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
+ err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ } else {
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+ if (err < 0) {
+ thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ return MEDIA_THUMB_ERROR_DB;
+ }
+ }
+#endif
+
+ thumb_dbg("_media_thumb_update_db success");
+
+ return MEDIA_THUMB_ERROR_NONE;
+}
+
diff --git a/src/util/media-thumb-debug.c b/src/util/media-thumb-debug.c
new file mode 100755
index 0000000..b684aa4
--- /dev/null
+++ b/src/util/media-thumb-debug.c
@@ -0,0 +1,112 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <asm/unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include "media-thumb-debug.h"
+
+#ifdef _PERFORMANCE_CHECK_
+static long g_time_usec = 0L;
+#endif
+
+#ifdef _USE_LOG_FILE_
+static FILE *g_log_fp = NULL;
+static char _g_file_path[1024] = "\0";
+
+FILE *get_fp()
+{
+ return g_log_fp;
+}
+
+void thumb_init_file_debug()
+{
+ if (g_log_fp == NULL) {
+ snprintf(_g_file_path, sizeof(_g_file_path), "/tmp/%s",
+ "media-thumb.log");
+ if (access(_g_file_path, R_OK == 0)) {
+ remove(_g_file_path);
+ }
+
+ g_log_fp = fopen(_g_file_path, "a");
+ }
+}
+
+void thumb_close_file_debug()
+{
+ if (g_log_fp != NULL) {
+ fclose(g_log_fp);
+ g_log_fp = NULL;
+ }
+}
+
+#endif
+
+long thumb_get_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ return time.tv_sec * 1000000 + time.tv_usec;
+#else
+ return 0L;
+#endif
+}
+
+void thumb_reset_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ g_time_usec = time.tv_sec * 1000000 + time.tv_usec;
+#endif
+}
+
+void thumb_print_debug_time(char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ double totaltime = 0.0;
+
+ gettimeofday(&time, NULL);
+ totaltime =
+ (double)(time.tv_sec * 1000000 + time.tv_usec -
+ g_time_usec) / CLOCKS_PER_SEC;
+
+ thumb_dbg("time [%s] : %f \n", time_string, totaltime);
+#endif
+}
+
+void
+thumb_print_debug_time_ex(long start, long end, const char *func_name,
+ char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ double totaltime = 0.0;
+
+ totaltime = (double)(end - start) / CLOCKS_PER_SEC;
+
+ thumb_dbg("time [%s: %s] : %f \n", func_name, time_string,
+ totaltime);
+#endif
+}
+
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
new file mode 100755
index 0000000..0db4133
--- /dev/null
+++ b/src/util/media-thumb-util.c
@@ -0,0 +1,374 @@
+/*
+ * libmedia-thumbnail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-thumb-util.h"
+#include "media-thumb-internal.h"
+
+#include <glib.h>
+#include <aul.h>
+#include <string.h>
+#include <drm_client.h>
+
+#include <Evas.h>
+#include <Ecore_Evas.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;
+ drm_bool_type_e drm_type;
+ drm_file_type_e drm_file_type;
+ char mimetype[255];
+
+ if (file_full_path == NULL)
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+
+ ret = drm_is_drm_file(file_full_path, &drm_type);
+ if (ret < 0) {
+ thumb_err("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ if (drm_type == DRM_TRUE) {
+ thumb_dbg("DRM file : %s", file_full_path);
+
+ ret = drm_get_file_type(file_full_path, &drm_file_type);
+ if (ret < 0) {
+ thumb_err("drm_get_file_type falied : %d", ret);
+ return THUMB_NONE_TYPE;
+ }
+
+ if (drm_file_type == DRM_TYPE_UNDEFINED) {
+ return THUMB_NONE_TYPE;
+ } else {
+ drm_content_info_s contentInfo;
+ memset(&contentInfo, 0x00, sizeof(drm_content_info_s));
+
+ ret = drm_get_content_info(file_full_path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ thumb_err("drm_get_content_info() fails. : %d", ret);
+ return THUMB_NONE_TYPE;
+ }
+ thumb_dbg("DRM mime type: %s", contentInfo.mime_type);
+
+ strncpy(mimetype, contentInfo.mime_type, sizeof(mimetype) - 1);
+ mimetype[sizeof(mimetype) - 1] = '\0';
+ }
+ } else {
+ /* get content type and mime type from file. */
+ ret =
+ aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
+ if (ret < 0) {
+ thumb_warn
+ ("aul_get_mime_from_file fail.. Now trying to get type by extension");
+
+ char ext[255] = { 0 };
+ int ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext));
+ if (ret < 0) {
+ thumb_err("_media_thumb_get_file_ext failed");
+ return THUMB_NONE_TYPE;
+ }
+
+ if (strcasecmp(ext, "JPG") == 0 ||
+ strcasecmp(ext, "JPEG") == 0 ||
+ strcasecmp(ext, "PNG") == 0 ||
+ strcasecmp(ext, "GIF") == 0 ||
+ strcasecmp(ext, "AGIF") == 0 ||
+ strcasecmp(ext, "XWD") == 0 ||
+ strcasecmp(ext, "BMP") == 0 ||
+ strcasecmp(ext, "WBMP") == 0) {
+ return THUMB_IMAGE_TYPE;
+ } else if (strcasecmp(ext, "AVI") == 0 ||
+ strcasecmp(ext, "MPEG") == 0 ||
+ strcasecmp(ext, "MP4") == 0 ||
+ strcasecmp(ext, "DCF") == 0 ||
+ strcasecmp(ext, "WMV") == 0 ||
+ strcasecmp(ext, "3GPP") == 0 ||
+ strcasecmp(ext, "3GP") == 0) {
+ return THUMB_VIDEO_TYPE;
+ } else {
+ return THUMB_NONE_TYPE;
+ }
+ }
+ }
+
+ thumb_dbg("mime type : %s", mimetype);
+
+ /* categorize from mimetype */
+ if (strstr(mimetype, "image") != NULL) {
+ return THUMB_IMAGE_TYPE;
+ } else if (strstr(mimetype, "video") != NULL) {
+ return THUMB_VIDEO_TYPE;
+ }
+
+ return THUMB_NONE_TYPE;
+}
+
+int _media_thumb_get_store_type_by_path(const char *full_path)
+{
+ if (full_path != NULL) {
+ if (strncmp
+ (full_path, THUMB_PATH_PHONE,
+ strlen(THUMB_PATH_PHONE)) == 0) {
+ return THUMB_PHONE;
+ } else
+ if (strncmp
+ (full_path, THUMB_PATH_MMC,
+ strlen(THUMB_PATH_MMC)) == 0) {
+ return THUMB_MMC;
+ }
+ }
+
+ return -1;
+}
+
+int _media_thumb_remove_file(const char *path)
+{
+ int result = -1;
+
+ result = remove(path);
+ if (result == 0) {
+ thumb_dbg("success to remove file");
+ return TRUE;
+ } else {
+ thumb_err("fail to remove file[%s] result errno = %s", path, strerror(errno));
+ return FALSE;
+ }
+}
+
+int
+_media_thumb_get_hash_name(const char *file_full_path,
+ char *thumb_hash_path, size_t max_thumb_path)
+{
+ char *hash_name;
+ char *thumb_dir = NULL;
+ char file_ext[255] = { 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;
+ }
+
+ _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) {
+ thumb_dir = THUMB_PHONE_PATH;
+ } else if (store_type == THUMB_MMC) {
+ thumb_dir = THUMB_MMC_PATH;
+ } else {
+ thumb_dir = THUMB_PHONE_PATH;
+ }
+
+ hash_name = _media_thumb_generate_hash_name(file_full_path);
+
+ int ret_len;
+ ret_len =
+ snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg",
+ thumb_dir, file_ext, hash_name);
+ 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;
+ }
+
+ //thumb_dbg("thumb hash : %s", thumb_hash_path);
+
+ return 0;
+}
+
+
+int _media_thumb_save_to_file_with_evas(unsigned char *data,
+ int w,
+ int h,
+ int alpha,
+ char *thumb_path)
+{
+ Ecore_Evas *ee =
+ ecore_evas_buffer_new(w, h);
+ if (ee == NULL) {
+ thumb_err("Failed to create a new ecore evas buffer\n");
+ return -1;
+ }
+
+ Evas *evas = ecore_evas_get(ee);
+ if (evas == NULL) {
+ thumb_err("Failed to ecore_evas_get\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ Evas_Object *img = NULL;
+ img = evas_object_image_add(evas);
+
+ if (img == NULL) {
+ thumb_err("image object is NULL\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+
+ evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_size_set(img, w, h);
+ evas_object_image_fill_set(img, 0, 0, w, h);
+
+ if (alpha) evas_object_image_alpha_set(img, 1);
+
+ evas_object_image_data_set(img, data);
+ evas_object_image_data_update_add(img, 0, 0, w, h);
+
+ if (evas_object_image_save
+ (img, thumb_path, NULL, "quality=100 compress=1")) {
+ thumb_dbg("evas_object_image_save success\n");
+ ecore_evas_free(ee);
+
+ return 0;
+ } else {
+ thumb_dbg("evas_object_image_save failed\n");
+ ecore_evas_free(ee);
+ return -1;
+ }
+}
+
+
+int _thumbnail_get_data(const char *origin_path,
+ media_thumb_type thumb_type,
+ media_thumb_format format,
+ unsigned char **data,
+ int *size,
+ int *width,
+ int *height,
+ int *origin_width,
+ int *origin_height,
+ int *alpha)
+{
+ int err = -1;
+ int thumb_width = -1;
+ int thumb_height = -1;
+
+ if (origin_path == NULL || size == NULL
+ || width == NULL || height == NULL) {
+ thumb_err("Invalid parameter");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (format < MEDIA_THUMB_BGRA || format > MEDIA_THUMB_RGB888) {
+ thumb_err("parameter format is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!g_file_test
+ (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("Original path (%s) does not exist", origin_path);
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_width = _media_thumb_get_width(thumb_type);
+ if (thumb_width < 0) {
+ thumb_err("media_thumb_type is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_height = _media_thumb_get_height(thumb_type);
+ if (thumb_height < 0) {
+ thumb_err("media_thumb_type is invalid");
+ return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
+ }
+
+ thumb_dbg("Origin path : %s", origin_path);
+
+ int file_type = THUMB_NONE_TYPE;
+ media_thumb_info thumb_info = {0,};
+ file_type = _media_thumb_get_file_type(origin_path);
+
+ if (file_type == THUMB_IMAGE_TYPE) {
+ err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_image failed");
+ return err;
+ }
+
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ if (err < 0) {
+ thumb_err("_media_thumb_image failed");
+ return err;
+ }
+ }
+
+ if (size) *size = thumb_info.size;
+ if (width) *width = thumb_info.width;
+ if (height) *height = thumb_info.height;
+ *data = thumb_info.data;
+ if (origin_width) *origin_width = thumb_info.origin_width;
+ if (origin_height) *origin_height = thumb_info.origin_height;
+ if (alpha) *alpha = thumb_info.alpha;
+
+ thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x",
+ *size, *width, *height, *data);
+
+ return MEDIA_THUMB_ERROR_NONE;
+}