summaryrefslogtreecommitdiff
path: root/src/codec/img-codec-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec/img-codec-parser.c')
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec-parser.c711
1 files changed, 245 insertions, 466 deletions
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
index dd04455..2d8d348 100644..100755
--- a/src/codec/img-codec-parser.c
+++ b/src/codec/img-codec-parser.c
@@ -33,6 +33,21 @@
#include "img-codec-common.h"
#include "img-codec-parser.h"
+#define MINIMUM_HEADER_BYTES 8
+
+#define PNG_HEADER_LENGTH 8
+#define JPG_HEADER_LENGTH 2
+#define GIF_HEADER_LENGTH 3
+#define TIFF_HEADER_LENGTH 2
+#define BMP_HEADER_LENGTH 2
+#define WBMP_HEADER_LENGTH 2
+#define TIFF_IMAGE_WIDTH 0x100
+#define TIFF_IMAGE_HEIGHT 0x101
+
+#define JPG_HEADER_TYPE_LENGTH 2
+#define JPG_BLOCK_SIZE_LENGTH 2
+#define JPG_IMAGE_SIZE_LENGTH 8
+
#define FILE_READ_SIZE 4096
typedef struct _stream {
HFile fd;
@@ -44,61 +59,11 @@ typedef struct _stream {
unsigned char *buffer;
} IFEGSTREAMCTRL;
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo);
-BOOL process_EXIF(unsigned char *ExifSection, unsigned int length,
- unsigned int *pOrientataion);
-
-ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- ImgCodecType result = 0;
- SysAssert(hFile);
- SysAssert(fileSize);
-
- if (imgInfo == NULL) {
- result = _ImgGetInfoStreaming(hFile, fileSize, NULL);
- } else {
- result = _ImgGetInfoStreaming(hFile, fileSize, imgInfo);
- }
-
- DrmSeekFile(hFile, SEEK_SET, 0);
-
- return result;
-
-}
-
-ImgCodecType ImgGetInfoFile(const char *filePath, ImgImageInfo * imgInfo)
-{
- HFile hFile;
- FmFileAttribute fileAttrib;
- ImgCodecType result;
- SysAssert(filePath);
- hFile = DrmOpenFile(filePath);
-
- if (hFile == (HFile) INVALID_HOBJ) {
- return IMG_CODEC_NONE;
- }
- DrmGetFileAttributes(filePath, &fileAttrib);
-
- if ((fileAttrib.fileSize == 0)) {
- DrmCloseFile(hFile);
- return IMG_CODEC_NONE;
- }
-
- result = ImgGetInfoHFile(hFile, fileAttrib.fileSize, imgInfo);
-
- DrmCloseFile(hFile);
-
- return result;
-
-}
-
-static unsigned char gIfegPNGHeader[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+static unsigned char gIfegPNGHeader[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 };
static unsigned char gIfegGIFHeader[] = { "GIF" };
static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
+static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
static int _CheckBuffer(IFEGSTREAMCTRL *pIfegstreamctrl, unsigned int size)
{
@@ -160,277 +125,118 @@ static unsigned int _IfegReadUINT(unsigned char *pBuffer)
((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
}
-ImgCodecType ImgGetInfo(unsigned char *pEncodedData, unsigned long fileSize,
- ImgImageInfo *imgInfo)
+static int _ImgGetImageInfo(HFile hFile, unsigned long fileSize, char *fileExt, ImgCodecType *type, unsigned int *width, unsigned int *height, bool fast_mode)
{
- unsigned int width = 0, height = 0;
-
- /* Initialize values */
- if (imgInfo) {
- imgInfo->width = 0;
- imgInfo->height = 0;
- imgInfo->numberOfFrame = 1;
- imgInfo->bOrientation = 0;
- }
-
- SysAssert(pEncodedData);
- SysAssert(fileSize);
+ unsigned int fileleft;
+ unsigned long fileread;
+ unsigned char EncodedDataBuffer[4096];
- /*********************** PNG *************************/
- if (AcMemcmp(pEncodedData, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
- unsigned char tmp;
+ unsigned int *pWidth = NULL;
+ unsigned int *pHeight = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
- if (fileSize < 40) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Get Image Width */
- width = _IfegReadUINT((pEncodedData + 16));
+ if (type == NULL || width == NULL ||height == NULL ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ } else {
+ pWidth = width;
+ pHeight = height;
- /* Get Image Height */
- height = _IfegReadUINT((pEncodedData + 20));
+ *type = IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = 0;
+ *pHeight = 0;
+ }
- /* Read Interlace byte */
- tmp = *(pEncodedData + 28);
- /* If image is interlaced then multiple should be 2 */
- if (tmp) {
- thumb_dbg("Interlaced PNG Image.");
- }
+ AcMemset(EncodedDataBuffer, 0, 4096);
- thumb_dbg("type: IMG_CODEC_PNG");
+ SysAssert((const char *)&fileSize);
- if (imgInfo) {
- imgInfo->width = width;
- imgInfo->height = height;
- }
- return IMG_CODEC_PNG;
+ if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- /*********************** BMP *************************/
- else if (AcMemcmp(pEncodedData, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
- /* Parse BMP File and get image width and image height */
- if (fileSize < 26) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[18] | (pEncodedData[19] << 8) |
- (pEncodedData[20] << 16) | (pEncodedData[21] << 24);
- imgInfo->height =
- pEncodedData[22] | (pEncodedData[23] << 8) |
- (pEncodedData[24] << 16) | (pEncodedData[25] << 24);
- }
-
- thumb_dbg("type : IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
-
+ if (fileread < MINIMUM_HEADER_BYTES) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
+ return ret;
}
- /*********************** GIF *************************/
- else if (AcMemcmp(pEncodedData, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
- int length;
- int inputPos = 0;
- int temp;
- int finished;
- int imagecount = 0;
-
- if ((unsigned int)inputPos + 13 > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- if (pEncodedData[0] != 'G' || pEncodedData[1] != 'I'
- || pEncodedData[2] != 'F' || pEncodedData[3] < '0'
- || pEncodedData[3] > '9' || pEncodedData[4] < '0'
- || pEncodedData[4] > '9' || pEncodedData[5] < 'A'
- || pEncodedData[5] > 'z') {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* get Logical width, height */
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[6] | (pEncodedData[7] << 8);
- imgInfo->height =
- pEncodedData[8] | (pEncodedData[9] << 8);
- }
- if ((pEncodedData[10] & 0x80) != 0) /* Global color table */ {
- temp = (pEncodedData[10] & 0x7) + 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- }
+ if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) == 0) {
+ if (fast_mode == FALSE) {
+ unsigned char header_type[JPG_HEADER_TYPE_LENGTH];
+ unsigned char block_size[JPG_BLOCK_SIZE_LENGTH];
+ unsigned char image_size[JPG_IMAGE_SIZE_LENGTH];
- inputPos += 13;
- finished = 0;
+ rewind(hFile);
- /* still gif image (image_cnt = 1) */
- while (!finished) {
- if ((unsigned int)inputPos > fileSize)
- break;
+ unsigned short block_length = EncodedDataBuffer[4] * 256 + EncodedDataBuffer[5];
+ thumb_dbg("block length : %d", block_length);
+ unsigned int i = 4;
- switch (pEncodedData[inputPos++]) {
- case 0x3b: /* End of the GIF dataset */
- finished = 1;
- break;
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length+4) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- case 0x21: /* Extension Block */
- switch (pEncodedData[inputPos++]) {
- case 0xf9: /* Graphic control extension block */
- if (4 != pEncodedData[inputPos++]) { /* data length : fixed 4 bytes */
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- inputPos += 4;
- inputPos++; /* block end */
+ while (i < fileSize) {
+ i += block_length;
+ if (i >= fileSize) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
+ }
- case 0x01: /* Plain Text block */
- case 0xfe: /* Comment Extension block */
- case 0xff: /* Appliation Extension block */
- while ((length = pEncodedData[inputPos++]) > 0) { /* get the data length */
- inputPos += (length);
- if ((unsigned int)inputPos >
- fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return
- IMG_CODEC_UNKNOWN_TYPE;
- }
- }
- break;
+ AcMemset(header_type, 0, JPG_HEADER_TYPE_LENGTH);
+ if (DrmReadFile(hFile, header_type, (ULONG)JPG_HEADER_TYPE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- default:
+ if (header_type[0] != 0xFF) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
}
- break;
-
- case 0x2c: /* Start of an image object. Read the image description. */
-
- if ((unsigned int)inputPos + 9 > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Color Resolution */
- if ((pEncodedData[inputPos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (pEncodedData[inputPos + 8] & 0x7) +
- 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (header_type[1] == 0xC0 || header_type[1] == 0xC2) {
+ AcMemset(image_size, 0, JPG_IMAGE_SIZE_LENGTH);
+ if (DrmReadFile(hFile, image_size, (ULONG)JPG_IMAGE_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- }
-
- inputPos += 9;
- temp = pEncodedData[inputPos++];
- if (temp < 2 || 9 < temp) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- do {
- length = pEncodedData[inputPos++];
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = image_size[5] * 256 + image_size[6];
+ *pHeight = image_size[3] * 256 + image_size[4];
+ break;
+ } else {
+ i += 2;
+ AcMemset(block_size, 0, JPG_BLOCK_SIZE_LENGTH);
+ if (DrmReadFile(hFile, block_size, (ULONG)JPG_BLOCK_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- } while (length);
- if (!imagecount)
- imagecount++;
- else {
- if (imgInfo)
- imgInfo->numberOfFrame = 2;
- return IMG_CODEC_AGIF;
+ block_length = block_size[0] * 256 + block_size[1];
+ thumb_dbg("new block length : %d", block_length);
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length-JPG_BLOCK_SIZE_LENGTH) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
}
- break;
-
- default:
- finished = 0;
- break;
-
- } /* end of switch (pEncodedData[inputPos++]) */
- } /* end of while (pImage->bitmapCount > image_cnt && !finished) */
-
- return IMG_CODEC_GIF;
- }
-
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
-}
-
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- unsigned int fileleft;
- unsigned long fileread;
- unsigned char EncodedDataBuffer[4096];
-
- unsigned int *pNumberOfFrames = NULL;
- unsigned int *pWidth = NULL;
- unsigned int *pHeight = NULL;
- unsigned int *pOrientation = NULL;
-
- if (imgInfo == NULL) {
- pNumberOfFrames = NULL;
- pWidth = NULL;
- pHeight = NULL;
- pOrientation = NULL;
- } else {
- pWidth = &(imgInfo->width);
- pHeight = &(imgInfo->height);
- pOrientation = &(imgInfo->bOrientation);
- pNumberOfFrames = &(imgInfo->numberOfFrame);
-
- *pWidth = 0;
- *pHeight = 0;
- *pOrientation = 0;
- }
-
- AcMemset(EncodedDataBuffer, 0, 4096);
-
- /* Initialize values */
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
-
- SysAssert((const char *)&fileSize);
-
- if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
- }
-
- if (fileread < MINIMUM_HEADER_BYTES) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
+ }
+ thumb_dbg("IMG_CODEC_JPEG");
+ *type = IMG_CODEC_JPEG;
}
/*********************** PNG *************************/
- if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
unsigned char tmp;
if (DrmReadFile(hFile, EncodedDataBuffer, 32, &fileread) ==
FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 32) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Get Image Width */
if (pWidth) {
@@ -448,25 +254,19 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (tmp) {
thumb_dbg("Interlaced PNG Image.");
}
- thumb_dbg("IMG_CODEC_PNG\n");
- return IMG_CODEC_PNG;
+ thumb_dbg("IMG_CODEC_PNG");
+ *type = IMG_CODEC_PNG;
}
/*********************** BMP *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH)
- == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
/* Parse BMP File and get image width and image height */
- if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) ==
- FALSE) {
+ if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 18) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (pWidth == NULL || pHeight == NULL
- || pNumberOfFrames == NULL) {
- return IMG_CODEC_BMP;
+ return ret;
}
if (pWidth) {
*pWidth =
@@ -482,7 +282,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
thumb_dbg("IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
+ *type = IMG_CODEC_BMP;
}
/*********************** GIF *************************/
else if (AcMemcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
@@ -495,17 +295,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (13 > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (DrmReadFile(hFile, &EncodedDataBuffer[8], 5, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 5) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I'
@@ -514,17 +313,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
|| EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A'
|| EncodedDataBuffer[5] > 'z') {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (!(pWidth && pHeight)) {
- return IMG_CODEC_UNKNOWN_TYPE;
- } else {
- *pWidth =
- EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
- *pHeight =
- EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
- }
+ *pWidth = EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
+ *pHeight = EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
thumb_dbg("Logical width : %d, Height : %d", *pWidth, *pHeight);
@@ -534,22 +327,21 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if ((tablelength * sizeof(char)) > sizeof(EncodedDataBuffer)) {
thumb_warn("_ImgGetInfoStreaming :table length is more than buffer length");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (13 + tablelength > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* coverity[ -tainted_data_argument : EncodedDataBuffer ] */
if (DrmReadFile(hFile, EncodedDataBuffer, tablelength, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < tablelength) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
}
@@ -567,7 +359,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
break;
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -579,7 +371,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0x21: /* Extension Block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -587,11 +379,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xf9: /* Graphic control extension block */
if (_CheckBuffer(&ifegstreamctrl, 6) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
- return 0;
+ if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
+ *type = 0;
}
ifegstreamctrl.buffpos += 4;
ifegstreamctrl.buffpos++; /* block end */
@@ -602,24 +394,25 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xff: /* Appliation Extension block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (ifegstreamctrl.buffpos > sizeof(EncodedDataBuffer)) {
thumb_warn("buffer position exceeds buffer max length ");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer)) && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
+ while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer))
+ && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
if (_CheckBuffer(&ifegstreamctrl, length) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Check integer overflow */
if (ifegstreamctrl.buffpos > 0xffffffff - length) {
thumb_err("Prevent integer overflow..");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
ifegstreamctrl.buffpos += (length);
@@ -637,41 +430,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 9) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
#if 1
if (imagecount == 0) {
/* Regard the width/height of the first image block as the size of thumbnails. */
- int img_block_w, img_block_h,
- img_block_left, img_block_top;
- img_block_left =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 1] << 8);
- img_block_top =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 2] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 3] << 8);
-
- img_block_w =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 4] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 5] << 8);
- img_block_h =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 6] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 7] << 8);
- thumb_dbg
- ("Image block width : %d, Height : %d, left:%d, top:%d\n",
- img_block_w, img_block_h,
- img_block_left, img_block_top);
+ int img_block_w, img_block_h;
+
+ img_block_w = EncodedDataBuffer[ifegstreamctrl.buffpos + 4] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 5] << 8);
+ img_block_h = EncodedDataBuffer[ifegstreamctrl.buffpos + 6] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 7] << 8);
+ thumb_dbg ("Image block width : %d, Height : %d, left:%d, top:%d", img_block_w, img_block_h);
*pWidth = img_block_w;
*pHeight = img_block_h;
@@ -679,17 +447,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
#endif
/* Color Resolution */
if ((EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos +
- 8] & 0x7) + 1;
+ temp = (EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x7) + 1;
length = (1 << temp) * 3;
- if (_CheckBuffer
- (&ifegstreamctrl,
- length + 9) == 0) {
- thumb_warn
- ("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (_CheckBuffer(&ifegstreamctrl, length + 9) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return ret;
}
ifegstreamctrl.buffpos += length;
@@ -700,18 +462,18 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
temp = EncodedDataBuffer[ifegstreamctrl.buffpos++];
if (temp < 2 || 9 < temp) {
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
do {
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
length =EncodedDataBuffer[ifegstreamctrl.buffpos++];
@@ -722,13 +484,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
ifegstreamctrl.buffend;
if (DrmSeekFile(ifegstreamctrl.fd, SEEK_CUR, length) == FALSE) {
if (imagecount) {
- if (pNumberOfFrames)
- *pNumberOfFrames
- = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
- return IMG_CODEC_UNKNOWN_TYPE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
ifegstreamctrl.filepos += length;
ifegstreamctrl.buffpos = 0;
@@ -742,10 +502,9 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (!imagecount)
imagecount++;
else {
- if (pNumberOfFrames)
- *pNumberOfFrames = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
break;
@@ -755,102 +514,122 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
}
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
thumb_dbg("IMG_CODEC_GIF");
- return IMG_CODEC_GIF;
+ *type = IMG_CODEC_GIF;
}
+ /*********************** WBMP *************************/
+ else if ((AcMemcmp(EncodedDataBuffer, gIfegWBMPHeader, WBMP_HEADER_LENGTH) == 0)
+ && (strcasecmp(fileExt, "wbmp") == 0)) {
+ /* Parse BMP File and get image width and image height */
+/* if (DrmReadFile(hFile, &EncodedDataBuffer[2], 2, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
+ if (fileread < 2) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in WBMP");
+ return ret;
+ }*/
+ if (pWidth) {
+ *pWidth = EncodedDataBuffer[2];
+ }
+ if (pHeight) {
+ *pHeight = EncodedDataBuffer[3];
+ }
+ thumb_dbg("WBMP w: %d, h: %d", *pWidth, *pHeight);
- /*********************** Jpeg *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH)
- == 0) {
-#if 1
- /*
- IFEGSTREAMCTRL ifegstreamctrl;
- if( DrmReadFile(hFile, &EncodedDataBuffer[8], FILE_READ_SIZE-8, &fileread) == FALSE )
- {
- thumb_err( "DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
- }
-
- ifegstreamctrl.fd = hFile;
- ifegstreamctrl.filesize = fileSize;
- ifegstreamctrl.filepos = fileread+8;
- ifegstreamctrl.buffpos = 2;
- ifegstreamctrl.buffend = 8+fileread;
- ifegstreamctrl.buffer = EncodedDataBuffer;
- */
-
-#else /* Get w / h from jpeg header */
-
-#ifdef _PERFORMANCE_CHECK_
- long start = 0L, end = 0L;
- start = mediainfo_get_debug_time();
-#endif
- unsigned char *img_buf = NULL;
- img_buf = (unsigned char *)malloc(fileSize);
+ thumb_dbg("IMG_CODEC_WBMP");
+ *type = IMG_CODEC_WBMP;
+ }
+ return ret;
+}
- rewind(hFile);
- if (DrmReadFile(hFile, img_buf, fileSize, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
+static int _ImgGetFileExt(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
- return IMG_CODEC_NONE;
+ for (i = (int)strlen(file_path); i >= 0; i--) {
+ if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
+ strncpy(file_ext, &file_path[i + 1], max_len);
+ return 0;
}
- unsigned short block_length = img_buf[4] * 256 + img_buf[5];
- thumb_dbg("block length : %d", block_length);
- int i = 4;
+ /* meet the dir. no ext */
+ if (file_path[i] == '/') {
+ return -1;
+ }
+ }
- while (i < fileSize) {
- i += block_length;
- if (i >= fileSize) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+ return -1;
+}
- if (img_buf[i] != 0xFF) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+int ImgGetImageInfo(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
- if (img_buf[i + 1] == 0xC0) {
- *pWidth = img_buf[i + 5] * 256 + img_buf[i + 6];
- *pHeight =
- img_buf[i + 7] * 256 + img_buf[i + 8];
- break;
- } else {
- i += 2;
- block_length =
- img_buf[i] * 256 + img_buf[i + 1];
- thumb_dbg("new block length : %d",
- block_length);
- }
- }
- thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
-
- if (img_buf)
- free(img_buf);
-
-#if defined(_PERFORMANCE_CHECK_) && defined(_USE_LOG_FILE_)
- end = mediainfo_get_debug_time();
- double get_size =
- ((double)(end - start) / (double)CLOCKS_PER_SEC);
- thumb_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_init_file_debug();
- mediainfo_file_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_close_file_debug();
-#endif
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
-#endif /* End of Get w / h from jpeg header */
+ DrmGetFileAttributes(filePath, &fileAttrib);
- thumb_dbg("IMG_CODEC_JPEG");
- return IMG_CODEC_JPEG;
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
}
- return IMG_CODEC_UNKNOWN_TYPE;
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, FALSE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
+}
+
+int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
+
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ DrmGetFileAttributes(filePath, &fileAttrib);
+
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
+ };
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, TRUE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
}