⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Project Name JPEG DRIVER IN WINCE
 * Copyright  2007 Samsung Electronics Co, Ltd. All Rights Reserved. 
 *
 * This software is the confidential and proprietary information
 * of Samsung Electronics  ("Confidential Information").   
 * you shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung Electronics 
 *
 * This file implements JPEG Test Application.
 *
 * @name JPEG Test Application Module (jpg_app.c)
 * @author Jiyoung Shin (idon.shin@samsung.com)
 * @date 28-05-07
 */
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "JPGApi.h"
#include "SVEDriverAPI.h"
 

#define FPS			1
#define DEBUG		0	


#define TEST_DECODE					1  // enable decoder test
#define TEST_DECODE_OUTPUT_YUV422	1  // output file format is YUV422(non-interleaved)
#define TEST_DECODE_OUTPUT_YCBYCR	0  // output file format is YCBYCR(interleaved)
#define TEST_DECODE_OUTPUT_RGB16	0  // output file format is RGB16
#define TEST_DECODE_OUTPUT_LCD		0  // output will display to LCD during DISPLAY_TIME

#define TEST_ENCODE					0 // enable encoder test
#define TEST_ENCODE_WITH_EXIF		1 // encoded jpg file will include Exif info
#define TEST_ENCODE_WITH_THUMBNAIL	0 // enable thumbnail encoding

#if (TEST_DECODE == 1)
	#define CTRL_FILE_NAME	"fname_dec.txt"
#elif (TEST_ENCODE == 1)
	#define CTRL_FILE_NAME	"fname_enc.txt"
#endif


#define PHY_ADDR_FRAME_BUFFER 0x57400000
#define LCD_X		800
#define LCD_Y		480
#define DISPLAY_TIME	5//sec

#define R_RGB565(x)		(unsigned char) (((x) >> 8) & 0xF8)
#define G_RGB565(x)		(unsigned char) (((x) >> 3) & 0xFC)
#define B_RGB565(x)		(unsigned char) ((x) << 3)

void TestDecoder();
void TestEncoder();
void DecodeFileOutYCBYCR(char *OutBuf, UINT32 streamSize, char *filename);
void DecodeFileOutYUV422(char *OutBuf, UINT32 streamSize, char *filename);
void makeExifParam(ExifFileInfo *exifFileInfo);
void DisplayJPEG (int srcAddr, 
				  INT32 srcwidth, INT32 srcheight, 
				  INT32 dstwidth, INT32 dstheight,
				  int displayTime);
BOOL ConvertYCBYCRToRGB(int inBuf, INT32 srcwidth, INT32 srcheight, 
						unsigned long srcType,
						int outBuf, INT32 dstwidth, INT32 dstheight,
						unsigned long dstType);
void DecodeFileOutRGB16ToPPM(unsigned char *p_img, int wd, int hi, char *filename);
void printD(char* fmt, ...);

/*
*******************************************************************************
Name            : main
Description     : Main function
Parameter       :
Return Value    : SUCCESS or FAILURE
*******************************************************************************
*/

int WINAPI WinMain(HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
#if (TEST_DECODE == 1)
	TestDecoder();
#elif (TEST_ENCODE == 1)
	TestEncoder();
#endif

	return 1;
}

/*
*******************************************************************************
Name            : TestDecoder
Description     : To test Decoder
Parameter       : imageType - JPG_YCBYCR or JPG_RGB16
Return Value    : void
*******************************************************************************
*/
void TestDecoder()
{
	char *InBuf = NULL;
	char *OutBuf = NULL;
	char *OutPhyBuf = NULL;
	char *OutRGBBuf = NULL;
	char *OutRGBPhyBuf = NULL;
	FILE *fp;
	FILE *CTRfp;
	UINT32 fileSize;
	UINT32 streamSize;
	void *handle;
	INT32 width, height, samplemode;
	JPEG_ERRORTYPE ret;
	char outFilename[128];
	char inFilename[128];
	BOOL result = TRUE;
#if (FPS == 1)
	INT32	decodeTime;
#endif
	DWORD	startTime;


	printf("------------------------Decoder Test Start ---------------------\n");

	//////////////////////////////////////////////////////////////
	// 0. 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                                           //
		//////////////////////////////////////////////////////////////
		#if (FPS == 1)
			decodeTime = GetTickCount();
		#endif
		handle = SsbSipJPEGDecodeInit();
		#if (FPS == 1)		
			decodeTime = GetTickCount() - decodeTime;
			printf( "Initialization Time : %d \n", decodeTime);
		#endif
		if(handle == NULL){
			printf("Decoder Init failed\n");
			break;
		}

		//////////////////////////////////////////////////////////////
		// 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                                     //
		//////////////////////////////////////////////////////////////
		#if (FPS == 1)
			decodeTime = GetTickCount();
		#endif

		ret = SsbSipJPEGDecodeExe(handle);

		#if (FPS == 1)		
			decodeTime = GetTickCount() - decodeTime;
			printf( "decodeTime : %d \n", decodeTime);
		#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);

		printf("width : %d height : %d samplemode : %d\n\n", width, height, samplemode);

		//////////////////////////////////////////////////////////////
		// 8. wirte output file                                     //
		//////////////////////////////////////////////////////////////

#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
#elif (TEST_DECODE_OUTPUT_RGB16 == 1)							//RGB16
		OutPhyBuf = SsbSipJPEGGetDecodeOutPhyBuf(handle);
		OutRGBPhyBuf = SsbSipJPEGGetRGBPhyBuf(handle, LCD_X, LCD_Y);
		if(ConvertYCBYCRToRGB((int)OutPhyBuf, width, height, 
							  POST_SRC_YUV422_CRYCBY,
							  (int)OutRGBPhyBuf, LCD_X, LCD_Y,
							  POST_DST_RGB16) == FALSE){
			printf("ConvertYCBYCRToRGB error\n");
			result = FALSE;
			break;
		}
		OutRGBBuf = SsbSipJPEGGetRGBBuf(handle, LCD_X, LCD_Y);
		DecodeFileOutRGB16ToPPM(OutRGBBuf, LCD_X, LCD_Y, outFilename); 
#elif(TEST_DECODE_OUTPUT_LCD == 1)
		OutPhyBuf = SsbSipJPEGGetDecodeOutPhyBuf(handle);
		OutRGBPhyBuf = SsbSipJPEGGetRGBPhyBuf(handle, LCD_X, LCD_Y);
		startTime = GetTickCount();
		if(ConvertYCBYCRToRGB((int)OutPhyBuf, width, height, 
							  POST_SRC_YUV422_CRYCBY,
							  (int)OutRGBPhyBuf, LCD_X, LCD_Y,
							  POST_DST_RGB16) == FALSE){
			printf("ConvertYCBYCRToRGB error\n");
			result = FALSE;
			break;
		}
		printf("converting time : %d\n\n", GetTickCount() - startTime);
		printf("\n\n This image will be disappeared after %d seconds......\n\n", DISPLAY_TIME);
		DisplayJPEG((int)OutRGBPhyBuf, LCD_X, LCD_Y, LCD_X, LCD_Y, DISPLAY_TIME);
#endif

		//////////////////////////////////////////////////////////////
		// 9. finalize handle                                      //
		//////////////////////////////////////////////////////////////
		SsbSipJPEGDecodeDeInit(handle);
		Sleep(5);
	}while(1);

	if(result == FALSE){
		SsbSipJPEGDecodeDeInit(handle);
	}

	fclose(CTRfp);
	printf("------------------------Decoder Test Done ---------------------\n");
}
/*
*******************************************************************************
Name            : TestEncoder
Description     : To test Encoder
Parameter       : imageType - JPG_YCBYCR or JPG_RGB16
Return Value    : void
*******************************************************************************
*/
void TestEncoder()
{
	char *InBuf = NULL;
	char *InThumbBuf = NULL;
	char *OutBuf = NULL;
	FILE *fp;
	FILE *CTRfp;
	JPEG_ERRORTYPE ret;
	UINT32 fileSize;
	UINT32 frameSize;
	void *handle;
	ExifFileInfo *ExifInfo;
	char outFilename[128];
	char inFilename[128];
	char widthstr[8], heightstr[8];
	INT32 width, height;
	BOOL result = TRUE;
#if (FPS == 1)
	INT32	encodeTime;
#endif

	printf("------------------------Encoder Test start---------------------\n");
	//////////////////////////////////////////////////////////////
	// 0. 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));
		memset(widthstr, 0x00, sizeof(widthstr));
		memset(heightstr, 0x00, sizeof(heightstr));

		fscanf(CTRfp, "%s", inFilename);
		if(inFilename[0] == '#'){
			printf("------------------------Encoder Test Done---------------------\n");
			fclose(CTRfp);
			return;
		}

		fscanf(CTRfp, "%s", outFilename);
		fscanf(CTRfp, "%s", widthstr);
		fscanf(CTRfp, "%s", heightstr);
		width = (INT32)atoi(widthstr);
		height = (INT32)atoi(heightstr);

		if(inFilename == NULL || outFilename == NULL){
			printf("read file error\n");
			printf("------------------------Encoder Test Done---------------------\n");
			fclose(CTRfp);
			return;
		}

		printf("inFilename : %s \noutFilename : %s width : %d height : %d\n", 
				inFilename, outFilename, width, height);
		//////////////////////////////////////////////////////////////
		// 1. handle Init                                           //
		//////////////////////////////////////////////////////////////
		#if (FPS == 1)
			encodeTime = GetTickCount();
		#endif
		handle = SsbSipJPEGEncodeInit();
		#if (FPS == 1)		
			encodeTime = GetTickCount() - encodeTime;
			printf( "Initialization Time : %d \n", encodeTime);
		#endif
		if(handle == NULL)
			break;

		//////////////////////////////////////////////////////////////
		// 2. set decode config.                                    //
		//////////////////////////////////////////////////////////////
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_SAMPING_MODE, JPG_422)) != JPEG_OK){
			result = FALSE;
			break;
		}
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_WIDTH, width)) != JPEG_OK){
			result = FALSE;
			break;
		}
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_HEIGHT, height)) != JPEG_OK){
			result = FALSE;
			break;
		}
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_QUALITY, JPG_QUALITY_LEVEL_2)) != JPEG_OK){
			result = FALSE;
			break;
		}
#if (TEST_ENCODE_WITH_THUMBNAIL == 1)
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_THUMBNAIL, TRUE)) != JPEG_OK){
			result = FALSE;
			break;
		}
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_WIDTH, 160)) != JPEG_OK){
			result = FALSE;
			break;
		}
		if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_HEIGHT, 120)) != JPEG_OK){
			result = FALSE;
			break;
		}
#endif

		//////////////////////////////////////////////////////////////
		// 3. open JPEG file to decode                              //
		//////////////////////////////////////////////////////////////
		fp = fopen(inFilename, "rb");
		if(fp == NULL){
			printf("file open error : %s\n", inFilename);
			result = FALSE;
			break;
		}
		fseek(fp, 0, SEEK_END);
		fileSize = ftell(fp);
		fseek(fp, 0, SEEK_SET);

		//////////////////////////////////////////////////////////////
		// 4. get Input buffer address                              //
		//////////////////////////////////////////////////////////////
		printD("filesize : %d\n", fileSize);
		InBuf = SsbSipJPEGGetEncodeInBuf(handle, fileSize);
		if(InBuf == NULL){
			result = FALSE;
			break;
		}
		printD("inBuf : 0x%x\n", InBuf);

		//////////////////////////////////////////////////////////////
		// 5. put YUV stream to Input buffer                        //
		//////////////////////////////////////////////////////////////
		fread(InBuf, 1, fileSize, fp);
		fclose(fp);

	
		//////////////////////////////////////////////////////////////
		// 6. Make Exif info parameters                             //
		//////////////////////////////////////////////////////////////
		ExifInfo = (ExifFileInfo *)malloc(sizeof(ExifFileInfo));
		memset(ExifInfo, 0x00, sizeof(ExifFileInfo));
		makeExifParam(ExifInfo);

		//////////////////////////////////////////////////////////////
		// 7. Encode YUV stream                                     //
		//////////////////////////////////////////////////////////////
		#if (FPS == 1)
			encodeTime = GetTickCount();
		#endif

		#if (TEST_ENCODE_WITH_EXIF == 1)
		ret = SsbSipJPEGEncodeExe(handle, ExifInfo);    //with Exif
		#else
		ret = SsbSipJPEGEncodeExe(handle, NULL); 		//No Exif
		#endif

		#if (FPS == 1)		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -