From 95823a776b2687a7fca9e08816ad897b17a8fbc8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 May 2013 21:13:50 -0700 Subject: [PATCH] Don't pass quite so many args to DrawCharacter(). --- Core/Font/PGF.cpp | 9 ++++++--- Core/Font/PGF.h | 13 ++++++++++++- Core/HLE/sceFont.cpp | 31 ++++--------------------------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 87754ab1e..90da78ad2 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -409,7 +409,7 @@ bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) { return true; } -void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType) { +void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) { Glyph glyph; if (!GetCharGlyph(charCode, glyphType, glyph)) { // No Glyph available for this charCode, try to use the alternate char. @@ -432,6 +432,9 @@ void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, i int numberPixels = glyph.w * glyph.h; int pixelIndex = 0; + int x = image->xPos64 >> 6; + int y = image->yPos64 >> 6; + while (pixelIndex < numberPixels && bitPtr + 8 < fontDataSize * 8) { // This is some kind of nibble based RLE compression. int nibble = getBits(4, fontData, bitPtr); @@ -467,7 +470,7 @@ void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, i if (pixelX >= clipX && pixelX < clipX + clipWidth && pixelY >= clipY && pixelY < clipY + clipHeight) { // 4-bit color value int pixelColor = value; - switch (pixelformat) { + switch (image->pixelFormat) { case PSP_FONT_PIXELFORMAT_8: // 8-bit color value pixelColor |= pixelColor << 4; @@ -486,7 +489,7 @@ void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, i break; } - SetFontPixel(base, bpl, bufWidth, bufHeight, pixelX, pixelY, pixelColor, pixelformat); + SetFontPixel(image->bufferPtr, image->bytesPerLine, image->bufWidth, image->bufHeight, pixelX, pixelY, pixelColor, image->pixelFormat); } pixelIndex++; diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index 3a133394e..5a0fa78be 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -108,6 +108,17 @@ struct Glyph { u32 ptr; }; +struct GlyphImage { + FontPixelFormat pixelFormat; + s32 xPos64; + s32 yPos64; + u16 bufWidth; + u16 bufHeight; + u16 bytesPerLine; + u16 pad; + u32 bufferPtr; +}; + #pragma pack(push,1) struct PGFHeader { @@ -243,7 +254,7 @@ public: bool GetCharInfo(int charCode, PGFCharInfo *ci); void GetFontInfo(PGFFontInfo *fi); - void DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType); + void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType); void DoState(PointerWrap &p); diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 224fef538..efe2986c7 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -57,17 +57,6 @@ struct FontNewLibParams { u32 ioFinishFuncAddr; }; -struct GlyphImage { - FontPixelFormat pixelFormat; - s32 xPos64; - s32 yPos64; - u16 bufWidth; - u16 bufHeight; - u16 bytesPerLine; - u16 pad; - u32 bufferPtr; -}; - struct FontRegistryEntry { int hSize; int vSize; @@ -840,13 +829,7 @@ int sceFontGetShadowImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) { int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { INFO_LOG(HLE, "sceFontGetCharGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr); - int pixelFormat = Memory::Read_U32(glyphImagePtr); - int xPos64 = Memory::Read_U32(glyphImagePtr+4); - int yPos64 = Memory::Read_U32(glyphImagePtr+8); - int bufWidth = Memory::Read_U16(glyphImagePtr+12); - int bufHeight = Memory::Read_U16(glyphImagePtr+14); - int bytesPerLine = Memory::Read_U16(glyphImagePtr+16); - int buffer = Memory::Read_U32(glyphImagePtr+20); + auto glyph = Memory::GetStruct(glyphImagePtr); LoadedFont *font = GetLoadedFont(fontHandle, false); if (!font) { @@ -854,20 +837,14 @@ int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { return 0; } int altCharCode = font->GetFontLib()->GetAltCharCode(); - font->GetPGF()->DrawCharacter(buffer, bytesPerLine, bufWidth, bufHeight, xPos64 >> 6, yPos64 >> 6, 0, 0, 8192, 8192, pixelFormat, charCode, altCharCode, FONT_PGF_CHARGLYPH); + font->GetPGF()->DrawCharacter(glyph, 0, 0, 8192, 8192, charCode, altCharCode, FONT_PGF_CHARGLYPH); return 0; } int sceFontGetCharGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePtr, int clipXPos, int clipYPos, int clipWidth, int clipHeight) { INFO_LOG(HLE, "sceFontGetCharGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); - int pixelFormat = Memory::Read_U32(glyphImagePtr); - int xPos64 = Memory::Read_U32(glyphImagePtr+4); - int yPos64 = Memory::Read_U32(glyphImagePtr+8); - int bufWidth = Memory::Read_U16(glyphImagePtr+12); - int bufHeight = Memory::Read_U16(glyphImagePtr+14); - int bytesPerLine = Memory::Read_U16(glyphImagePtr+16); - int buffer = Memory::Read_U32(glyphImagePtr+20); + auto glyph = Memory::GetStruct(glyphImagePtr); LoadedFont *font = GetLoadedFont(fontHandle, false); if (!font) { @@ -875,7 +852,7 @@ int sceFontGetCharGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePt return 0; } int altCharCode = font->GetFontLib()->GetAltCharCode(); - font->GetPGF()->DrawCharacter(buffer, bytesPerLine, bufWidth, bufHeight, xPos64 >> 6, yPos64 >> 6, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, pixelFormat, charCode, altCharCode, FONT_PGF_CHARGLYPH); + font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, charCode, altCharCode, FONT_PGF_CHARGLYPH); return 0; }