If other devs want to use the JPEG decoder, here is what I've done. They'll know how to use it:
Code:
Add the library in the Makefile (PPU_LDLIBS)
-ljpgdec_stub
...
// Load the JPEG decoder module first (somewhere in your app)
cellSysmoduleLoadModule(CELL_SYSMODULE_JPGDEC);
...
// data = memory buffer to store decoded data
// name = JPEG full file path
int load_jpg_texture(u8 *data, char *name)
{
int ret, ok=-1;
png_w=0; png_h=0;
CellJpgDecMainHandle mHandle;
CellJpgDecSubHandle sHandle;
CellJpgDecInParam inParam;
CellJpgDecOutParam outParam;
CellJpgDecSrc src;
CellJpgDecOpnInfo opnInfo;
CellJpgDecInfo info;
CellJpgDecDataOutInfo dOutInfo;
CellJpgDecDataCtrlParam dCtrlParam;
CellJpgDecThreadInParam InParam;
CellJpgDecThreadOutParam OutParam;
CtrlMallocArg MallocArg;
CtrlFreeArg FreeArg;
float downScale;
bool unsupportFlag;
MallocArg.mallocCallCounts = 0;
FreeArg.freeCallCounts = 0;
InParam.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_DISABLE;
InParam.ppuThreadPriority = 512;
InParam.spuThreadPriority = 200;
InParam.cbCtrlMallocFunc = png_malloc;
InParam.cbCtrlMallocArg = &MallocArg;
InParam.cbCtrlFreeFunc = png_free;
InParam.cbCtrlFreeArg = &FreeArg;
ret = cellJpgDecCreate(&mHandle, &InParam, &OutParam);
if(ret == CELL_OK){
src.srcSelect = CELL_JPGDEC_FILE;
src.fileName = name;
src.fileOffset = 0;
src.fileSize = 0;
src.streamPtr = NULL;
src.streamSize = 0;
src.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_DISABLE;
unsupportFlag = false;
ret = cellJpgDecOpen(mHandle, &sHandle, &src, &opnInfo);
if(ret == CELL_OK){
ret = cellJpgDecReadHeader(mHandle, sHandle, &info);
if(info.jpegColorSpace == CELL_JPG_UNKNOWN){
unsupportFlag = true;
}
} //decoder open
if(ret == CELL_OK){
if(info.imageWidth>1920 || info.imageHeight>1080){
if( ((float)info.imageWidth / 1920) > ((float)info.imageHeight / 1080 ) ){
downScale = (float)info.imageWidth / 1920;
}else{
downScale = (float)info.imageHeight / 1080;
}
}
else
downScale=1.f;
if( downScale <= 1.f ){
inParam.downScale = 1;
}else if( downScale <= 2.f ){
inParam.downScale = 2;
}else if( downScale <= 4.f ){
inParam.downScale = 4;
}else{
inParam.downScale = 8;
}
inParam.commandPtr = NULL;
inParam.method = CELL_JPGDEC_FAST;
inParam.outputMode = CELL_JPGDEC_TOP_TO_BOTTOM;
inParam.outputColorSpace = CELL_JPG_RGBA;
inParam.outputColorAlpha = 0xff;
ret = cellJpgDecSetParameter(mHandle, sHandle, &inParam, &outParam);
}
if(ret == CELL_OK){
dCtrlParam.outputBytesPerLine = 1920 * 4;
memset(data, 0, (1920 * 1080 * 4));
ret = cellJpgDecDecodeData(mHandle, sHandle, data, &dCtrlParam, &dOutInfo);
if((ret == CELL_OK) && (dOutInfo.status == CELL_JPGDEC_DEC_STATUS_FINISH))
{
png_w= outParam.outputWidth;
png_h= outParam.outputHeight;
ok=0;
}
}
ret = cellJpgDecClose(mHandle, sHandle);
ret = cellJpgDecDestroy(mHandle);
} //decoder create
return ret;
}
...
// Unload the module when you're done (before your app exits to xmb)
cellSysmoduleUnloadModule(CELL_SYSMODULE_JPGDEC);