/*********************************************************************** * create png decoder ***********************************************************************/ static int32_t create_decoder(png_dec_info *dec_ctx) { uint32_t ret = 0; CellPngDecThreadInParam in; CellPngDecThreadOutParam out; // set params dec_ctx->cb_arg.mallocCallCounts = 0; dec_ctx->cb_arg.freeCallCounts = 0; in.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_DISABLE; // ppu only in.ppuThreadPriority = 512; in.spuThreadPriority = 200; in.cbCtrlMallocFunc = cb_malloc; in.cbCtrlMallocArg = &dec_ctx->cb_arg; in.cbCtrlFreeFunc = cb_free; in.cbCtrlFreeArg = &dec_ctx->cb_arg; // create png decoder ret = PngDecCreate(&dec_ctx->main_h, &in, &out); return ret; }
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; }