Improved image dec. modules & New dummy modules

* Improved image decoding modules:
- Fixed error that appeared after last commit (eebe859f83).
- Changed some functions to use the mem*_t classes.
- Implemented cell*DecSetParameter.

* Created new dummy modules for sys_net (0x0000), sys_http (0x0001),
cellHttpUtil (0x0002) and cellSsl (0x0003).
This commit is contained in:
Alexandro Sánchez Bach 2013-09-25 15:43:55 +02:00
parent eebe859f83
commit 1a85ccbbf4
9 changed files with 1589 additions and 124 deletions

View file

@ -74,12 +74,10 @@ struct CellGifDecSubHandle //Custom struct
{
u32 fd;
u64 fileSize;
CellGifDecInParam inParam;
CellGifDecInfo info;
CellGifDecOutParam outParam;
};
CellGifDecInfo current_info;
CellGifDecSrc current_src;
int cellGifDecCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam)
{
@ -93,47 +91,50 @@ int cellGifDecExtCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam, u
return CELL_OK;
}
int cellGifDecOpen(u32 mainHandle, u32 subHandle_addr, u32 src_addr, u32 openInfo)
int cellGifDecOpen(u32 mainHandle, mem32_t subHandle, u32 src_addr, u32 openInfo)
{
//current_src.srcSelect = Memory.Read32(src_addr);
current_src.fileName = Memory.Read32(src_addr+4);
//current_src.fileOffset = Memory.Read32(src_addr+8);
//current_src.fileSize = Memory.Read32(src_addr+12);
//current_src.streamPtr = Memory.Read32(src_addr+16);
//current_src.streamSize = Memory.Read32(src_addr+20);
//current_src.spuThreadEnable = Memory.Read32(src_addr+24);
//u32 srcSelect = Memory.Read32(src_addr);
u32 fileName = Memory.Read32(src_addr+4);
//u64 fileOffset = Memory.Read32(src_addr+8);
//u32 fileSize = Memory.Read32(src_addr+12);
//u32 streamPtr = Memory.Read32(src_addr+16);
//u32 streamSize = Memory.Read32(src_addr+20);
//u32 spuThreadEnable = Memory.Read32(src_addr+24);
CellGifDecSubHandle *subHandle = new CellGifDecSubHandle;
CellGifDecSubHandle *current_subHandle = new CellGifDecSubHandle;
// Get file descriptor
u32 fd_addr = Memory.Alloc(sizeof(u32), 1);
int ret = cellFsOpen(current_src.fileName, 0, fd_addr, NULL, 0);
subHandle->fd = Memory.Read32(fd_addr);
int ret = cellFsOpen(fileName, 0, fd_addr, NULL, 0);
current_subHandle->fd = Memory.Read32(fd_addr);
Memory.Free(fd_addr);
if(ret != 0) return CELL_GIFDEC_ERROR_OPEN_FILE;
// Get size of file
u32 sb_addr = Memory.Alloc(52,1); // Alloc a CellFsStat struct
cellFsFstat(subHandle->fd, sb_addr);
subHandle->fileSize = Memory.Read64(sb_addr+36); // Get CellFsStat.st_size
cellFsFstat(current_subHandle->fd, sb_addr);
current_subHandle->fileSize = Memory.Read64(sb_addr+36); // Get CellFsStat.st_size
Memory.Free(sb_addr);
// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
Memory.Write32(subHandle_addr, (u32)subHandle);
subHandle += (u32)current_subHandle;
return CELL_OK;
}
int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, u32 info_addr)
int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, mem_class_t info)
{
const u32& fd = ((CellGifDecSubHandle*)subHandle)->fd;
const u64& fileSize = ((CellGifDecSubHandle*)subHandle)->fileSize;
CellGifDecInfo& current_info = ((CellGifDecSubHandle*)subHandle)->info;
//Write the header to buffer
u32 buffer = Memory.Alloc(13,1); // Alloc buffer for GIF header
u32 nread = Memory.Alloc(8,1);
u32 pos_addr = Memory.Alloc(8,1);
cellFsLseek(fd, 0, 0, pos_addr);
cellFsRead(fd, buffer, 13, NULL);
cellFsRead(fd, buffer, 13, nread);
Memory.Free(nread);
Memory.Free(pos_addr);
if (Memory.Read32(buffer) != 0x47494638 ||
@ -154,7 +155,6 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, u32 info_addr)
current_info.SBackGroundColor = Memory.Read8(buffer+11);
current_info.SPixelAspectRatio = Memory.Read8(buffer+12);
mem_class_t info(info_addr);
info += current_info.SWidth;
info += current_info.SHeight;
info += current_info.SGlobalColorTableFlag;
@ -168,27 +168,48 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, u32 info_addr)
return CELL_OK;
}
int cellGifDecSetParameter(u32 mainHandle, u32 subHandle, u32 inParam_addr, u32 outParam_addr)
int cellGifDecSetParameter(u32 mainHandle, u32 subHandle, u32 inParam_addr, mem_class_t outParam)
{
CellGifDecInParam& inParam = ((CellGifDecSubHandle*)subHandle)->inParam;
inParam.colorSpace = Memory.Read32(inParam_addr+4);
CellGifDecInfo& current_info = ((CellGifDecSubHandle*)subHandle)->info;
CellGifDecOutParam& current_outParam = ((CellGifDecSubHandle*)subHandle)->outParam;
current_outParam.outputWidthByte = (current_info.SWidth * current_info.SColorResolution * 3)/8;
current_outParam.outputWidth = current_info.SWidth;
current_outParam.outputHeight = current_info.SHeight;
current_outParam.outputColorSpace = Memory.Read32(inParam_addr+4);
switch (current_outParam.outputColorSpace)
{
case CELL_GIFDEC_RGBA: current_outParam.outputComponents = 4; break;
case CELL_GIFDEC_ARGB: current_outParam.outputComponents = 4; break;
default: return CELL_GIFDEC_ERROR_ARG; // Not supported color space
}
current_outParam.outputBitDepth = 0; // Unimplemented
current_outParam.useMemorySpace = 0; // Unimplemented
// (TODO)
outParam += current_outParam.outputWidthByte;
outParam += current_outParam.outputWidth;
outParam += current_outParam.outputHeight;
outParam += current_outParam.outputComponents;
outParam += current_outParam.outputBitDepth;
outParam += current_outParam.outputColorSpace;
outParam += current_outParam.useMemorySpace;
return CELL_OK;
}
int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataCtrlParam_addr, u32 dataOutInfo_addr)
int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, mem8_ptr_t data, u32 dataCtrlParam_addr, mem_class_t dataOutInfo)
{
const u32& fd = ((CellGifDecSubHandle*)subHandle)->fd;
const u64& fileSize = ((CellGifDecSubHandle*)subHandle)->fileSize;
const CellGifDecInParam& inParam = ((CellGifDecSubHandle*)subHandle)->inParam; // (TODO: We should use the outParam)
const CellGifDecOutParam& current_outParam = ((CellGifDecSubHandle*)subHandle)->outParam; // (TODO: We should use the outParam)
//Copy the GIF file to a buffer
u32 buffer = Memory.Alloc(fileSize,1);
u32 nread = Memory.Alloc(8,1);
u32 pos_addr = Memory.Alloc(8,1);
cellFsLseek(fd, 0, 0, pos_addr);
cellFsRead(fd, buffer, fileSize, NULL);
cellFsRead(fd, buffer, fileSize, nread);
Memory.Free(nread);
Memory.Free(pos_addr);
//Decode GIF file. (TODO: Is there any faster alternative? Can we do it without external libraries?)
@ -199,29 +220,27 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataC
if (!image) return CELL_GIFDEC_ERROR_STREAM_FORMAT;
u32 image_size = width * height * 4;
if (inParam.colorSpace == CELL_GIFDEC_RGBA){
if (current_outParam.outputColorSpace == CELL_GIFDEC_RGBA){
for(u32 i = 0; i < image_size; i+=4){
Memory.Write8(data_addr+i+0, image[i+0]);
Memory.Write8(data_addr+i+1, image[i+1]);
Memory.Write8(data_addr+i+2, image[i+2]);
Memory.Write8(data_addr+i+3, image[i+3]);
data += image[i+0];
data += image[i+1];
data += image[i+2];
data += image[i+3];
}
}
if (inParam.colorSpace == CELL_GIFDEC_ARGB){
if (current_outParam.outputColorSpace == CELL_GIFDEC_ARGB){
for(u32 i = 0; i < image_size; i+=4){
Memory.Write8(data_addr+i+0, image[i+3]);
Memory.Write8(data_addr+i+1, image[i+0]);
Memory.Write8(data_addr+i+2, image[i+1]);
Memory.Write8(data_addr+i+3, image[i+2]);
data += image[i+3];
data += image[i+0];
data += image[i+1];
data += image[i+2];
}
}
delete[] image;
//The output data is an image (dataOutInfo.recordType = 1)
Memory.Write32(dataOutInfo_addr, 1);
u32 outExtensionData_addr = Memory.Alloc(20,1); // (TODO: Is this the best way to avoid exceptions when trying to access this data? Will this produce a memory leak?)
Memory.Write32(dataOutInfo_addr+8, outExtensionData_addr);
dataOutInfo += (u32)1; // The output data is an image (dataOutInfo.recordType = 1)
dataOutInfo += (u32)0; // outExtension.label = 0
dataOutInfo += Memory.Alloc(20,1); // outExtension.data allocated (TODO: Is this the best way to avoid exceptions when trying to access this data? Will this produce a memory leak?)
return CELL_OK;
}