*Made "No Gameinfo" translatable -> gameinfo6

*Update FreetypeGX with I4 optimizations(thx Dimok), also cleaned it up
This commit is contained in:
fedeanto11 2012-09-05 15:51:09 +00:00
parent f8a0d4891b
commit c5dbc32d10
3 changed files with 34 additions and 103 deletions

View File

@ -24,15 +24,12 @@
/**
* Default constructor for the FreeTypeGX class.
*
* @param textureFormat Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
* @param positionFormat Optional positional format (GX_POS_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_POS_XYZ.
*/
FreeTypeGX::FreeTypeGX(uint8_t textureFormat, uint8_t positionFormat)
FreeTypeGX::FreeTypeGX(uint8_t positionFormat)
{
FT_Init_FreeType(&this->ftLibrary);
this->textureFormat = textureFormat;
this->positionFormat = positionFormat;
reset();
this->ftFace = 0;
@ -133,70 +130,6 @@ void FreeTypeGX::unloadFont()
this->fontData.clear();
}
/**
* Adjusts the texture data buffer to necessary width for a given texture format.
*
* This routine determines adjusts the given texture width into the required width to hold the necessary texture data for proper alignment.
*
* @param textureWidth The initial guess for the texture width.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture width.
*/
uint16_t FreeTypeGX::adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat)
{
uint16_t alignment;
switch(textureFormat) {
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
alignment = 8;
break;
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureWidth % alignment == 0 ? textureWidth : alignment + textureWidth - (textureWidth % alignment);
}
/**
* Adjusts the texture data buffer to necessary height for a given texture format.
*
* This routine determines adjusts the given texture height into the required height to hold the necessary texture data for proper alignment.
*
* @param textureHeight The initial guess for the texture height.
* @param textureFormat The texture format to which the data is to be converted.
* @return The correctly adjusted texture height.
*/
uint16_t FreeTypeGX::adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat)
{
uint16_t alignment;
switch(textureFormat) {
case GX_TF_I4: /* 8x8 Tiles - 4-bit Intensity */
alignment = 8;
break;
case GX_TF_I8: /* 8x4 Tiles - 8-bit Intensity */
case GX_TF_IA4: /* 8x4 Tiles - 4-bit Intensity, , 4-bit Alpha */
case GX_TF_IA8: /* 4x4 Tiles - 8-bit Intensity, 8-bit Alpha */
case GX_TF_RGB565: /* 4x4 Tiles - RGB565 Format */
case GX_TF_RGB5A3: /* 4x4 Tiles - RGB5A3 Format */
case GX_TF_RGBA8: /* 4x4 Tiles - RGBA8 Dual Cache Line Format */
default:
alignment = 4;
break;
}
return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
}
/**
* Caches the given font glyph in the instance font texture buffer.
*
@ -221,8 +154,8 @@ ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode)
FT_Bitmap *glyphBitmap = &this->ftSlot->bitmap;
FT_Bitmap_Embolden(this->ftLibrary, glyphBitmap, this->ftWeight, this->ftWeight);
textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
textureWidth = glyphBitmap->width % 8 == 0 ? glyphBitmap->width : 8 + glyphBitmap->width - (glyphBitmap->width % 8);
textureHeight = glyphBitmap->rows % 8 == 0 ? glyphBitmap->rows : 8 + glyphBitmap->rows - (glyphBitmap->rows % 8);
this->fontData[charCode] = (ftgxCharData)
{
@ -274,35 +207,43 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete()
*
* @param bmp A pointer to the most recently rendered glyph's bitmap.
* @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph.
*
* Optimized for RGBA8 use by Dimok.
*/
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
{
int length = charData->textureWidth * charData->textureHeight * 4;
int glyphSize = (charData->textureWidth * charData->textureHeight) >> 1;
uint8_t * glyphData = (uint8_t *) MEM2_alloc(length);
if(!glyphData) return;
memset(glyphData, 0x00, length);
uint8_t *glyphData = (uint8_t *) MEM2_alloc(glyphSize);
if(glyphData < 0)
return;
memset(glyphData, 0x00, glyphSize);
uint8_t *src = (uint8_t *)bmp->buffer;
uint32_t offset;
uint8_t *dst = glyphData;
int32_t pos, x1, y1, x, y;
for (int imagePosY = 0; imagePosY < bmp->rows; ++imagePosY)
for(y1 = 0; y1 < bmp->rows; y1 += 8)
{
for (int imagePosX = 0; imagePosX < bmp->width; ++imagePosX)
for(x1 = 0; x1 < bmp->width; x1 += 8)
{
offset = ((((imagePosY >> 2) * (charData->textureWidth >> 2) + (imagePosX >> 2)) << 5) + ((imagePosY & 3) << 2) + (imagePosX & 3)) << 1;
glyphData[offset] = *src;
glyphData[offset+1] = *src;
glyphData[offset+32] = *src;
glyphData[offset+33] = *src;
++src;
for(y = y1; y < (y1 + 8); y++)
{
for(x = x1; x < (x1 + 8); x += 2, dst++)
{
if(x >= bmp->width || y >= bmp->rows)
continue;
pos = y * bmp->width + x;
*dst = (src[pos] & 0xF0);
if(x+1 < bmp->width)
*dst |= (src[pos + 1] >> 4);
}
}
DCFlushRange(glyphData, length);
charData->glyphDataTexture = (uint32_t *) glyphData;
}
}
DCFlushRange(glyphData, glyphSize);
charData->glyphDataTexture = glyphData;
}
/**
@ -388,7 +329,7 @@ uint16_t FreeTypeGX::drawText(uint16_t x, uint16_t y, wchar_t *text, GXColor col
x_pos += pairDelta.x >> 6;
}
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, this->textureFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, GX_TF_I4, GX_CLAMP, GX_CLAMP, GX_FALSE);
this->copyTextureToFramebuffer(&glyphTexture, this->positionFormat, glyphData->textureWidth, glyphData->textureHeight, x_pos - x_offset, y - glyphData->renderOffsetY - y_offset, color);
x_pos += glyphData->glyphAdvanceX;

View File

@ -177,7 +177,7 @@ typedef struct ftgxCharData_ {
uint16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
uint16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
uint32_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
uint8_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
} ftgxCharData;
/*! \struct ftgxDataOffset_
@ -228,13 +228,9 @@ class FreeTypeGX {
float xPos;
float yPos;
uint8_t textureFormat; /**< Defined texture format of the target EFB. */
uint8_t positionFormat; /**< Defined position format of the texture. */
std::map<wchar_t, ftgxCharData> fontData; /**< Map which holds the glyph data structures for the corresponding characters. */
static uint16_t adjustTextureWidth(uint16_t textureWidth, uint8_t textureFormat);
static uint16_t adjustTextureHeight(uint16_t textureHeight, uint8_t textureFormat);
static uint16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
static uint16_t getStyleOffsetHeight(ftgxDataOffset offset, uint16_t format);
@ -248,7 +244,7 @@ class FreeTypeGX {
void drawTextFeature(uint16_t x, uint16_t y, uint16_t width, ftgxDataOffset offsetData, uint16_t format, GXColor color);
public:
FreeTypeGX(uint8_t textureFormat = GX_TF_RGBA8, uint8_t positionFormat = GX_POS_XYZ);
FreeTypeGX(uint8_t positionFormat = GX_POS_XYZ);
~FreeTypeGX();
static wchar_t* charToWideChar(char* p);

View File

@ -1,4 +1,3 @@
#include "menu.hpp"
#include "gui/GameTDB.hpp"
@ -546,9 +545,6 @@ void CMenu::_textGameInfo(void)
cnt_controlsreq = x;
//for(unsigned int i = 0;i<ARRAY_SIZE(m_gameinfoLblControlsReq);i++)
//m_btnMgr.setTexture(m_gameinfoLblControlsReq[i] ,m_controlsreq[i]);
//check optional controlls
wiimote=0,
nunchuk=0,
@ -680,11 +676,9 @@ void CMenu::_textGameInfo(void)
}
cnt_controls = x;
//for(unsigned int i = 0;i<ARRAY_SIZE(m_gameinfoLblControls);i++)
//m_btnMgr.setTexture(m_gameinfoLblControls[i] ,m_controls[i]);
}
else
m_btnMgr.setText(m_gameinfoLblTitle, wfmt(L"%s", "No Gameinfo"), true);
m_btnMgr.setText(m_gameinfoLblTitle, wfmt(_fmt("gameinfo6",L"No Gameinfo"), true));
gametdb.CloseFile();