void TestDecoder()
{
char *InBuf = NULL;
char *OutBuf = NULL;
FILE *fp;
FILE *CTRfp;
UINT32 fileSize;
long streamSize;
int handle;
INT32 width, height, samplemode;
JPEG_ERRORTYPE ret;
char outFilename[128];
char inFilename[128];
BOOL result = TRUE;
#ifdef FPS
struct timeval start;
struct timeval stop;
unsigned int time = 0;
#endif
printf("------------------------Decoder Test Start ---------------------\n");
//
// Get input/output file name //
//
CTRfp = fopen(CTRL_FILE_NAME, "rb");
if(CTRfp == NULL){
printf("file open error : %s\n", CTRL_FILE_NAME);
return;
}
do{
memset(outFilename, 0x00, sizeof(outFilename));
memset(inFilename, 0x00, sizeof(inFilename));
fscanf(CTRfp, "%s", inFilename);
if(inFilename[0] == '#'){
printf("------------------------Decoder Test Done ---------------------\n");
fclose(CTRfp);
return;
}
fscanf(CTRfp, "%s", outFilename);
if(inFilename == NULL || outFilename == NULL){
printf("read file error\n");
printf("------------------------Decoder Test Done ---------------------\n");
fclose(CTRfp);
return;
}
printf("inFilename : %s \noutFilename : %s\n", inFilename, outFilename);
//
// 1. handle Init //
//
#ifdef FPS
gettimeofday(&start, NULL);
#endif
handle = SsbSipJPEGDecodeInit();
if(handle < 0)
break;
#ifdef FPS
gettimeofday(&stop, NULL);
time += measureTime(&start, &stop);
#endif
//
// 2. open JPEG file to decode //
//
fp = fopen(inFilename, "rb");
if(fp == NULL){
result = FALSE;
printf("file open error : %s\n", inFilename);
break;
}
fseek(fp, 0, SEEK_END);
fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
printD("filesize : %d\n", fileSize);
//
// 3. get Input buffer address //
//
InBuf = SsbSipJPEGGetDecodeInBuf(handle, fileSize);
if(InBuf == NULL){
printf("Input buffer is NULL\n");
result = FALSE;
break;
}
printD("inBuf : 0x%x\n", InBuf);
//
// 4. put JPEG frame to Input buffer //
//
fread(InBuf, 1, fileSize, fp);
fclose(fp);
//
// 5. Decode JPEG frame //
//
#ifdef FPS
gettimeofday(&start, NULL);
#endif
ret = SsbSipJPEGDecodeExe(handle);
#ifdef FPS
gettimeofday(&stop, NULL);
time += measureTime(&start, &stop);
printf("[JPEG Decoding Performance] Elapsed time : %u\n", time);
time = 0;
#endif
if(ret != JPEG_OK){
printf("Decoding failed\n");
result = FALSE;
break;
}
//
// 6. get Output buffer address //
//
OutBuf = SsbSipJPEGGetDecodeOutBuf(handle, &streamSize);
if(OutBuf == NULL){
printf("Output buffer is NULL\n");
result = FALSE;
break;
}
printD("OutBuf : 0x%x streamsize : %d\n", OutBuf, streamSize);
//
// 7. get decode config. //
//
SsbSipJPEGGetConfig(JPEG_GET_DECODE_WIDTH, &width);
SsbSipJPEGGetConfig(JPEG_GET_DECODE_HEIGHT, &height);
SsbSipJPEGGetConfig(JPEG_GET_SAMPING_MODE, &samplemode);
printD("width : %d height : %d samplemode : %d\n", width, height, samplemode);
//
// 8. wirte output file & dispaly to LCD //
//
#if (TEST_DECODE_OUTPUT_YCBYCR == 1)
DecodeFileOutYCBYCR(OutBuf, streamSize, outFilename); // YCBYCR interleaved
#elif (TEST_DECODE_OUTPUT_YUV422 == 1)
DecodeFileOutYUV422(OutBuf, streamSize, outFilename); // yuv422 non-interleaved
#endif
//
// 9. finalize handle //
//
SsbSipJPEGDecodeDeInit(handle);
sleep(1);
}while(1);
if(result == FALSE){
SsbSipJPEGDecodeDeInit(handle);
}
fclose(CTRfp);
printf("------------------------Decoder Test Done ---------------------\n");
}