Esempio n. 1
0
/***********************************************************************
* decode png stream
***********************************************************************/
static int32_t decode_png_stream(png_dec_info	*dec_ctx, void *buf)
{
	uint32_t ret = 0;
	uint8_t *out;
	CellPngDecDataCtrlParam  param;
	CellPngDecDataOutInfo    info; 
	
	
	param.outputBytesPerLine = png_w * 4;
	out = (void*)buf;
	
	memset(out, 0, (png_w * png_h * 4));
	
	// decode png...
	ret = PngDecDecodeData(dec_ctx->main_h, dec_ctx->sub_h, out, &param, &info);
	
	return ret;
}
Esempio 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;
}