コード例 #1
0
ファイル: jpg.c プロジェクト: AzagraMac/PS2_SDK
void displayjpeg(jpgData *jpg) {
	GSTEXTURE tex;
	u8 *data;
	int i;

	data = malloc(jpg->width * jpg->height * (jpg->bpp/8));
	jpgReadImage(jpg, data);
	tex.Width =  jpg->width;
	tex.Height = jpg->height;
	tex.PSM = GS_PSM_CT24;
	tex.Vram = 0;
	tex.Mem = (u32*) data;
	gsKit_texture_upload(gsGlobal, &tex);
	jpgClose(jpg);
	free(data);

	for (i=0; i<120; i++) {
		gsKit_vsync();
	}
}
コード例 #2
0
ファイル: GUI_M_MyPictures.c プロジェクト: smiley22/myPS2
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;
}