1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

WIP (cellPngDec refactoring)

This commit is contained in:
Nekotekina 2014-09-08 04:54:17 +04:00
parent e65676ffa9
commit 470afd78d5
9 changed files with 1081 additions and 215 deletions

View File

@ -438,9 +438,9 @@ public:
}
}
template<typename T1> be_t operator & (const be_t<T1>& right) const { const T res; res = ToBE() & right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator | (const be_t<T1>& right) const { const T res; res = ToBE() | right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator ^ (const be_t<T1>& right) const { const T res; res = ToBE() ^ right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator & (const be_t<T1>& right) const { const T res = ToBE() & right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator | (const be_t<T1>& right) const { const T res = ToBE() | right.ToBE(); return (be_t&)res; }
template<typename T1> be_t operator ^ (const be_t<T1>& right) const { const T res = ToBE() ^ right.ToBE(); return (be_t&)res; }
template<typename T1> bool operator == (T1 right) const { return (T1)ToLE() == right; }
template<typename T1> bool operator != (T1 right) const { return !(*this == right); }

View File

@ -238,6 +238,13 @@ namespace vm
return (_ptr_base<void, 1, AT2>&)addr;
}
template<typename AT2>
operator const _ptr_base<const void, 1, AT2>() const
{
typename std::remove_const<AT2>::type addr; addr = m_addr;
return (_ptr_base<const void, 1, AT2>&)addr;
}
static _ptr_base make(AT addr)
{
return (_ptr_base&)addr;
@ -352,15 +359,20 @@ namespace vm
AT m_addr;
static_assert(!std::is_floating_point<RT>::value, "TODO: Unsupported callback result type (floating point)");
static_assert(!std::is_same<RT, u128>::value, "TODO: Unsupported callback result type (vector)");
static_assert(!std::is_pointer<RT>::value, "Invalid callback result type (pointer)");
static_assert(!std::is_reference<RT>::value, "Invalid callback result type (reference)");
template<typename TT>
struct _func_arg
{
static_assert(!std::is_floating_point<TT>::value, "TODO: Unsupported callback argument type (floating point)");
static_assert(!std::is_same<TT, u128>::value, "TODO: Unsupported callback argument type (vector)");
static_assert(sizeof(TT) <= 8, "Invalid callback argument type");
static_assert(!std::is_pointer<TT>::value, "Invalid callback argument type (pointer)");
static_assert(!std::is_reference<TT>::value, "Invalid callback argument type (reference)");
__forceinline static u64 get_value(const TT& arg)
{

View File

@ -0,0 +1,174 @@
#pragma once
enum CellPngTxtType
{
CELL_PNG_TEXT = 0,
CELL_PNG_ZTXT = 1,
CELL_PNG_ITXT = 2,
};
struct CellPngPLTEentry
{
u8 red;
u8 green;
u8 blue;
};
struct CellPngPaletteEntries
{
be_t<u16> red;
be_t<u16> green;
be_t<u16> blue;
be_t<u16> alpha;
be_t<u16> frequency;
};
struct CellPngSPLTentry
{
vm::bptr<char> paletteName;
u8 sampleDepth;
vm::bptr<CellPngPaletteEntries> paletteEntries;
be_t<u32> paletteEntriesNumber;
};
enum CellPngUnknownLocation
{
CELL_PNG_BEFORE_PLTE = 1,
CELL_PNG_BEFORE_IDAT = 2,
CELL_PNG_AFTER_IDAT = 8,
};
struct CellPngTextInfo
{
be_t<CellPngTxtType> txtType;
vm::bptr<char> keyword;
vm::bptr<char> text;
be_t<u32> textLength;
vm::bptr<char> languageTag;
vm::bptr<char> translatedKeyword;
};
struct CellPngPLTE
{
be_t<u32> paletteEntriesNumber;
vm::bptr<CellPngPLTEentry> paletteEntries;
};
struct CellPngGAMA
{
be_t<double> gamma;
};
struct CellPngSRGB
{
be_t<u32> renderingIntent;
};
struct CellPngICCP
{
vm::bptr<char> profileName;
vm::bptr<char> profile;
be_t<u32> profileLength;
};
struct CellPngSBIT
{
be_t<u32> red;
be_t<u32> green;
be_t<u32> blue;
be_t<u32> gray;
be_t<u32> alpha;
};
struct CellPngTRNS
{
vm::bptr<char> alphaForPaletteIndex;
be_t<u32> alphaForPaletteIndexNumber;
be_t<u16> red;
be_t<u16> green;
be_t<u16> blue;
be_t<u16> gray;
};
struct CellPngHIST
{
vm::bptr<u16> histgramEntries;
be_t<u32> histgramEntriesNumber;
};
struct CellPngTIME
{
be_t<u16> year;
u8 month;
u8 day;
u8 hour;
u8 minute;
u8 second;
};
struct CellPngBKGD
{
u8 paletteIndex;
be_t<u32> red;
be_t<u32> green;
be_t<u32> blue;
be_t<u32> gray;
};
struct CellPngSPLT
{
vm::bptr<CellPngSPLTentry> sPLTentries;
be_t<u32> sPLTentriesNumber;
};
struct CellPngOFFS
{
be_t<s32> xPosition;
be_t<s32> yPosition;
be_t<u32> unitSpecifier;
};
struct CellPngPHYS
{
be_t<u32> xAxis;
be_t<u32> yAxis;
be_t<u32> unitSpecifier;
};
struct CellPngSCAL
{
be_t<u32> unitSpecifier;
be_t<double> pixelWidth;
be_t<double> pixelHeight;
};
struct CellPngCHRM
{
be_t<double> whitePointX;
be_t<double> whitePointY;
be_t<double> redX;
be_t<double> redY;
be_t<double> greenX;
be_t<double> greenY;
be_t<double> blueX;
be_t<double> blueY;
};
struct CellPngPCAL
{
vm::bptr<char> calibrationName;
be_t<s32> x0;
be_t<s32> x1;
be_t<u32> equationType;
be_t<u32> numberOfParameters;
vm::bptr<char> unitName;
vm::bptr<char, 2> parameter;
};
struct CellPngUnknownChunk
{
char chunkType[5];
vm::bptr<char> chunkData;
be_t<u32> length;
be_t<CellPngUnknownLocation> location;
};

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "Emu/SysCalls/Modules.h"
#include "stblib/stb_image.h"
@ -11,149 +12,111 @@
//Module cellPngDec(0x0018, cellPngDec_init);
Module *cellPngDec = nullptr;
static std::map<u32, CellPngDecMainHandle *> cellPngDecMap;
#ifdef PRX_DEBUG
#include "prx_libpngdec.h"
u32 libpngdec;
u32 libpngdec_rtoc;
#endif
CellPngDecMainHandle *getCellPngDecCtx(u32 mainHandle) {
if (cellPngDecMap.find(mainHandle) == cellPngDecMap.end())
return nullptr;
return cellPngDecMap[mainHandle];
}
int cellPngDecCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam)
u32 pngDecCreate(vm::ptr<const CellPngDecThreadInParam> param, vm::ptr<const CellPngDecExtThreadInParam> ext = {})
{
cellPngDec->Warning("cellPngDecCreate(mainHandle=0x%x, threadInParam=0x%x, threadOutParam=0x%x)", mainHandle, threadInParam, threadOutParam);
CellPngDecMainHandle *ctx = new CellPngDecMainHandle;
if (cellPngDecMap.find(mainHandle) != cellPngDecMap.end()) {
delete cellPngDecMap[mainHandle];
cellPngDecMap.erase(mainHandle);
// alloc memory (should probably use param->cbCtrlMallocFunc)
auto dec = CellPngDecMainHandle::make(Memory.Alloc(sizeof(PngDecoder), 128));
// initialize decoder
dec->malloc = param->cbCtrlMallocFunc;
dec->malloc_arg = param->cbCtrlMallocArg;
dec->free = param->cbCtrlFreeFunc;
dec->free_arg = param->cbCtrlFreeArg;
if (ext)
{
}
cellPngDecMap[mainHandle] = ctx;
ctx->threadInParam = threadInParam;
ctx->threadOutParam = threadOutParam;
return CELL_OK;
// use virtual memory address as a handle
return dec.addr();
}
int cellPngDecDestroy(u32 mainHandle)
void pngDecDestroy(CellPngDecMainHandle dec)
{
cellPngDec->Warning("cellPngDecDestroy(mainHandle=0x%x)", mainHandle);
CellPngDecMainHandle *ctx = getCellPngDecCtx(mainHandle);
if (!ctx) {
cellPngDec->Warning("cellPngDecDestroy(mainHandle=0x%x): bad handle", mainHandle);
return -1;
}
delete ctx;
cellPngDecMap.erase(mainHandle);
return CELL_OK;
Memory.Free(dec.addr());
}
int cellPngDecOpen(u32 mainHandle, vm::ptr<be_t<u32>> subHandle, vm::ptr<CellPngDecSrc> src, u32 openInfo)
u32 pngDecOpen(CellPngDecMainHandle dec, vm::ptr<const CellPngDecSrc> src, vm::ptr<const CellPngDecCbCtrlStrm> cb = {}, vm::ptr<const CellPngDecOpnParam> param = {})
{
cellPngDec->Warning("cellPngDecOpen(mainHandle=0x%x, subHandle=0x%x, src_addr=0x%x, openInfo=0x%x)",
mainHandle, subHandle.addr(), src.addr(), openInfo);
// alloc memory (should probably use dec->malloc)
auto stream = CellPngDecSubHandle::make(Memory.Alloc(sizeof(PngStream), 128));
// initialize stream
stream->fd = 0;
stream->src = *src;
CellPngDecSubHandle *current_subHandle = new CellPngDecSubHandle;
current_subHandle->fd = 0;
current_subHandle->src = *src;
switch(src->srcSelect.ToBE())
switch (src->srcSelect.ToBE())
{
case se32(CELL_PNGDEC_BUFFER):
current_subHandle->fileSize = src->streamSize.ToLE();
stream->fileSize = src->streamSize.ToLE();
break;
case se32(CELL_PNGDEC_FILE):
// Get file descriptor
vm::var<be_t<u32>> fd;
int ret = cellFsOpen(vm::ptr<const char>::make(src->fileName.addr()), 0, fd, vm::ptr<be_t<u32>>::make(0), 0);
current_subHandle->fd = fd->ToLE();
if(ret != CELL_OK) return CELL_PNGDEC_ERROR_OPEN_FILE;
stream->fd = fd->ToLE();
if (ret != CELL_OK) return CELL_PNGDEC_ERROR_OPEN_FILE;
// Get size of file
vm::var<CellFsStat> sb; // Alloc a CellFsStat struct
ret = cellFsFstat(current_subHandle->fd, sb);
if(ret != CELL_OK) return ret;
current_subHandle->fileSize = sb->st_size; // Get CellFsStat.st_size
ret = cellFsFstat(stream->fd, sb);
if (ret != CELL_OK) return ret;
stream->fileSize = sb->st_size; // Get CellFsStat.st_size
break;
}
// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
*subHandle = cellPngDec->GetNewId(current_subHandle);
if (cb)
{
// TODO: callback
}
return CELL_OK;
if (param)
{
// TODO: param->selectChunk
}
// use virtual memory address as a handle
return stream.addr();
}
int cellPngDecExtOpen(u32 mainHandle, vm::ptr<be_t<u32>> subHandle, vm::ptr<CellPngDecSrc> src, u32 openInfo, vm::ptr<CellPngDecCbCtrlStrm> cbCtrlStrm, vm::ptr<CellPngDecOpnParam> opnParam)
void pngDecClose(CellPngDecSubHandle stream)
{
cellPngDec->Warning("cellPngDecExtOpen(mainHandle=0x%x, subHandle=0x%x, src_addr=0x%x, openInfo=0x%x, cbCtrlStrm_addr=0x%x, opnParam=0x%x)",
mainHandle, subHandle.addr(), src.addr(), openInfo, cbCtrlStrm.addr(), opnParam.addr());
cellPngDec->Warning("*** cbCtrlStrm->cbCtrlStrmFunc_addr=0x%x", cbCtrlStrm->cbCtrlStrmFunc.addr());
vm::var<CellPngDecStrmInfo> streamInfo;
vm::var<CellPngDecStrmParam> streamParam;
int res = cellPngDecOpen(mainHandle, subHandle, src, openInfo);
if (!res) cbCtrlStrm->cbCtrlStrmFunc(streamInfo, streamParam, cbCtrlStrm->cbCtrlStrmArg);
return res;
cellFsClose(stream->fd);
Memory.Free(stream.addr());
}
int cellPngDecClose(u32 mainHandle, u32 subHandle)
void pngReadHeader(CellPngDecSubHandle stream, vm::ptr<CellPngDecInfo> info, vm::ptr<CellPngDecExtInfo> extInfo = {})
{
cellPngDec->Warning("cellPngDecClose(mainHandle=0x%x,subHandle=0x%x)", mainHandle, subHandle);
CellPngDecInfo& current_info = stream->info;
CellPngDecSubHandle* subHandle_data;
if(!cellPngDec->CheckId(subHandle, subHandle_data))
return CELL_PNGDEC_ERROR_FATAL;
assert(stream->fileSize >= 29); // Error: The file is smaller than the length of a PNG header
cellFsClose(subHandle_data->fd);
cellPngDec->RemoveId(subHandle);
return CELL_OK;
}
int cellPngDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellPngDecInfo> info)
{
cellPngDec->Warning("cellPngDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x)", mainHandle, subHandle, info.addr());
CellPngDecSubHandle* subHandle_data;
if(!cellPngDec->CheckId(subHandle, subHandle_data))
return CELL_PNGDEC_ERROR_FATAL;
const u32& fd = subHandle_data->fd;
const u64& fileSize = subHandle_data->fileSize;
CellPngDecInfo& current_info = subHandle_data->info;
//Check size of file
if(fileSize < 29) return CELL_PNGDEC_ERROR_HEADER; // Error: The file is smaller than the length of a PNG header
//Write the header to buffer
vm::var<u8[34]> buffer; // Alloc buffer for PNG header
auto buffer_32 = buffer.To<be_t<u32>>();
vm::var<be_t<u64>> pos, nread;
switch(subHandle_data->src.srcSelect.ToBE())
switch (stream->src.srcSelect.ToBE())
{
case se32(CELL_PNGDEC_BUFFER):
memmove(buffer.begin(), vm::get_ptr<void>(subHandle_data->src.streamPtr), buffer.size());
memmove(buffer.begin(), vm::get_ptr<void>(stream->src.streamPtr), buffer.size());
break;
case se32(CELL_PNGDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos);
cellFsRead(fd, vm::ptr<void>::make(buffer.addr()), buffer.size(), nread);
cellFsLseek(stream->fd, 0, CELL_SEEK_SET, pos);
cellFsRead(stream->fd, vm::ptr<void>::make(buffer.addr()), buffer.size(), nread);
break;
}
if (buffer_32[0].ToBE() != se32(0x89504E47) ||
buffer_32[1].ToBE() != se32(0x0D0A1A0A) || // Error: The first 8 bytes are not a valid PNG signature
buffer_32[3].ToBE() != se32(0x49484452)) // Error: The PNG file does not start with an IHDR chunk
{
return CELL_PNGDEC_ERROR_HEADER;
}
assert(buffer_32[0].ToBE() == se32(0x89504E47) &&
buffer_32[1].ToBE() == se32(0x0D0A1A0A) && // Error: The first 8 bytes are not a valid PNG signature
buffer_32[3].ToBE() == se32(0x49484452)); // Error: The PNG file does not start with an IHDR chunk
switch (buffer[25])
{
@ -162,27 +125,19 @@ int cellPngDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellPngDecInfo>
case 3: current_info.colorSpace = CELL_PNGDEC_PALETTE; current_info.numComponents = 1; break;
case 4: current_info.colorSpace = CELL_PNGDEC_GRAYSCALE_ALPHA; current_info.numComponents = 2; break;
case 6: current_info.colorSpace = CELL_PNGDEC_RGBA; current_info.numComponents = 4; break;
default: return CELL_PNGDEC_ERROR_HEADER; // Not supported color type
default: assert(!"Unknown color type"); return; // Not supported color type
}
current_info.imageWidth = buffer_32[4];
current_info.imageHeight = buffer_32[5];
current_info.bitDepth = buffer[24];
current_info.interlaceMethod = buffer[28];
current_info.imageWidth = buffer_32[4];
current_info.imageHeight = buffer_32[5];
current_info.bitDepth = buffer[24];
current_info.interlaceMethod = (CellPngDecInterlaceMode)buffer[28];
current_info.chunkInformation = 0; // Unimplemented
*info = current_info;
return CELL_OK;
}
int cellPngDecExtReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellPngDecInfo> info, vm::ptr<CellPngDecExtInfo> extInfo)
{
cellPngDec->Warning("cellPngDecExtReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x, extInfo_addr=0x%x)",
mainHandle, subHandle, info.addr(), extInfo.addr());
return cellPngDecReadHeader(mainHandle, subHandle, info);
}
/*
int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr<u8> data, vm::ptr<const CellPngDecDataCtrlParam> dataCtrlParam, vm::ptr<CellPngDecDataOutInfo> dataOutInfo)
{
@ -367,39 +322,496 @@ int cellPngDecExtSetParameter(u32 mainHandle, u32 subHandle, vm::ptr<const CellP
mainHandle, subHandle, inParam.addr(), outParam.addr(), extInParam.addr(), extOutParam.addr());
return cellPngDecSetParameter(mainHandle, subHandle, inParam, outParam);
}*/
s32 cellPngDecCreate(vm::ptr<u32> mainHandle, vm::ptr<const CellPngDecThreadInParam> threadInParam, vm::ptr<CellPngDecThreadOutParam> threadOutParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x295C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecCreate(mainHandle_addr=0x%x, threadInParam_addr=0x%x, threadOutParam_addr=0x%x)",
mainHandle.addr(), threadInParam.addr(), threadOutParam.addr());
*mainHandle = pngDecCreate(threadInParam);
// set codec version
threadOutParam->pngCodecVersion = PNGDEC_CODEC_VERSION;
return CELL_OK;
#endif
}
s32 cellPngDecExtCreate(
vm::ptr<u32> mainHandle,
vm::ptr<const CellPngDecThreadInParam> threadInParam,
vm::ptr<CellPngDecThreadOutParam> threadOutParam,
vm::ptr<const CellPngDecExtThreadInParam> extThreadInParam,
vm::ptr<CellPngDecExtThreadOutParam> extThreadOutParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x296C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecCreate(mainHandle_addr=0x%x, threadInParam_addr=0x%x, threadOutParam_addr=0x%x, extThreadInParam_addr=0x%x, extThreadOutParam_addr=0x%x)",
mainHandle.addr(), threadInParam.addr(), threadOutParam.addr(), extThreadInParam.addr(), extThreadOutParam.addr());
// create decoder
*mainHandle = pngDecCreate(threadInParam, extThreadInParam);
// set codec version
threadOutParam->pngCodecVersion = PNGDEC_CODEC_VERSION;
extThreadOutParam->reserved = 0;
return CELL_OK;
#endif
}
s32 cellPngDecDestroy(CellPngDecMainHandle mainHandle)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x1E6C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecDestroy(mainHandle=0x%x)", mainHandle.addr());
pngDecDestroy(mainHandle);
return CELL_OK;
#endif
}
s32 cellPngDecOpen(
CellPngDecMainHandle mainHandle,
vm::ptr<u32> subHandle,
vm::ptr<const CellPngDecSrc> src,
vm::ptr<CellPngDecOpnInfo> openInfo)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x3F3C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecOpen(mainHandle=0x%x, subHandle_addr=0x%x, src_addr=0x%x, openInfo_addr=0x%x)",
mainHandle.addr(), subHandle.addr(), src.addr(), openInfo.addr());
// create stream handle
*subHandle = pngDecOpen(mainHandle, src);
// set memory info
openInfo->initSpaceAllocated = 4096;
return CELL_OK;
#endif
}
s32 cellPngDecExtOpen(
CellPngDecMainHandle mainHandle,
vm::ptr<u32> subHandle,
vm::ptr<const CellPngDecSrc> src,
vm::ptr<CellPngDecOpnInfo> openInfo,
vm::ptr<const CellPngDecCbCtrlStrm> cbCtrlStrm,
vm::ptr<const CellPngDecOpnParam> opnParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x3F34, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecExtOpen(mainHandle=0x%x, subHandle_addr=0x%x, src_addr=0x%x, openInfo_addr=0x%x, cbCtrlStrm_addr=0x%x, opnParam_addr=0x%x)",
mainHandle.addr(), subHandle.addr(), src.addr(), openInfo.addr(), cbCtrlStrm.addr(), opnParam.addr());
// create stream handle
*subHandle = pngDecOpen(mainHandle, src, cbCtrlStrm, opnParam);
// set memory info
openInfo->initSpaceAllocated = 4096;
return CELL_OK;
#endif
}
s32 cellPngDecClose(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x066C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecClose(mainHandle=0x%x, subHandle=0x%x)", mainHandle.addr(), subHandle.addr());
pngDecClose(subHandle);
return CELL_OK;
#endif
}
s32 cellPngDecReadHeader(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngDecInfo> info)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x3A3C, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x)",
mainHandle.addr(), subHandle.addr(), info.addr());
pngReadHeader(subHandle, info);
return CELL_OK;
#endif
}
s32 cellPngDecExtReadHeader(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<CellPngDecInfo> info,
vm::ptr<CellPngDecExtInfo> extInfo)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x3A34, libpngdec_rtoc);
#else
cellPngDec->Warning("cellPngDecExtReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x, extInfo_addr=0x%x)",
mainHandle.addr(), subHandle.addr(), info.addr(), extInfo.addr());
pngReadHeader(subHandle, info, extInfo);
return CELL_OK;
#endif
}
s32 cellPngDecSetParameter(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<const CellPngDecInParam> inParam,
vm::ptr<CellPngDecOutParam> outParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x33F4, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecExtSetParameter(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<const CellPngDecInParam> inParam,
vm::ptr<CellPngDecOutParam> outParam,
vm::ptr<const CellPngDecExtInParam> extInParam,
vm::ptr<CellPngDecExtOutParam> extOutParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x33EC, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecDecodeData(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u8> data,
vm::ptr<const CellPngDecDataCtrlParam> dataCtrlParam,
vm::ptr<CellPngDecDataOutInfo> dataOutInfo)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x5D40, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecExtDecodeData(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u8> data,
vm::ptr<const CellPngDecDataCtrlParam> dataCtrlParam,
vm::ptr<CellPngDecDataOutInfo> dataOutInfo,
vm::ptr<const CellPngDecCbCtrlDisp> cbCtrlDisp,
vm::ptr<CellPngDecDispParam> dispParam)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x5D38, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetUnknownChunks(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<CellPngUnknownChunk, 2> unknownChunk,
vm::ptr<u32> unknownChunkNumber)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x03EC, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetpCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPCAL> pcal)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0730, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetcHRM(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngCHRM> chrm)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0894, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetsCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSCAL> scal)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x09EC, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetpHYs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPHYS> phys)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0B14, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetoFFs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngOFFS> offs)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0C58, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetsPLT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSPLT> splt)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0D9C, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetbKGD(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngBKGD> bkgd)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x0ED0, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGettIME(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngTIME> time)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x1024, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGethIST(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngHIST> hist)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x116C, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGettRNS(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngTRNS> trns)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x12A4, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetsBIT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSBIT> sbit)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x1420, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetiCCP(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngICCP> iccp)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x1574, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetsRGB(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSRGB> srgb)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x16B4, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetgAMA(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngGAMA> gama)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x17CC, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetPLTE(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPLTE> plte)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x18E4, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
s32 cellPngDecGetTextChunk(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u32> textInfoNum,
vm::ptr<CellPngTextInfo, 2> textInfo)
{
#ifdef PRX_DEBUG
cellPngDec->Warning("%s()", __FUNCTION__);
return GetCurrentPPUThread().FastCall2(libpngdec + 0x19FC, libpngdec_rtoc);
#else
UNIMPLEMENTED_FUNC(cellPngDec);
return CELL_OK;
#endif
}
void cellPngDec_init()
{
cellPngDec->AddFunc(0x157d30c5, cellPngDecCreate);
cellPngDec->AddFunc(0x820dae1a, cellPngDecDestroy);
cellPngDec->AddFunc(0xd2bc5bfd, cellPngDecOpen);
cellPngDec->AddFunc(0x5b3d1ff1, cellPngDecClose);
cellPngDec->AddFunc(0x9ccdcc95, cellPngDecReadHeader);
cellPngDec->AddFunc(0x2310f155, cellPngDecDecodeData);
cellPngDec->AddFunc(0xe97c9bd4, cellPngDecSetParameter);
REG_FUNC(cellPngDec, cellPngDecGetUnknownChunks);
REG_FUNC(cellPngDec, cellPngDecClose);
REG_FUNC(cellPngDec, cellPngDecGetpCAL);
REG_FUNC(cellPngDec, cellPngDecGetcHRM);
REG_FUNC(cellPngDec, cellPngDecGetsCAL);
REG_FUNC(cellPngDec, cellPngDecGetpHYs);
REG_FUNC(cellPngDec, cellPngDecGetoFFs);
REG_FUNC(cellPngDec, cellPngDecGetsPLT);
REG_FUNC(cellPngDec, cellPngDecGetbKGD);
REG_FUNC(cellPngDec, cellPngDecGettIME);
REG_FUNC(cellPngDec, cellPngDecGethIST);
REG_FUNC(cellPngDec, cellPngDecGettRNS);
REG_FUNC(cellPngDec, cellPngDecGetsBIT);
REG_FUNC(cellPngDec, cellPngDecGetiCCP);
REG_FUNC(cellPngDec, cellPngDecGetsRGB);
REG_FUNC(cellPngDec, cellPngDecGetgAMA);
REG_FUNC(cellPngDec, cellPngDecGetPLTE);
REG_FUNC(cellPngDec, cellPngDecGetTextChunk);
REG_FUNC(cellPngDec, cellPngDecDestroy);
REG_FUNC(cellPngDec, cellPngDecCreate);
REG_FUNC(cellPngDec, cellPngDecExtCreate);
REG_FUNC(cellPngDec, cellPngDecExtSetParameter);
REG_FUNC(cellPngDec, cellPngDecSetParameter);
REG_FUNC(cellPngDec, cellPngDecExtReadHeader);
REG_FUNC(cellPngDec, cellPngDecReadHeader);
REG_FUNC(cellPngDec, cellPngDecExtOpen);
REG_FUNC(cellPngDec, cellPngDecOpen);
REG_FUNC(cellPngDec, cellPngDecExtDecodeData);
REG_FUNC(cellPngDec, cellPngDecDecodeData);
cellPngDec->AddFunc(0x0c515302, cellPngDecExtOpen);
cellPngDec->AddFunc(0x8b33f863, cellPngDecExtReadHeader);
cellPngDec->AddFunc(0x726fc1d0, cellPngDecExtDecodeData);
cellPngDec->AddFunc(0x9e9d7d42, cellPngDecExtSetParameter);
#ifdef PRX_DEBUG
CallAfter([]()
{
libpngdec = (u32)Memory.PRXMem.AllocAlign(sizeof(libpngdec_data), 4096);
memcpy(vm::get_ptr<void>(libpngdec), libpngdec_data, sizeof(libpngdec_data));
libpngdec_rtoc = libpngdec + 0x49710;
/*cellPngDec->AddFunc(0x48436b2d, cellPngDecExtCreate);
cellPngDec->AddFunc(0x7585a275, cellPngDecGetbKGD);
cellPngDec->AddFunc(0x7a062d26, cellPngDecGetcHRM);
cellPngDec->AddFunc(0xb153629c, cellPngDecGetgAMA);
cellPngDec->AddFunc(0xb905ebb7, cellPngDecGethIST);
cellPngDec->AddFunc(0xf44b6c30, cellPngDecGetiCCP);
cellPngDec->AddFunc(0x27c921b5, cellPngDecGetoFFs);
cellPngDec->AddFunc(0xb4fe75e1, cellPngDecGetpCAL);
cellPngDec->AddFunc(0x3d50016a, cellPngDecGetpHYs);
cellPngDec->AddFunc(0x30cb334a, cellPngDecGetsBIT);
cellPngDec->AddFunc(0xc41e1198, cellPngDecGetsCAL);
cellPngDec->AddFunc(0xa5cdf57e, cellPngDecGetsPLT);
cellPngDec->AddFunc(0xe4416e82, cellPngDecGetsRGB);
cellPngDec->AddFunc(0x35a6846c, cellPngDecGettIME);
cellPngDec->AddFunc(0xb96fb26e, cellPngDecGettRNS);
cellPngDec->AddFunc(0xe163977f, cellPngDecGetPLTE);
cellPngDec->AddFunc(0x609ec7d5, cellPngDecUnknownChunks);
cellPngDec->AddFunc(0xb40ca175, cellPngDecGetTextChunk);*/
extern Module* sysPrxForUser;
extern Module* cellSpurs;
extern Module* sys_fs;
FIX_IMPORT(sysPrxForUser, _sys_snprintf , libpngdec + 0x1E6D0);
FIX_IMPORT(sysPrxForUser, _sys_strlen , libpngdec + 0x1E6F0);
fix_import(sysPrxForUser, 0x3EF17F8C , libpngdec + 0x1E710);
FIX_IMPORT(sysPrxForUser, _sys_memset , libpngdec + 0x1E730);
FIX_IMPORT(sysPrxForUser, _sys_memcpy , libpngdec + 0x1E750);
FIX_IMPORT(sysPrxForUser, _sys_strcpy , libpngdec + 0x1E770);
FIX_IMPORT(sysPrxForUser, _sys_strncpy , libpngdec + 0x1E790);
FIX_IMPORT(sysPrxForUser, _sys_memcmp , libpngdec + 0x1E7B0);
FIX_IMPORT(cellSpurs, cellSpursQueueDetachLv2EventQueue , libpngdec + 0x1E7D0);
FIX_IMPORT(cellSpurs, cellSpursAttributeSetNamePrefix , libpngdec + 0x1E7F0);
FIX_IMPORT(cellSpurs, _cellSpursQueueInitialize , libpngdec + 0x1E810);
FIX_IMPORT(cellSpurs, _cellSpursTasksetAttributeInitialize, libpngdec + 0x1E830);
FIX_IMPORT(cellSpurs, cellSpursTasksetAttributeSetName , libpngdec + 0x1E850);
FIX_IMPORT(cellSpurs, cellSpursTaskGetReadOnlyAreaPattern , libpngdec + 0x1E870);
FIX_IMPORT(cellSpurs, cellSpursTaskGetContextSaveAreaSize , libpngdec + 0x1E890);
FIX_IMPORT(cellSpurs, cellSpursQueuePopBody , libpngdec + 0x1E8B0);
FIX_IMPORT(cellSpurs, cellSpursQueuePushBody , libpngdec + 0x1E8D0);
FIX_IMPORT(cellSpurs, _cellSpursAttributeInitialize , libpngdec + 0x1E8F0);
FIX_IMPORT(cellSpurs, cellSpursJoinTaskset , libpngdec + 0x1E910);
FIX_IMPORT(cellSpurs, cellSpursShutdownTaskset , libpngdec + 0x1E930);
FIX_IMPORT(cellSpurs, cellSpursInitializeWithAttribute , libpngdec + 0x1E950);
FIX_IMPORT(cellSpurs, cellSpursCreateTask , libpngdec + 0x1E970);
FIX_IMPORT(cellSpurs, cellSpursCreateTasksetWithAttribute , libpngdec + 0x1E990);
FIX_IMPORT(cellSpurs, cellSpursFinalize , libpngdec + 0x1E9B0);
FIX_IMPORT(cellSpurs, cellSpursQueueAttachLv2EventQueue , libpngdec + 0x1E9D0);
FIX_IMPORT(sys_fs, cellFsClose , libpngdec + 0x1E9F0);
FIX_IMPORT(sys_fs, cellFsRead , libpngdec + 0x1EA10);
FIX_IMPORT(sys_fs, cellFsOpen , libpngdec + 0x1EA30);
FIX_IMPORT(sys_fs, cellFsLseek , libpngdec + 0x1EA50);
fix_relocs(cellPngDec, libpngdec, 0x41C30, 0x47AB0, 0x40A00);
});
#endif
}

View File

@ -1,6 +1,18 @@
#pragma once
#include "cellPng.h"
//Return Codes
enum : u32
{
PNGDEC_CODEC_VERSION = 0x00420000,
};
struct PngDecoder;
struct PngStream;
typedef vm::ptr<PngDecoder> CellPngDecMainHandle;
typedef vm::ptr<PngStream> CellPngDecSubHandle;
// Return Codes
enum
{
CELL_PNGDEC_ERROR_HEADER = 0x80611201,
@ -15,6 +27,7 @@ enum
CELL_PNGDEC_ERROR_CB_PARAM = 0x8061120a,
};
// Consts
enum CellPngDecColorSpace
{
CELL_PNGDEC_GRAYSCALE = 1,
@ -25,10 +38,10 @@ enum CellPngDecColorSpace
CELL_PNGDEC_ARGB = 20,
};
enum CellPngDecDecodeStatus
enum CellPngDecSpuThreadEna : u32
{
CELL_PNGDEC_DEC_STATUS_FINISH = 0, //Decoding finished
CELL_PNGDEC_DEC_STATUS_STOP = 1, //Decoding halted
CELL_PNGDEC_SPU_THREAD_DISABLE = 0,
CELL_PNGDEC_SPU_THREAD_ENABLE = 1,
};
enum CellPngDecStreamSrcSel
@ -49,19 +62,77 @@ enum CellPngDecOutputMode
CELL_PNGDEC_BOTTOM_TO_TOP = 1,
};
// Structs
struct CellPngDecDataOutInfo
enum CellPngDecPackFlag
{
be_t<u32> chunkInformation;
be_t<u32> numText;
be_t<u32> numUnknownChunk;
be_t<u32> status;
CELL_PNGDEC_1BYTE_PER_NPIXEL = 0,
CELL_PNGDEC_1BYTE_PER_1PIXEL = 1,
};
struct CellPngDecDataCtrlParam
enum CellPngDecAlphaSelect
{
be_t<u64> outputBytesPerLine;
CELL_PNGDEC_STREAM_ALPHA = 0,
CELL_PNGDEC_FIX_ALPHA = 1,
};
enum CellPngDecCommand
{
CELL_PNGDEC_CONTINUE = 0,
CELL_PNGDEC_STOP = 1,
};
enum CellPngDecDecodeStatus
{
CELL_PNGDEC_DEC_STATUS_FINISH = 0,
CELL_PNGDEC_DEC_STATUS_STOP = 1,
};
// Callbacks
typedef vm::ptr<void>(*CellPngDecCbControlMalloc)(u32 size, vm::ptr<void> cbCtrlMallocArg);
typedef s32(*CellPngDecCbControlFree)(vm::ptr<void> ptr, vm::ptr<void> cbCtrlFreeArg);
// Structs
struct CellPngDecThreadInParam
{
be_t<CellPngDecSpuThreadEna> spuThreadEnable;
be_t<u32> ppuThreadPriority;
be_t<u32> spuThreadPriority;
vm::bptr<CellPngDecCbControlMalloc> cbCtrlMallocFunc;
be_t<vm::ptr<void>> cbCtrlMallocArg; // rough attempt (it's hard to pass vm::bptr as vm::ptr in function argument)
vm::bptr<CellPngDecCbControlFree> cbCtrlFreeFunc;
be_t<vm::ptr<void>> cbCtrlFreeArg;
};
struct CellPngDecExtThreadInParam
{
be_t<u32> spurs_addr; // it could be vm::bptr<CellSpurs>, but nobody will use SPURS in HLE implementation
u8 priority[8];
be_t<u32> maxContention;
};
struct CellPngDecThreadOutParam
{
be_t<u32> pngCodecVersion;
};
struct CellPngDecExtThreadOutParam
{
be_t<u32> reserved;
};
struct CellPngDecSrc
{
be_t<CellPngDecStreamSrcSel> srcSelect;
vm::bptr<const char> fileName;
be_t<s64> fileOffset;
be_t<u32> fileSize;
vm::bptr<void> streamPtr;
be_t<u32> streamSize;
be_t<CellPngDecSpuThreadEna> spuThreadEnable;
};
struct CellPngDecOpnInfo
{
be_t<u32> initSpaceAllocated;
};
struct CellPngDecInfo
@ -69,31 +140,20 @@ struct CellPngDecInfo
be_t<u32> imageWidth;
be_t<u32> imageHeight;
be_t<u32> numComponents;
be_t<u32> colorSpace; // CellPngDecColorSpace
be_t<CellPngDecColorSpace> colorSpace;
be_t<u32> bitDepth;
be_t<u32> interlaceMethod; // CellPngDecInterlaceMode
be_t<CellPngDecInterlaceMode> interlaceMethod;
be_t<u32> chunkInformation;
};
struct CellPngDecSrc
{
be_t<u32> srcSelect; // CellPngDecStreamSrcSel
vm::bptr<const char> fileName;
be_t<s64> fileOffset;
be_t<u32> fileSize;
be_t<u32> streamPtr;
be_t<u32> streamSize;
be_t<u32> spuThreadEnable; // CellPngDecSpuThreadEna
};
struct CellPngDecInParam
{
be_t<u32> commandPtr;
be_t<u32> outputMode; // CellPngDecOutputMode
be_t<u32> outputColorSpace; // CellPngDecColorSpace
vm::bptr<volatile CellPngDecCommand> commandPtr;
be_t<CellPngDecOutputMode> outputMode;
be_t<CellPngDecColorSpace> outputColorSpace;
be_t<u32> outputBitDepth;
be_t<u32> outputPackFlag; // CellPngDecPackFlag
be_t<u32> outputAlphaSelect; // CellPngDecAlphaSelect
be_t<CellPngDecPackFlag> outputPackFlag;
be_t<CellPngDecAlphaSelect> outputAlphaSelect;
be_t<u32> outputColorAlpha;
};
@ -104,11 +164,114 @@ struct CellPngDecOutParam
be_t<u32> outputHeight;
be_t<u32> outputComponents;
be_t<u32> outputBitDepth;
be_t<u32> outputMode; // CellPngDecOutputMode
be_t<u32> outputColorSpace; // CellPngDecColorSpace
be_t<CellPngDecOutputMode> outputMode;
be_t<CellPngDecColorSpace> outputColorSpace;
be_t<u32> useMemorySpace;
};
struct CellPngDecDataCtrlParam
{
be_t<u64> outputBytesPerLine;
};
struct CellPngDecDataOutInfo
{
be_t<u32> chunkInformation;
be_t<u32> numText;
be_t<u32> numUnknownChunk;
be_t<CellPngDecDecodeStatus> status;
};
// Functions
s32 cellPngDecCreate(vm::ptr<u32> mainHandle, vm::ptr<const CellPngDecThreadInParam> threadInParam, vm::ptr<CellPngDecThreadOutParam> threadOutParam);
s32 cellPngDecExtCreate(
vm::ptr<u32> mainHandle,
vm::ptr<const CellPngDecThreadInParam> threadInParam,
vm::ptr<CellPngDecThreadOutParam> threadOutParam,
vm::ptr<const CellPngDecExtThreadInParam> extThreadInParam,
vm::ptr<CellPngDecExtThreadOutParam> extThreadOutParam);
s32 cellPngDecOpen(
CellPngDecMainHandle mainHandle,
vm::ptr<u32> subHandle,
vm::ptr<const CellPngDecSrc> src,
vm::ptr<CellPngDecOpnInfo> openInfo);
s32 cellPngDecReadHeader(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngDecInfo> info);
s32 cellPngDecSetParameter(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<const CellPngDecInParam> inParam,
vm::ptr<CellPngDecOutParam> outParam);
s32 cellPngDecDecodeData(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u8> data,
vm::ptr<const CellPngDecDataCtrlParam> dataCtrlParam,
vm::ptr<CellPngDecDataOutInfo> dataOutInfo);
s32 cellPngDecClose(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle);
s32 cellPngDecDestroy(CellPngDecMainHandle mainHandle);
s32 cellPngDecGetTextChunk(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u32> textInfoNum,
vm::ptr<CellPngTextInfo, 2> textInfo);
s32 cellPngDecGetPLTE(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPLTE> plte);
s32 cellPngDecGetgAMA(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngGAMA> gama);
s32 cellPngDecGetsRGB(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSRGB> srgb);
s32 cellPngDecGetiCCP(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngICCP> iccp);
s32 cellPngDecGetsBIT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSBIT> sbit);
s32 cellPngDecGettRNS(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngTRNS> trns);
s32 cellPngDecGethIST(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngHIST> hist);
s32 cellPngDecGettIME(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngTIME> time);
s32 cellPngDecGetbKGD(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngBKGD> bkgd);
s32 cellPngDecGetsPLT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSPLT> splt);
s32 cellPngDecGetoFFs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngOFFS> offs);
s32 cellPngDecGetpHYs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPHYS> phys);
s32 cellPngDecGetsCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngSCAL> scal);
s32 cellPngDecGetcHRM(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngCHRM> chrm);
s32 cellPngDecGetpCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr<CellPngPCAL> pcal);
s32 cellPngDecGetUnknownChunks(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<CellPngUnknownChunk, 2> unknownChunk,
vm::ptr<u32> unknownChunkNumber);
enum CellPngDecBufferMode
{
CELL_PNGDEC_LINE_MODE = 1,
};
enum CellPngDecSpuMode
{
CELL_PNGDEC_RECEIVE_EVENT = 0,
CELL_PNGDEC_TRYRECEIVE_EVENT = 1,
};
// Structs
struct CellPngDecStrmInfo
{
be_t<u32> decodedStrmSize;
@ -116,25 +279,49 @@ struct CellPngDecStrmInfo
struct CellPngDecStrmParam
{
be_t<u32> strmPtr;
vm::bptr<void> strmPtr;
be_t<u32> strmSize;
};
struct CellPngDecCbCtrlStrm
{
vm::bptr<void(*)(vm::ptr<CellPngDecStrmInfo> strmInfo, vm::ptr<CellPngDecStrmParam> strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc;
be_t<u32> cbCtrlStrmArg;
};
typedef s32(*CellPngDecCbControlStream)(
vm::ptr<CellPngDecStrmInfo> strmInfo,
vm::ptr<CellPngDecStrmParam> strmParam,
vm::ptr<void> cbCtrlStrmArg
);
struct CellPngDecCbCtrlDisp
struct CellPngDecDispInfo
{
be_t<u32> cbCtrlDispFunc_addr;
be_t<u32> cbCtrlDispArg;
be_t<u64> outputFrameWidthByte;
be_t<u32> outputFrameHeight;
be_t<u64> outputStartXByte;
be_t<u32> outputStartY;
be_t<u64> outputWidthByte;
be_t<u32> outputHeight;
be_t<u32> outputBitDepth;
be_t<u32> outputComponents;
be_t<u32> nextOutputStartY;
be_t<u32> scanPassCount;
vm::bptr<void> outputImage;
};
struct CellPngDecDispParam
{
be_t<u32> nextOutputImage_addr;
vm::bptr<void> nextOutputImage;
};
// Callback
typedef s32(*CellPngDecCbControlDisp)(vm::ptr<CellPngDecDispInfo> dispInfo, vm::ptr<CellPngDecDispParam> dispParam, vm::ptr<void> cbCtrlDispArg);
// Structs
struct CellPngDecOpnParam
{
be_t<u32> selectChunk;
};
struct CellPngDecCbCtrlStrm
{
vm::bptr<CellPngDecCbControlStream> cbCtrlStrmFunc;
be_t<vm::ptr<void>> cbCtrlStrmArg;
};
struct CellPngDecExtInfo
@ -144,9 +331,9 @@ struct CellPngDecExtInfo
struct CellPngDecExtInParam
{
be_t<u32> bufferMode; // CellPngDecBufferMode
be_t<CellPngDecBufferMode> bufferMode;
be_t<u32> outputCounts;
be_t<u32> spuMode; // CellPngDecSpuMode
be_t<CellPngDecSpuMode> spuMode;
};
struct CellPngDecExtOutParam
@ -155,25 +342,80 @@ struct CellPngDecExtOutParam
be_t<u32> outputHeight;
};
struct CellPngDecOpnParam
struct CellPngDecCbCtrlDisp
{
be_t<u32> selectChunk;
vm::bptr<CellPngDecCbControlDisp> cbCtrlDispFunc;
be_t<vm::ptr<void>> cbCtrlDispArg;
};
// Functions
s32 cellPngDecExtOpen(
CellPngDecMainHandle mainHandle,
vm::ptr<u32> subHandle,
vm::ptr<const CellPngDecSrc> src,
vm::ptr<CellPngDecOpnInfo> openInfo,
vm::ptr<const CellPngDecCbCtrlStrm> cbCtrlStrm,
vm::ptr<const CellPngDecOpnParam> opnParam);
// Custom structs
struct CellPngDecSubHandle
s32 cellPngDecExtReadHeader(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<CellPngDecInfo> info,
vm::ptr<CellPngDecExtInfo> extInfo);
s32 cellPngDecExtSetParameter(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<const CellPngDecInParam> inParam,
vm::ptr<CellPngDecOutParam> outParam,
vm::ptr<const CellPngDecExtInParam> extInParam,
vm::ptr<CellPngDecExtOutParam> extOutParam);
s32 cellPngDecExtDecodeData(
CellPngDecMainHandle mainHandle,
CellPngDecSubHandle subHandle,
vm::ptr<u8> data,
vm::ptr<const CellPngDecDataCtrlParam> dataCtrlParam,
vm::ptr<CellPngDecDataOutInfo> dataOutInfo,
vm::ptr<const CellPngDecCbCtrlDisp> cbCtrlDisp,
vm::ptr<CellPngDecDispParam> dispParam);
//// Custom structs
//struct CellPngDecSubHandle
//{
// be_t<u32> fd;
// be_t<u64> fileSize;
// CellPngDecInfo info;
// CellPngDecOutParam outParam;
// CellPngDecSrc src;
//};
//
//struct CellPngDecMainHandle
//{
// be_t<u32> mainHandle;
// be_t<u32> threadInParam;
// be_t<u32> threadOutParam;
//};
struct PngDecoder
{
be_t<u32> fd;
be_t<u64> fileSize;
vm::ptr<CellPngDecCbControlMalloc> malloc;
vm::ptr<void> malloc_arg;
vm::ptr<CellPngDecCbControlFree> free;
vm::ptr<void> free_arg;
};
struct PngStream
{
CellPngDecMainHandle dec;
// old data:
u32 fd;
u64 fileSize;
CellPngDecInfo info;
CellPngDecOutParam outParam;
CellPngDecSrc src;
};
struct CellPngDecMainHandle
{
be_t<u32> mainHandle;
be_t<u32> threadInParam;
be_t<u32> threadOutParam;
};
CellPngDecStrmInfo streamInfo;
CellPngDecStrmParam streamParam;
};

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "Emu/SysCalls/Modules.h"
#include "Emu/FS/vfsFile.h"
@ -299,12 +300,26 @@ s64 _sys_spu_printf_detach_thread(u32 arg)
return GetCurrentPPUThread().FastCall(vm::read32(spu_printf_dtcb), vm::read32(spu_printf_dtcb + 4), arg);
}
s32 _sys_snprintf(vm::ptr<char> dst, u32 count, vm::ptr<const char> fmt, u32 a1, u32 a2) // va_args...
{
sysPrxForUser->Todo("_sys_snprintf(dst_addr=0x%x, count=%d, fmt_addr=0x%x['%s'], ...)", dst.addr(), count, fmt.addr(), fmt.get_ptr());
if (std::string(fmt.get_ptr()) == "%s_%08x")
{
return snprintf(dst.get_ptr(), count, fmt.get_ptr(), vm::get_ptr<char>(a1), a2);
}
Emu.Pause();
return 0;
}
s32 _sys_printf(vm::ptr<const char> fmt)
{
sysPrxForUser->Todo("_sys_printf(fmt_addr=0x%x, ...)", fmt.addr());
// probably, assertion failed
sysPrxForUser->Warning("_sys_printf: \n%s", fmt.get_ptr());
Emu.Pause();
return CELL_OK;
}
@ -395,7 +410,6 @@ void sysPrxForUser_init()
REG_FUNC(sysPrxForUser, _sys_strncat);
REG_FUNC(sysPrxForUser, _sys_strcpy);
REG_FUNC(sysPrxForUser, _sys_strncpy);
sysPrxForUser->AddFunc(0xe75c40f2, _unnamed_E75C40F2); // real name is unknown
REG_FUNC(sysPrxForUser, _sys_spu_printf_initialize);
REG_FUNC(sysPrxForUser, _sys_spu_printf_finalize);
@ -404,7 +418,10 @@ void sysPrxForUser_init()
REG_FUNC(sysPrxForUser, _sys_spu_printf_attach_thread);
REG_FUNC(sysPrxForUser, _sys_spu_printf_detach_thread);
REG_FUNC(sysPrxForUser, _sys_snprintf);
REG_FUNC(sysPrxForUser, _sys_printf);
sysPrxForUser->AddFunc(0xe75c40f2, _unnamed_E75C40F2); // real name is unknown
}
void sysPrxForUser_load()

View File

@ -24,7 +24,7 @@ namespace detail
template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_GENERAL, g_count, f_count, v_count>
{
static_assert(sizeof(T) <= 8, "Wrong argument type for ARG_GENERAL");
static_assert(sizeof(T) <= 8, "Invalid function argument type for ARG_GENERAL");
static __forceinline T func(PPUThread& CPU)
{
@ -35,7 +35,7 @@ namespace detail
template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_FLOAT, g_count, f_count, v_count>
{
static_assert(sizeof(T) <= 8, "Wrong argument type for ARG_FLOAT");
static_assert(sizeof(T) <= 8, "Invalid function argument type for ARG_FLOAT");
static __forceinline T func(PPUThread& CPU)
{
@ -46,7 +46,7 @@ namespace detail
template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_VECTOR, g_count, f_count, v_count>
{
static_assert(std::is_same<T, u128>::value, "Wrong argument type for ARG_VECTOR");
static_assert(std::is_same<T, u128>::value, "Invalid function argument type for ARG_VECTOR");
static __forceinline T func(PPUThread& CPU)
{
@ -57,11 +57,14 @@ namespace detail
template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_STACK, g_count, f_count, v_count>
{
static_assert(sizeof(T) <= 8 && v_count <= 12, "Wrong argument type for ARG_STACK");
static_assert(f_count <= 12, "TODO: Unsupported stack argument type (float)");
static_assert(v_count <= 12, "TODO: Unsupported stack argument type (vector)");
static_assert(sizeof(T) <= 8, "Invalid function argument type (ARG_STACK)");
static __forceinline T func(PPUThread& CPU)
{
const u64 res = CPU.GetStackArg(8 + std::max(g_count - 8, 0) + std::max(f_count - 12, 0));
// TODO: check stack argument displacement
const u64 res = CPU.GetStackArg(8 + std::max(g_count - 8, 0) + std::max(f_count - 12, 0) + std::max(v_count - 12, 0));
return (T&)res;
}
};
@ -69,18 +72,19 @@ namespace detail
template<typename T>
struct bind_result
{
static_assert(!std::is_pointer<T>::value, "Invalid function result type: pointer");
static_assert(sizeof(T) <= 8, "Invalid function result type");
static_assert(!std::is_pointer<T>::value, "Invalid function result type (pointer)");
static_assert(!std::is_reference<T>::value, "Invalid function result type (reference)");
static __forceinline void func(PPUThread& CPU, T value)
static __forceinline void func(PPUThread& CPU, T result)
{
if (std::is_floating_point<T>::value)
{
CPU.FPR[1] = (double)value;
CPU.FPR[1] = (double)result;
}
else
{
(T&)CPU.GPR[3] = value;
(T&)CPU.GPR[3] = result;
}
}
};
@ -88,9 +92,9 @@ namespace detail
template<>
struct bind_result<u128>
{
static __forceinline void func(PPUThread& CPU, u128 value)
static __forceinline void func(PPUThread& CPU, u128 result)
{
CPU.VPR[2] = value;
CPU.VPR[2] = result;
}
};
@ -128,7 +132,8 @@ namespace detail
template<int g_count, int f_count, int v_count, typename T, typename... A>
static __forceinline std::tuple<T, A...> iterate(PPUThread& CPU)
{
static_assert(!std::is_pointer<T>::value, "Invalid function argument type: pointer");
static_assert(!std::is_pointer<T>::value, "Invalid function argument type (pointer)");
static_assert(!std::is_reference<T>::value, "Invalid function argument type (reference)");
// TODO: check calculations
const bool is_float = std::is_floating_point<T>::value;
const bool is_vector = std::is_same<T, u128>::value;

View File

@ -377,6 +377,7 @@
<ClInclude Include="Emu\SysCalls\Modules\cellMsgDialog.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellPad.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellPamf.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellPng.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellPngDec.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellSail.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellResc.h" />

View File

@ -1210,5 +1210,8 @@
<ClInclude Include="define_new_memleakdetect.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Emu\SysCalls\Modules\cellPng.h">
<Filter>Emu\SysCalls\Modules</Filter>
</ClInclude>
</ItemGroup>
</Project>