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

cellPngEnc

This commit is contained in:
Megamouse 2022-08-01 22:45:55 +02:00
parent 84a785ea67
commit cb0ecb2afb
3 changed files with 178 additions and 29 deletions

View File

@ -727,7 +727,7 @@ error_code cellHttpUtilFormUrlDecode(vm::ptr<u8> out, u32 size, vm::cptr<char> i
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
const auto FUN_00036710 = [](b8 c)
const auto check_char = [](b8 c)
{
u32 utmp = static_cast<u32>(c);
s32 stmp = utmp - 48;
@ -746,8 +746,8 @@ error_code cellHttpUtilFormUrlDecode(vm::ptr<u8> out, u32 size, vm::cptr<char> i
return stmp;
};
const s32 tmp1 = FUN_00036710(c2);
const s32 tmp2 = FUN_00036710(c3);
const s32 tmp1 = check_char(c2);
const s32 tmp2 = check_char(c3);
if (tmp1 < 0 || tmp2 < 0)
{

View File

@ -1,6 +1,8 @@
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "cellPngEnc.h"
#include "png.h"
LOG_CHANNEL(cellPngEnc);
@ -27,57 +29,199 @@ void fmt_class_string<CellPngEncError>::format(std::string& out, u64 arg)
});
}
struct png_encoder
{
shared_mutex mutex;
CellPngEncConfig config{};
CellPngEncResource resource{};
CellPngEncResourceEx resourceEx{};
};
bool check_config(vm::cptr<CellPngEncConfig> config)
{
if (!config ||
config->maxWidth == 0 || config->maxWidth > 1000000 ||
config->maxHeight == 0 || config->maxHeight > 1000000 ||
config->maxBitDepth != 8 && config->maxBitDepth != 16 ||
static_cast<s32>(config->addMemSize) < 0 ||
config->exParamNum != 0)
{
return false;
}
return true;
}
u32 get_mem_size(vm::cptr<CellPngEncConfig> config)
{
return config->addMemSize
+ (config->enableSpu ? 0x78200 : 0x47a00)
+ (config->maxBitDepth >> 1) * config->maxWidth * 7;
}
error_code cellPngEncQueryAttr(vm::cptr<CellPngEncConfig> config, vm::ptr<CellPngEncAttr> attr)
{
cellPngEnc.todo("cellPngEncQueryAttr(config=*0x%x, attr=*0x%x)", config, attr);
if (!attr || !check_config(config))
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 memsize = get_mem_size(config);
attr->memSize = memsize + 0x1780;
attr->cmdQueueDepth = 4;
attr->versionLower = 0;
attr->versionUpper = 0x270000;
return CELL_OK;
}
error_code cellPngEncOpen(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResource> resource, vm::pptr<void> handle)
error_code cellPngEncOpen(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResource> resource, vm::ptr<u32> handle)
{
cellPngEnc.todo("cellPngEncOpen(config=*0x%x, resource=*0x%x, handle=*0x%x)", config, resource, handle);
cellPngEnc.todo("cellPngEncOpen(config=*0x%x, resource=*0x%x, handle=0x%x)", config, resource, handle);
if (!handle || !check_config(config) ||
!resource || !resource->memAddr || !resource->memSize ||
resource->ppuThreadPriority < 0 || resource->ppuThreadPriority > 0xbff ||
resource->spuThreadPriority < 0 || resource->ppuThreadPriority > 0xff)
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 required_memsize = get_mem_size(config);
if (resource->memSize < required_memsize + 0x1780U)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
encoder.config = *config;
encoder.resource = *resource;
}
return CELL_OK;
}
error_code cellPngEncOpenEx(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResourceEx> resourceEx, vm::pptr<void> handle)
error_code cellPngEncOpenEx(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResourceEx> resource, vm::ptr<u32> handle)
{
cellPngEnc.todo("cellPngEncOpenEx(config=*0x%x, resourceEx=*0x%x, handle=*0x%x)", config, resourceEx, handle);
cellPngEnc.todo("cellPngEncOpenEx(config=*0x%x, resourceEx=*0x%x, handle=0x%x)", config, resource, handle);
if (!handle || !check_config(config) ||
!resource || !resource->memAddr || !resource->memSize ||
resource->ppuThreadPriority < 0 || resource->ppuThreadPriority > 0xbff ||
resource->priority[0] > 15 || resource->priority[1] > 15 ||
resource->priority[2] > 15 || resource->priority[3] > 15 ||
resource->priority[4] > 15 || resource->priority[5] > 15 ||
resource->priority[6] > 15 || resource->priority[7] > 15)
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 required_memsize = get_mem_size(config);
if (resource->memSize < required_memsize + 0x1780U)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
encoder.config = *config;
encoder.resourceEx = *resource;
}
return CELL_OK;
}
error_code cellPngEncClose(vm::ptr<void> handle)
error_code cellPngEncClose(u32 handle)
{
cellPngEnc.todo("cellPngEncClose(handle=*0x%x)", handle);
cellPngEnc.todo("cellPngEncClose(handle=0x%x)", handle);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncWaitForInput(vm::ptr<void> handle, b8 block)
error_code cellPngEncWaitForInput(u32 handle, b8 block)
{
cellPngEnc.todo("cellPngEncWaitForInput(handle=*0x%x, block=%d)", handle, block);
cellPngEnc.todo("cellPngEncWaitForInput(handle=0x%x, block=%d)", handle, block);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncEncodePicture(vm::ptr<void> handle, vm::cptr<CellPngEncPicture> picture, vm::cptr<CellPngEncEncodeParam> encodeParam, vm::cptr<CellPngEncOutputParam> outputParam)
error_code cellPngEncEncodePicture(u32 handle, vm::cptr<CellPngEncPicture> picture, vm::cptr<CellPngEncEncodeParam> encodeParam, vm::cptr<CellPngEncOutputParam> outputParam)
{
cellPngEnc.todo("cellPngEncEncodePicture(handle=*0x%x, picture=*0x%x, encodeParam=*0x%x, outputParam=*0x%x)", handle, picture, encodeParam, outputParam);
cellPngEnc.todo("cellPngEncEncodePicture(handle=0x%x, picture=*0x%x, encodeParam=*0x%x, outputParam=*0x%x)", handle, picture, encodeParam, outputParam);
if (!handle || !picture || !picture->width || !picture->height ||
(picture->packedPixel && picture->bitDepth >= 8) ||
!picture->pictureAddr || picture->colorSpace > CELL_PNGENC_COLOR_SPACE_ARGB)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
if (picture->width > encoder.config.maxWidth ||
picture->height > encoder.config.maxHeight ||
picture->bitDepth > encoder.config.maxBitDepth)
{
return CELL_PNGENC_ERROR_ARG;
}
}
return CELL_OK;
}
error_code cellPngEncWaitForOutput(vm::ptr<void> handle, vm::ptr<u32> streamInfoNum, b8 block)
error_code cellPngEncWaitForOutput(u32 handle, vm::ptr<u32> streamInfoNum, b8 block)
{
cellPngEnc.todo("cellPngEncWaitForOutput(handle=*0x%x, streamInfoNum=*0x%x, block=%d)", handle, streamInfoNum, block);
cellPngEnc.todo("cellPngEncWaitForOutput(handle=0x%x, streamInfoNum=*0x%x, block=%d)", handle, streamInfoNum, block);
if (!handle || !streamInfoNum)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncGetStreamInfo(vm::ptr<void> handle, vm::ptr<CellPngEncStreamInfo> streamInfo)
error_code cellPngEncGetStreamInfo(u32 handle, vm::ptr<CellPngEncStreamInfo> streamInfo)
{
cellPngEnc.todo("cellPngEncGetStreamInfo(handle=*0x%x, streamInfo=*0x%x)", handle, streamInfo);
cellPngEnc.todo("cellPngEncGetStreamInfo(handle=0x%x, streamInfo=*0x%x)", handle, streamInfo);
if (!handle || !streamInfo)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncReset(vm::ptr<void> handle)
error_code cellPngEncReset(u32 handle)
{
cellPngEnc.todo("cellPngEncReset(handle=*0x%x)", handle);
cellPngEnc.todo("cellPngEncReset(handle=0x%x)", handle);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}

View File

@ -78,32 +78,34 @@ enum CellPngEncLocation
//typedef void *CellPngEncHandle;
struct CellPngEncExParam
struct CellPngEncExParam // Size 8
{
be_t<s32> index;
vm::bptr<s32> value;
};
struct CellPngEncConfig
struct CellPngEncConfig // Size 28
{
be_t<u32> maxWidth;
be_t<u32> maxHeight;
be_t<u32> maxBitDepth;
b8 enableSpu;
u8 padding[3];
be_t<u32> addMemSize;
vm::bptr<CellPngEncExParam> exParamList;
be_t<u32> exParamNum;
};
struct CellPngEncAttr
struct CellPngEncAttr // Size 16
{
be_t<u32> memSize; // usz
u8 cmdQueueDepth;
u8 padding[3];
be_t<u32> versionUpper;
be_t<u32> versionLower;
};
struct CellPngEncResource
struct CellPngEncResource // Size 16
{
vm::bptr<void> memAddr;
be_t<u32> memSize; // usz
@ -111,7 +113,7 @@ struct CellPngEncResource
be_t<s32> spuThreadPriority;
};
struct CellPngEncResourceEx
struct CellPngEncResourceEx // Size 24
{
vm::bptr<void> memAddr;
be_t<u32> memSize; // usz
@ -120,7 +122,7 @@ struct CellPngEncResourceEx
u8 priority[8];
};
struct CellPngEncPicture
struct CellPngEncPicture // Size 40
{
be_t<u32> width;
be_t<u32> height;
@ -128,19 +130,21 @@ struct CellPngEncPicture
be_t<u32> colorSpace; // CellPngEncColorSpace
be_t<u32> bitDepth;
b8 packedPixel;
u8 padding[3]; // TODO: is this correct?
vm::bptr<void> pictureAddr;
be_t<u64> userData;
};
struct CellPngEncAncillaryChunk
struct CellPngEncAncillaryChunk // Size 8
{
be_t<u32> chunkType; // CellPngEncChunkType
vm::bptr<void> chunkData;
};
struct CellPngEncEncodeParam
struct CellPngEncEncodeParam // Size 24
{
b8 enableSpu;
u8 padding[3];
be_t<u32> encodeColorSpace; // CellPngEncColorSpace
be_t<u32> compressionLevel; // CellPngEncCompressionLevel
be_t<u32> filterType;
@ -148,7 +152,7 @@ struct CellPngEncEncodeParam
be_t<u32> ancillaryChunkNum;
};
struct CellPngEncOutputParam
struct CellPngEncOutputParam // Size 16
{
be_t<u32> location; // CellPngEncLocation
vm::bcptr<char> streamFileName;
@ -156,7 +160,7 @@ struct CellPngEncOutputParam
be_t<u32> limitSize; // usz
};
struct CellPngEncStreamInfo
struct CellPngEncStreamInfo // Size 40
{
be_t<s32> state;
be_t<u32> location; // CellPngEncLocation
@ -166,4 +170,5 @@ struct CellPngEncStreamInfo
be_t<u32> streamSize; // usz
be_t<u32> processedLine;
be_t<u64> userData;
// TODO: where are the missing 4 bytes?
};