Exemplo n.º 1
0
/***********************************************************************
* set decode parameter
***********************************************************************/
static int32_t set_dec_param(png_dec_info	*dec_ctx)
{
	uint32_t ret = 0;
	CellPngDecInfo      info;
	CellPngDecInParam   in;
	CellPngDecOutParam  out;
	
	// read png header 
	PngDecReadHeader(dec_ctx->main_h, dec_ctx->sub_h, &info);
	
	png_w = info.imageWidth;
	png_h = info.imageHeight;
	
	
		
	/*
	dbg_printf("\nimageWidth:       %d\n"
	           "imageHeight:      %d\n"
	           "numComponents:    0x%08X\n"
	           "colorSpace:       0x%08X\n"
	           "bitDepth:         0x%08X\n"
	           "interlaceMethod:  0x%08X\n"
	           "chunkInformation: 0x%08X\n\n",
	           info.imageWidth, info.imageHeight, info.numComponents,
	           info.colorSpace, info.bitDepth, info.interlaceMethod, info.chunkInformation);
*/


	
	// set decoder parameter
	in.commandPtr		    = NULL;
	in.outputMode		    = CELL_PNGDEC_TOP_TO_BOTTOM;
	in.outputColorSpace	= CELL_PNGDEC_ARGB;        // ps3 framebuffer is ARGB
	in.outputBitDepth	  = 8;
	in.outputPackFlag	  = CELL_PNGDEC_1BYTE_PER_1PIXEL;
	 
	if((info.colorSpace == CELL_PNGDEC_GRAYSCALE_ALPHA) ||
	   (info.colorSpace == CELL_PNGDEC_RGBA) ||
	   (info.chunkInformation & 0x10))
	{
		in.outputAlphaSelect = CELL_PNGDEC_STREAM_ALPHA;
	}
	else
	{
		in.outputAlphaSelect = CELL_PNGDEC_FIX_ALPHA;
	}
	in.outputColorAlpha = 0xFF;
	
	ret = PngDecSetParameter(dec_ctx->main_h, dec_ctx->sub_h, &in, &out);
	
	return ret;
}
Exemplo n.º 2
0
int LoadPNG(PngDatas *png, char *filename)
{
	int ret=-1;
	
	int mHandle;
	int sHandle;

	PngDecThreadInParam InThdParam;
	PngDecThreadOutParam OutThdParam;

	uint64_t build_malloc, build_free; // used to create the fake 32 bits addrs .opd for functions png_malloc() and png_free()

	PngDecInParam inParam;
	PngDecOutParam outParam;
	
	PngDecSrc src; 
	uint32_t space_allocated;

	PngDecInfo DecInfo;
	
	uint64_t bytes_per_line;
	PngDecDataInfo DecDataInfo;

	InThdParam.enable   = 0;
	InThdParam.ppu_prio = 512;
	InThdParam.spu_prio = 200;
	InThdParam.addr_malloc_func  = build32_func_addr(png_malloc, &build_malloc); // (see sysmodule.h)
	InThdParam.addr_malloc_arg   = 0; // no args: if you want one uses get32_addr() to get the 32 bit address (see sysmodule.h)
	InThdParam.addr_free_func    = build32_func_addr(png_free, &build_free);     // (see sysmodule.h)
	InThdParam.addr_free_arg    =  0; // no args  if you want one uses get32_addr() to get the 32 bit address (see sysmodule.h)


	ret= PngDecCreate(&mHandle, &InThdParam, &OutThdParam);

	png->bmp_out= NULL;

	if(ret == 0) {
		
		memset(&src, 0, sizeof(PngDecSrc));
			
		if(filename) {
			src.stream_select = PNGDEC_FILE;
			src.addr_file_name  = get32_addr(filename);
		} else {
			src.stream_select = PNGDEC_BUFFER;
			src.addr_stream_ptr  = get32_addr((void *) png->png_in);
			src.stream_size    = png->png_size;
		}

		src.enable  = PNGDEC_DISABLE;
			
		ret= PngDecOpen(mHandle, &sHandle, &src, &space_allocated);
			
		if(ret == 0) {
			
			ret = PngDecReadHeader(mHandle, sHandle, &DecInfo);
				
			if(ret == 0) {	
				
				inParam.addr_cmd_ptr      = 0;
				inParam.mode         = PNGDEC_TOP_TO_BOTTOM;
				inParam.color_space  = PNGDEC_ARGB;
				inParam.bit_depth    = 8;
				inParam.pack_flag    = 1;
				
				if((DecInfo.color_space == PNGDEC_GRAYSCALE_ALPHA) || (DecInfo.color_space == PNGDEC_RGBA) || (DecInfo.chunk_info & 0x10))
					inParam.alpha_select = 0;
				else
					inParam.alpha_select = 1;
				
				inParam.color_alpha  = 0xff;

				ret = PngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
				}
				
			if(ret == 0) {
					png->wpitch= outParam.width* 4;
					bytes_per_line = (uint64_t)  png->wpitch;

					png->bmp_out= malloc(png->wpitch *  outParam.height);

					if(!png->bmp_out) {

						ret=-1; // out of memory

					} else {

						memset(png->bmp_out, 0, png->wpitch *  outParam.height);
						
						ret = PngDecDecodeData(mHandle, sHandle, png->bmp_out, &bytes_per_line, &DecDataInfo);

						if((ret == 0) && (DecDataInfo.status == 0)){

							png->width  = outParam.width;
							png->height = outParam.height;
							
							ret=0; // ok :)

							}
					}
				}
				
			PngDecClose(mHandle, sHandle);
			}

			if(ret && png->bmp_out) {
				
				free(png->bmp_out); png->bmp_out= NULL;	

			}

			PngDecDestroy(mHandle);
			
		}

return ret;
}