Keybord support improved

*Improved Keyboard:
- Fixed crash when using Null keyboard handler
- Added support for meta keys
- Added support for {caps, num, scroll} lock.

*Small issues fixed in previous module:
- cellGifDec: Fixed wrong information of packet field in
cellGifDecReadHeader.
- cellGifDec: Set DataOutInfo.recordType as 1 since the output is always
an image.
- cellJpgDec: Set colorSpace as 3, until a better function is
implemented.
- cellJpgDec, cellPngDec: Added RGBA support.

*Changed layout of "Config > Settings" menu.
This commit is contained in:
Alexandro Sánchez Bach 2013-09-13 19:29:54 +02:00
parent 4835ae35af
commit 1b7302c0ba
8 changed files with 262 additions and 74 deletions

View file

@ -22,6 +22,16 @@ enum
CELL_PNGDEC_ERROR_CB_PARAM = 0x8061120a,
};
enum CellPngDecColorSpace
{
CELL_PNGDEC_GRAYSCALE = 1,
CELL_PNGDEC_RGB = 2,
CELL_PNGDEC_PALETTE = 4,
CELL_PNGDEC_GRAYSCALE_ALPHA = 9,
CELL_PNGDEC_RGBA = 10,
CELL_PNGDEC_ARGB = 20,
};
struct CellPngDecInfo
{
u32 imageWidth;
@ -44,6 +54,36 @@ struct CellPngDecSrc
u32 spuThreadEnable; // CellPngDecSpuThreadEna
};
struct CellPngDecInParam
{
u32 *commandPtr;
u32 outputMode; // CellPngDecOutputMode
u32 outputColorSpace; // CellPngDecColorSpace
u32 outputBitDepth;
u32 outputPackFlag; // CellPngDecPackFlag
u32 outputAlphaSelect; // CellPngDecAlphaSelect
u32 outputColorAlpha;
};
struct CellPngDecOutParam
{
u64 outputWidthByte;
u32 outputWidth;
u32 outputHeight;
u32 outputComponents;
u32 outputBitDepth;
u32 outputMode; // CellPngDecOutputMode
u32 outputColorSpace; // CellPngDecColorSpace
u32 useMemorySpace;
};
struct CellPngDecSubHandle //Custom struct
{
u32 fd;
u64 fileSize;
CellPngDecInParam inParam;
};
CellPngDecInfo current_info;
CellPngDecSrc current_src;
@ -70,30 +110,41 @@ int cellPngDecOpen(u32 mainHandle, u32 subHandle_addr, u32 src_addr, u32 openInf
//current_src.streamSize = Memory.Read32(src_addr+20);
//current_src.spuThreadEnable = Memory.Read32(src_addr+24);
u32& fd_addr = subHandle_addr; // Set file descriptor as sub handler of the decoder
CellPngDecSubHandle *subHandle = new CellPngDecSubHandle;
// 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);
Memory.Free(fd_addr);
if(ret != 0) return CELL_PNGDEC_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
Memory.Free(sb_addr);
// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
Memory.Write32(subHandle_addr, (u32)subHandle);
return CELL_OK;
}
int cellPngDecClose(u32 mainHandle, u32 subHandle)
{
u32& fd = subHandle;
cellFsClose(fd);
cellFsClose( ((CellPngDecSubHandle*)subHandle)->fd );
delete (CellPngDecSubHandle*)subHandle;
return CELL_OK;
}
int cellPngDecReadHeader(u32 mainHandle, u32 subHandle, u32 info_addr)
{
u32& fd = subHandle;
const u32& fd = ((CellPngDecSubHandle*)subHandle)->fd;
const u64& fileSize = ((CellPngDecSubHandle*)subHandle)->fileSize;
//Check size of file
u32 sb_addr = Memory.Alloc(52,1); // Alloc a CellFsStat struct
cellFsFstat(fd, sb_addr);
u64 fileSize = Memory.Read64(sb_addr+36); // Get CellFsStat.st_size
Memory.Free(sb_addr);
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
@ -134,17 +185,13 @@ int cellPngDecReadHeader(u32 mainHandle, u32 subHandle, u32 info_addr)
int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataCtrlParam_addr, u32 dataOutInfo_addr)
{
u32& fd = subHandle;
//Get size of file
u32 sb_addr = Memory.Alloc(52,1); // Alloc a CellFsStat struct
cellFsFstat(fd, sb_addr);
u64 fileSize = Memory.Read64(sb_addr+36); // Get CellFsStat.st_size
Memory.Free(sb_addr);
const u32& fd = ((CellPngDecSubHandle*)subHandle)->fd;
const u64& fileSize = ((CellPngDecSubHandle*)subHandle)->fileSize;
const CellPngDecInParam& inParam = ((CellPngDecSubHandle*)subHandle)->inParam; // (TODO: We should use the outParam)
//Copy the PNG file to a buffer
u32 buffer = Memory.Alloc(fileSize,1);
u32 pos_addr = Memory.Alloc(8,1);
u32 pos_addr = Memory.Alloc(sizeof(u64),1);
cellFsLseek(fd, 0, 0, pos_addr);
cellFsRead(fd, buffer, fileSize, NULL);
Memory.Free(pos_addr);
@ -163,20 +210,34 @@ int cellPngDecDecodeData(u32 mainHandle, u32 subHandle, u32 data_addr, u32 dataC
return CELL_PNGDEC_ERROR_STREAM_FORMAT;
}
u32 image_size = width * height * 4;
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]);
if (inParam.outputColorSpace == CELL_PNGDEC_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]);
}
}
else if (inParam.outputColorSpace == CELL_PNGDEC_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]);
}
}
Memory.Free(buffer);
return CELL_OK;
}
int cellPngDecSetParameter(u32 mainHandle, u32 subHandle, u32 inParam, u32 outParam)
int cellPngDecSetParameter(u32 mainHandle, u32 subHandle, u32 inParam_addr, u32 outParam_addr)
{
UNIMPLEMENTED_FUNC(cellPngDec);
CellPngDecInParam& inParam = ((CellPngDecSubHandle*)subHandle)->inParam;
inParam.outputColorSpace = Memory.Read32(inParam_addr+8);
// (TODO)
return CELL_OK;
}