예제 #1
0
파일: jpg.c 프로젝트: AzagraMac/PS2_SDK
int main() {
	jpgData *jpg;

	SifInitRpc(0);
    
    printf("start\n");

	dmaKit_init(D_CTRL_RELE_ON, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
		    D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

	// Initialize the DMAC
	dmaKit_chan_init(DMA_CHANNEL_GIF);

	gsGlobal = gsKit_init_global(GS_MODE_NTSC);
	gsGlobal->PSM = GS_PSM_CT24;
	gsKit_init_screen(gsGlobal);


	printf("display raw jpeg\n");
	jpg = jpgOpenRAW(jpegtest, sizeof(jpegtest));
	if (jpg == NULL) {
		printf("error opening raw jpeg\n");
	} else {
		displayjpeg(jpg);
	}

	printf("display cdrom0:\\TEST.JPG;1\n");
	jpg = jpgOpen("cdrom0:\\TEST.JPG;1");
	if (jpg == NULL) {
		printf("error opening cdrom0:\\TEST.JPG;1\n");
	} else {
		displayjpeg(jpg);
	}

	printf("display host0:testorig.jpg\n");
	jpg = jpgOpen("host0:testorig.jpg");
	if (jpg == NULL) {
		printf("error opening host0:testorig.jpg\n");
	} else {
		displayjpeg(jpg);
	}

	printf("create screenshot file host0:screen.jpg\n");
	//ps2_screenshot_jpg("host0:screen.jpg", 0, 640, 480, GS_PSM_CT32);
    jpgScreenshot("host0:screen.jpg", gsGlobal->CurrentPointer,
                             gsGlobal->Width, gsGlobal->Height, gsGlobal->PSM);

	return 0;
}
예제 #2
0
int CreateThumbnail( const fileInfo_t *pFile, const char *pDir, GSTEXTURE **pTexture )
{
	char 		*pFilename;
	u8 			*pRaw;
	FHANDLE		fh;
	jpgData		*pJpg;
	u8			*pImgData;
	int			nWidth, nHeight;
	float		fRatio;
	u8			*pResData;
	int			nRet, nSize;

	if( pFile->flags & FLAG_DIRECTORY )
	{
		if( pTexture )
			*pTexture = pDirImage->gsTexture;
		
		return 1;
	}

	if( TbnCacheLoad( pFile, pDir, pTexture ) )
		return 1;
	
	pFilename = (char*) malloc( strlen(pDir) + strlen(pFile->name) + 1 );
	if( !pFilename )
		return 0;
	
	strcpy( pFilename, pDir );
	strcat( pFilename, pFile->name );

	fh = FileOpen( pFilename, O_RDONLY );
	if( fh.fh < 0 )
	{
		free(pFilename);
		return 0;
	}

	nSize = FileSeek( fh, 0, SEEK_END );
	FileSeek( fh, 0, SEEK_SET );

	if( !nSize )
	{
		free(pFilename);
		return 0;
	}

	if( (pRaw = (u8*) malloc( nSize )) == NULL )
		return 0;


	FileRead( fh, pRaw, nSize );
	FileClose( fh );

	if( (pJpg = jpgOpenRAW( pRaw, nSize, JPG_WIDTH_FIX )) == NULL )
	{
		free(pFilename);
		free(pRaw);
		return 0;
	}

	if( pJpg->bpp != 24 )
	{
		jpgClose(pJpg);
		free(pFilename);
		free(pRaw);
		return 0;
	}

	pImgData = (u8*) malloc( ((3 * pJpg->width + 3) & ~3) * pJpg->height );
	if( !pImgData )
	{
		jpgClose(pJpg);
		free(pFilename);
		free(pRaw);
		return 0;
	}

	if( -1 == jpgReadImage( pJpg, pImgData ) )
	{
		jpgClose(pJpg);
		free(pFilename);
		free(pRaw);
		free(pImgData);
		return 0;
	}

	// resize dimensions
	if( pJpg->width > pJpg->height )
	{
		fRatio	= (float) pJpg->height / pJpg->width;
		nWidth 	= 64;
		nHeight	= (int) (nWidth * fRatio);

		// make sure Height is even
		if( nHeight % 2 )
			nHeight++;
	} 
	else
	{
		fRatio	= (float) pJpg->width / pJpg->height;
		nHeight	= 64;
		nWidth	= (int) (nHeight * fRatio);

		// make sure width is a multiple of 4 so
		// ScaleBitmap will always work correctly.
		nWidth -= (nWidth % 4);
	}

	nRet = ScaleBitmap( pImgData, pJpg->width, pJpg->height, &pResData, nWidth, nHeight );
	if( 0 == nRet )
	{
		jpgClose(pJpg);
		free(pFilename);
		free(pRaw);
		free(pImgData);
		return 0;
	}

	TbnCacheSave( pFile, pDir, nWidth, nHeight, pResData );

	if( pTexture )
		*pTexture = gsLib_texture_raw( nWidth, nHeight, GS_PSM_CT24, pResData, GS_CLUT_NONE,
									   NULL );

	jpgClose(pJpg);
	free(pRaw);
	free(pImgData);
	free( pFilename );

	if( pTexture && *pTexture == NULL )
		return 0;

	return 1;
}