diff --git a/source/gcunzip.cpp b/source/gcunzip.cpp
index 8b096ec..588ca90 100644
--- a/source/gcunzip.cpp
+++ b/source/gcunzip.cpp
@@ -212,23 +212,21 @@ GetFirstZipFilename ()
return NULL;
// read start of ZIP
- if(LoadFile (tempbuffer, filepath, ZIPCHUNK, NOTSILENT))
+ if(LoadFile (tempbuffer, filepath, ZIPCHUNK, NOTSILENT) < 35)
+ return NULL;
+
+ tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
+ int namelength = tempbuffer[26]; // filename length starts 26 bytes in
+
+ if(namelength < 0 || namelength > 200) // filename is not a reasonable length
{
- tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
- int namelength = tempbuffer[26]; // filename length starts 26 bytes in
-
- if(namelength > 0 && namelength < 200) // the filename is a reasonable length
- {
- firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
- firstFilename[namelength] = 0; // truncate at filename length
- }
- else
- {
- ErrorPrompt("Error - Invalid ZIP file!");
- }
+ ErrorPrompt("Error - Invalid ZIP file!");
+ return NULL;
}
-
- return firstFilename;
+
+ firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
+ firstFilename[namelength] = 0; // truncate at filename length
+ return strdup(firstFilename);
}
/****************************************************************************
diff --git a/source/utils/FreeTypeGX.cpp b/source/utils/FreeTypeGX.cpp
index f7a4c53..3cd8616 100644
--- a/source/utils/FreeTypeGX.cpp
+++ b/source/utils/FreeTypeGX.cpp
@@ -88,15 +88,54 @@ wchar_t* charToWideChar(const char* strChar)
return strWChar;
}
+static uint32_t* convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
+ uint32_t bufferSize = (bufferWidth * bufferHeight) << 2;
+ uint32_t* dataBufferRGBA8 = (uint32_t *)memalign(32, bufferSize);
+ memset(dataBufferRGBA8, 0x00, bufferSize);
+
+ uint8_t *src = (uint8_t *)rgbaBuffer;
+ uint8_t *dst = (uint8_t *)dataBufferRGBA8;
+
+ for(uint32_t block = 0; block < bufferHeight; block += 4) {
+ for(uint32_t i = 0; i < bufferWidth; i += 4) {
+ for (uint32_t c = 0; c < 4; c++) {
+ uint32_t blockWid = (((block + c) * bufferWidth)+i)<<2 ;
+
+ *dst++ = src[blockWid+ 3]; // ar = 0
+ *dst++ = src[blockWid+ 0];
+ *dst++ = src[blockWid+ 7]; // ar = 1
+ *dst++ = src[blockWid+ 4];
+ *dst++ = src[blockWid+ 11]; // ar = 2
+ *dst++ = src[blockWid+ 8];
+ *dst++ = src[blockWid+ 15]; // ar = 3
+ *dst++ = src[blockWid+ 12];
+ }
+ for (uint32_t c = 0; c < 4; c++) {
+ uint32_t blockWid = (((block + c) * bufferWidth)+i)<<2 ;
+
+ *dst++ = src[blockWid+ 1]; // gb = 0
+ *dst++ = src[blockWid+ 2];
+ *dst++ = src[blockWid+ 5]; // gb = 1
+ *dst++ = src[blockWid+ 6];
+ *dst++ = src[blockWid+ 9]; // gb = 2
+ *dst++ = src[blockWid+ 10];
+ *dst++ = src[blockWid+ 13]; // gb = 3
+ *dst++ = src[blockWid+ 14];
+ }
+ }
+ }
+ DCFlushRange(dataBufferRGBA8, bufferSize);
+
+ return dataBufferRGBA8;
+}
+
/**
* 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 vertexIndex Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
*/
-FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat, uint8_t vertexIndex)
+FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t vertexIndex)
{
- this->textureFormat = textureFormat;
this->setVertexFormat(vertexIndex);
this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
this->ftPointSize = pixelSize;
@@ -208,67 +247,15 @@ 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 FreeTypeGX::adjustTextureWidth(uint16_t textureWidth)
{
- 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;
- }
+ uint16_t alignment = 4;
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 FreeTypeGX::adjustTextureHeight(uint16_t textureHeight)
{
- 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;
- }
+ uint16_t alignment = 4;
return textureHeight % alignment == 0 ? textureHeight : alignment + textureHeight - (textureHeight % alignment);
}
@@ -293,8 +280,8 @@ ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode)
if(ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
FT_Bitmap *glyphBitmap = &ftSlot->bitmap;
- textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
- textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);
+ textureWidth = adjustTextureWidth(glyphBitmap->width);
+ textureHeight = adjustTextureHeight(glyphBitmap->rows);
this->fontData[charCode] = (ftgxCharData){
ftSlot->bitmap_left,
@@ -359,32 +346,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
glyphData[imagePosY * charData->textureWidth + imagePosX] = 0x00000000 | (pixel << 24) | (pixel << 16) | (pixel << 8) | pixel;
}
}
-
- switch(this->textureFormat)
- {
- case GX_TF_I4:
- charData->glyphDataTexture = Metaphrasis::convertBufferToI4(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_I8:
- charData->glyphDataTexture = Metaphrasis::convertBufferToI8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_IA4:
- charData->glyphDataTexture = Metaphrasis::convertBufferToIA4(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_IA8:
- charData->glyphDataTexture = Metaphrasis::convertBufferToIA8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGB565:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGB565(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGB5A3:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGB5A3(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- case GX_TF_RGBA8:
- default:
- charData->glyphDataTexture = Metaphrasis::convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
- break;
- }
+ charData->glyphDataTexture = convertBufferToRGBA8(glyphData, charData->textureWidth, charData->textureHeight);
free(glyphData);
}
@@ -498,7 +460,7 @@ uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, wchar_t *text, GXColor color
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_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
this->copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, color);
x_pos += glyphData->glyphAdvanceX;
diff --git a/source/utils/FreeTypeGX.h b/source/utils/FreeTypeGX.h
index 6a9d599..b5910f1 100644
--- a/source/utils/FreeTypeGX.h
+++ b/source/utils/FreeTypeGX.h
@@ -2,7 +2,7 @@
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
* FreeType parsable font into a GX texture for Wii homebrew development.
* Copyright (C) 2008 Armin Tamzarian
- * Modified by Tantric, 2009
+ * Modified by Tantric, 2009-2010
*
* This file is part of FreeTypeGX.
*
@@ -20,134 +20,6 @@
* along with FreeTypeGX. If not, see .
*/
-/** \mainpage FreeTypeGX
- *
- * \section sec_intro Introduction
- *
- * FreeTypeGX is a wrapper class for libFreeType which renders a compiled FreeType parsable font into a GX texture for Wii homebrew development.
- *
- * FreeTypeGX is written in C++ and makes use of a selectable pre-buffered or buffer-on-demand methodology to allow fast and efficient printing of text to the EFB.
- *
- * This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet.
- *
- * \section sec_installation_source Installation (Source Code)
- *
- * -# Ensure that you have the libFreeType Wii library installed in your development environment with the library added to your Makefile where appropriate.
- * -# Ensure that you have the Metaphrasis library installed in your development environment with the library added to your Makefile where appropriate.
- * -# Extract the FreeTypeGX archive.
- * -# Copy the contents of the src directory into your project's development path.
- * -# Include the FreeTypeGX header file in your code using syntax such as the following:
- * \code
- * #include "FreeTypeGX.h"
- * \endcode
- *
- * \section sec_installation_library Installation (Library)
- *
- * -# Ensure that you have the libFreeType Wii library installed in your development environment with the library added to your Makefile where appropriate.
- * -# Ensure that you have the Metaphrasis library installed in your development environment with the library added to your Makefile where appropriate.
- * -# Extract the FreeTypeGX archive.
- * -# Copy the contents of the lib directory into your devKitPro/libogc directory.
- * -# Include the FreeTypeGX header file in your code using syntax such as the following:
- * \code
- * #include "FreeTypeGX.h"
- * \endcode
- *
- * \section sec_freetypegx_prerequisites FreeTypeGX Prerequisites
- *
- * Before you begin using FreeTypeGX in your project you must ensure that the desired font in compiled into your project. For this example I will assume you are building your project with a Makefile using devKitPro evironment and are attempting to include a font whose filename is rursus_compact_mono.ttf.
- *
- * -# Copy the font into a directory which will be processed by the project's Makefile. If you are unsure about where you should place your font just copy the it into your project's source directory.
- * \n\n
- * -# Modify the Makefile to convert the font into an object file:
- * \code
- * %.ttf.o : %.ttf
- * @echo $(notdir $<)
- * $(bin2o)
- * \endcode
- * \n
- * -# Include the font object's generated header file in your source code:
- * \code
- * #include "rursus_compact_mono_ttf.h"
- * \endcode
- * This header file defines the two variables that you will need for use within your project:
- * \code
- * extern const u8 rursus_compact_mono_ttf[]; A pointer to the font buffer within the compiled project.
- * extern const u32 rursus_compact_mono_ttf_size; The size of the font's buffer in bytes.
- * \endcode
- *
- * \section sec_freetypegx_usage FreeTypeGX Usage
- *
- * -# Within the file you included the FreeTypeGX.h header create an instance object of the FreeTypeGX class:
- * \code
- * FreeTypeGX *freeTypeGX = new FreeTypeGX();
- * \endcode
- * Alternately you can specify a texture format to which you would like to render the font characters. Note that the default value for this parameter is GX_TF_RGBA8.
- * \code
- * FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565);
- * \endcode
- * Furthermore, you can also specify a vertex format index to avoid conflicts with concurrent libraries or other systems. Note that the default value for this parameter is GX_VTXFMT1.
- * \code
- * FreeTypeGX *freeTypeGX = new FreeTypeGX(GX_TF_RGB565, GX_VTXFMT1);
- * \endcode
- * \n
- * Currently supported textures are:
- * \li GX_TF_I4
- * \li GX_TF_I8
- * \li GX_TF_IA4
- * \li GX_TF_IA8
- * \li GX_TF_RGB565
- * \li GX_TF_RGB5A3
- * \li GX_TF_RGBA8
- *
- * \n
- * -# Using the allocated FreeTypeGX instance object call the loadFont function to load the font from the compiled buffer and specify the desired point size. Note that this function can be called multiple times to load a new:
- * \code
- * freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64);
- * \endcode
- * Alternately you can specify a flag which will load and cache all available font glyphs immidiately. Note that on large font sets enabling this feature could take a significant amount of time.
- * \code
- * freeTypeGX->loadFont(rursus_compact_mono_ttf, rursus_compact_mono_ttf_size, 64, true);
- * \endcode
- * \n
- * -# If necessary you can enable compatibility modes with concurrent libraries or systems. For more information on this feature see the documentation for setCompatibilityMode:
- * \code
- * freeTypeGX->setCompatibilityMode(FTGX_COMPATIBILITY_GRRLIB);
- * \endcode
- * -# Using the allocated FreeTypeGX instance object call the drawText function to print a string at the specified screen X and Y coordinates to the current EFB:
- * \code
- * freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"));
- * \endcode
- * Alternately you can specify a GXColor object you would like to apply to the printed characters:
- * \code
- * freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
- * (GXColor){0xff, 0xee, 0xaa, 0xff});
- * \endcode
- * Furthermore you can also specify a group of styling parameters which will modify the positioning or style of the text:
- * \code
- * freeTypeGX->drawText(10, 25, _TEXT("FreeTypeGX Rocks!"),
- * (GXColor){0xff, 0xee, 0xaa, 0xff},
- * FTGX_JUSTIFY_CENTER | FTGX_ALIGN_BOTTOM | FTGX_STYLE_UNDERLINE);
- * \endcode
- * \n
- * Currently style parameters are:
- * \li FTGX_JUSTIFY_LEFT
- * \li FTGX_JUSTIFY_CENTER
- * \li FTGX_JUSTIFY_RIGHT
- * \li FTGX_ALIGN_TOP
- * \li FTGX_ALIGN_MIDDLE
- * \li FTGX_ALIGN_BOTTOM
- * \li FTGX_STYLE_UNDERLINE
- * \li FTGX_STYLE_STRIKE
- *
- * \section sec_license License
- *
- * FreeTypeGX is distributed under the GNU Lesser General Public License.
- *
- * \section sec_contact Contact
- *
- * If you have any suggestions, questions, or comments regarding this library feel free to e-mail me at tamzarian1989 [at] gmail [dawt] com.
- */
-
#ifndef FREETYPEGX_H_
#define FREETYPEGX_H_
@@ -161,8 +33,6 @@
#include
#include