mirror of
https://github.com/dborth/vbagx.git
synced 2024-12-27 03:01:50 +01:00
code cleanup
This commit is contained in:
parent
d5c73256aa
commit
fdf9271890
@ -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);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -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;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \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.
|
||||
* <br>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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 <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
|
||||
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
|
||||
* -# Extract the FreeTypeGX archive.
|
||||
* -# Copy the contents of the <i>src</i> 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 <a href = "http://www.tehskeen.com/forums/showthread.php?t=9404">libFreeType</a> Wii library installed in your development environment with the library added to your Makefile where appropriate.
|
||||
* -# Ensure that you have the <a href = "http://code.google.com/p/metaphrasis">Metaphrasis</a> library installed in your development environment with the library added to your Makefile where appropriate.
|
||||
* -# Extract the FreeTypeGX archive.
|
||||
* -# Copy the contents of the <i>lib</i> directory into your <i>devKitPro/libogc</i> 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 <i>GX_TF_I4</i>
|
||||
* \li <i>GX_TF_I8</i>
|
||||
* \li <i>GX_TF_IA4</i>
|
||||
* \li <i>GX_TF_IA8</i>
|
||||
* \li <i>GX_TF_RGB565</i>
|
||||
* \li <i>GX_TF_RGB5A3</i>
|
||||
* \li <i>GX_TF_RGBA8</i>
|
||||
*
|
||||
* \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 <i>GXColor</i> 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 <i>FTGX_JUSTIFY_LEFT</i>
|
||||
* \li <i>FTGX_JUSTIFY_CENTER</i>
|
||||
* \li <i>FTGX_JUSTIFY_RIGHT</i>
|
||||
* \li <i>FTGX_ALIGN_TOP</i>
|
||||
* \li <i>FTGX_ALIGN_MIDDLE</i>
|
||||
* \li <i>FTGX_ALIGN_BOTTOM</i>
|
||||
* \li <i>FTGX_STYLE_UNDERLINE</i>
|
||||
* \li <i>FTGX_STYLE_STRIKE</i>
|
||||
*
|
||||
* \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 <wchar.h>
|
||||
#include <map>
|
||||
|
||||
#include "Metaphrasis.h"
|
||||
|
||||
#define MAX_FONT_SIZE 100
|
||||
|
||||
/*! \struct ftgxCharData_
|
||||
@ -256,14 +126,12 @@ class FreeTypeGX {
|
||||
private:
|
||||
FT_UInt ftPointSize; /**< Requested size of the rendered font. */
|
||||
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||
|
||||
uint8_t textureFormat; /**< Defined texture format of the target EFB. */
|
||||
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
||||
uint32_t compatibilityMode; /**< Compatibility mode for default tev operations and vertex descriptors. */
|
||||
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 adjustTextureWidth(uint16_t textureWidth);
|
||||
static uint16_t adjustTextureHeight(uint16_t textureHeight);
|
||||
|
||||
static int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||
static int16_t getStyleOffsetHeight(ftgxDataOffset *offset, uint16_t format);
|
||||
@ -280,7 +148,7 @@ class FreeTypeGX {
|
||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, GXColor color);
|
||||
|
||||
public:
|
||||
FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat = GX_TF_RGBA8, uint8_t vertexIndex = GX_VTXFMT1);
|
||||
FreeTypeGX(FT_UInt pixelSize, uint8_t vertexIndex = GX_VTXFMT1);
|
||||
~FreeTypeGX();
|
||||
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
|
@ -1,392 +0,0 @@
|
||||
/*
|
||||
* Metaphrasis is a static conversion class for transforming RGBA image
|
||||
* buffers into verious GX texture formats for Wii homebrew development.
|
||||
* Copyright (C) 2008 Armin Tamzarian
|
||||
*
|
||||
* This file is part of Metaphrasis.
|
||||
*
|
||||
* Metaphrasis is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Metaphrasis is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Metaphrasis. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Metaphrasis.h"
|
||||
|
||||
/**
|
||||
* Default constructor for the Metaphrasis class.
|
||||
*/
|
||||
|
||||
Metaphrasis::Metaphrasis() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default destructor for the Metaphrasis class.
|
||||
*/
|
||||
|
||||
Metaphrasis::~Metaphrasis() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the I4 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the I4 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = bufferWidth * bufferHeight >> 1;
|
||||
uint32_t* dataBufferI4 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferI4, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint8_t *dst = (uint8_t *)dataBufferI4;
|
||||
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 8) {
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 8) {
|
||||
for(uint32_t rows = 0; rows < 8; rows++) {
|
||||
*dst++ = (src[((y + rows) * bufferWidth) + (x + 0)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 1)] & 0xf0) >> 4);
|
||||
*dst++ = (src[((y + rows) * bufferWidth) + (x + 2)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 3)] & 0xf0) >> 4);
|
||||
*dst++ = (src[((y + rows) * bufferWidth) + (x + 4)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) >> 4);
|
||||
*dst++ = (src[((y + rows) * bufferWidth) + (x + 5)] & 0xf0) | ((src[((y + rows) * bufferWidth) + (x + 7)] & 0xf0) >> 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferI4, bufferSize);
|
||||
|
||||
return dataBufferI4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the I8 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the I8 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = bufferWidth * bufferHeight;
|
||||
uint32_t* dataBufferI8 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferI8, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint8_t *dst = (uint8_t *)dataBufferI8;
|
||||
|
||||
for(uint32_t rows = 0; rows < 4; rows++) {
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 4) {
|
||||
uint32_t bufWid = ((y + rows) * bufferWidth);
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 8) {
|
||||
|
||||
*dst++ = src[bufWid + (x + 0)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 1)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 2)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 3)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 4)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 5)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 6)] & 0xff;
|
||||
*dst++ = src[bufWid + (x + 7)] & 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferI8, bufferSize);
|
||||
|
||||
return dataBufferI8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downsample the specified RGBA value data buffer to an IA4 value.
|
||||
*
|
||||
* This routine downsamples the given RGBA data value into the IA4 texture data format.
|
||||
*
|
||||
* @param rgba A 32-bit RGBA value to convert to the IA4 format.
|
||||
* @return The IA4 value of the given RGBA value.
|
||||
*/
|
||||
|
||||
uint8_t Metaphrasis::convertRGBAToIA4(uint32_t rgba) {
|
||||
uint8_t i = (rgba >> 8) & 0xf0;
|
||||
uint8_t a = (rgba ) & 0xff;
|
||||
return i | (a >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the IA4 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the IA4 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = bufferWidth * bufferHeight;
|
||||
uint32_t* dataBufferIA4 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferIA4, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint8_t *dst = (uint8_t *)dataBufferIA4;
|
||||
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 4) {
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 8) {
|
||||
for(uint32_t rows = 0; rows < 4; rows++) {
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 0)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 1)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 2)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 3)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 4)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 5)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 6)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA4(src[((y + rows) * bufferWidth) + (x + 7)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferIA4, bufferSize);
|
||||
|
||||
return dataBufferIA4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downsample the specified RGBA value data buffer to an IA8 value.
|
||||
*
|
||||
* This routine downsamples the given RGBA data value into the IA8 texture data format.
|
||||
*
|
||||
* @param rgba A 32-bit RGBA value to convert to the IA8 format.
|
||||
* @return The IA8 value of the given RGBA value.
|
||||
*/
|
||||
|
||||
uint16_t Metaphrasis::convertRGBAToIA8(uint32_t rgba) {
|
||||
return (((rgba >> 8) & 0xff) << 8) | ((rgba ) & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the IA8 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the IA8 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
|
||||
uint32_t* dataBufferIA8 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferIA8, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint16_t *dst = (uint16_t *)dataBufferIA8;
|
||||
|
||||
for(uint32_t rows = 0; rows < 4; ++rows) {
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 4) {
|
||||
uint32_t bufWid = ((y + rows) * bufferWidth);
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 4) {
|
||||
|
||||
*dst++ = Metaphrasis::convertRGBAToIA8(src[bufWid + (x + 0)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA8(src[bufWid + (x + 1)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA8(src[bufWid + (x + 2)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToIA8(src[bufWid + (x + 3)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferIA8, bufferSize);
|
||||
|
||||
return dataBufferIA8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the RGBA8 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the RGBA8 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downsample the specified RGBA value data buffer to an RGB565 value.
|
||||
*
|
||||
* This routine downsamples the given RGBA data value into the RGB565 texture data format.
|
||||
* Attribution for this routine is given fully to NoNameNo of GRRLIB Wii library.
|
||||
*
|
||||
* @param rgba A 32-bit RGBA value to convert to the RGB565 format.
|
||||
* @return The RGB565 value of the given RGBA value.
|
||||
*/
|
||||
|
||||
uint16_t Metaphrasis::convertRGBAToRGB565(uint32_t rgba) {
|
||||
uint32_t rA = ((rgba >> 24) & 0xff);
|
||||
uint32_t gA = ((rgba >> 16) & 0xff);
|
||||
uint32_t bA = ((rgba >> 8) & 0xff);
|
||||
|
||||
uint32_t r = ((rA<<5) - rA) / 255;
|
||||
uint32_t g = ((gA<<6) - gA) / 255;
|
||||
uint32_t b = ((bA<<5) - bA) / 255;
|
||||
|
||||
return (((r << 6) | g ) << 5 ) | b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the RGB565 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the RGB565 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
|
||||
uint32_t* dataBufferRGB565 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferRGB565, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint16_t *dst = (uint16_t *)dataBufferRGB565;
|
||||
|
||||
for(uint32_t rows = 0; rows < 4; rows++) {
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 4) {
|
||||
uint32_t bufWid = ((y + rows) * bufferWidth);
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 4) {
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB565(src[bufWid + (x + 0)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB565(src[bufWid + (x + 1)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB565(src[bufWid + (x + 2)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB565(src[bufWid + (x + 3)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferRGB565, bufferSize);
|
||||
|
||||
return dataBufferRGB565;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downsample the specified RGBA value data buffer to an RGB5A3 value.
|
||||
*
|
||||
* This routine downsamples the given RGBA data value into the RGB5A3 texture data format.
|
||||
* Attribution for this routine is given fully to WiiGator via the TehSkeen forum.
|
||||
*
|
||||
* @param rgba A 32-bit RGBA value to convert to the RGB5A3 format.
|
||||
* @return The RGB5A3 value of the given RGBA value.
|
||||
*/
|
||||
|
||||
uint16_t Metaphrasis::convertRGBAToRGB5A3(uint32_t rgba) {
|
||||
uint32_t r = (rgba >> 24) & 0xff;
|
||||
uint32_t g = (rgba >> 16) & 0xff;
|
||||
uint32_t b = (rgba >> 8) & 0xff;
|
||||
uint32_t a = (rgba ) & 0xff;
|
||||
uint16_t color;
|
||||
|
||||
// No predictive misses, faster shifting
|
||||
if (a > 0xe0) {
|
||||
r >>= 3;
|
||||
g >>= 3;
|
||||
b >>= 3;
|
||||
|
||||
color = (r << 10) | (g << 5) | b;
|
||||
color |= 0x8000;
|
||||
return color;
|
||||
}
|
||||
|
||||
r >>= 4;
|
||||
g >>= 4;
|
||||
b >>= 4;
|
||||
a >>= 5;
|
||||
color = (a << 12) | (r << 8) | (g << 4) | b;
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified RGBA data buffer into the RGB5A3 texture format
|
||||
*
|
||||
* This routine converts the RGBA data buffer into the RGB5A3 texture format and returns a pointer to the converted buffer.
|
||||
*
|
||||
* @param rgbaBuffer Buffer containing the temporarily rendered RGBA data.
|
||||
* @param bufferWidth Pixel width of the data buffer.
|
||||
* @param bufferHeight Pixel height of the data buffer.
|
||||
* @return A pointer to the allocated buffer.
|
||||
*/
|
||||
|
||||
uint32_t* Metaphrasis::convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight) {
|
||||
uint32_t bufferSize = (bufferWidth * bufferHeight) << 1;
|
||||
uint32_t* dataBufferRGB5A3 = (uint32_t *)memalign(32, bufferSize);
|
||||
memset(dataBufferRGB5A3, 0x00, bufferSize);
|
||||
|
||||
uint32_t *src = (uint32_t *)rgbaBuffer;
|
||||
uint16_t *dst = (uint16_t *)dataBufferRGB5A3;
|
||||
|
||||
for(uint32_t rows = 0; rows < 4; rows++) {
|
||||
for(uint32_t y = 0; y < bufferHeight; y += 4) {
|
||||
uint32_t bufWid = ((y + rows) * bufferWidth);
|
||||
for(uint32_t x = 0; x < bufferWidth; x += 4) {
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[bufWid + (x + 0)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[bufWid + (x + 1)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[bufWid + (x + 2)]);
|
||||
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[bufWid + (x + 3)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
DCFlushRange(dataBufferRGB5A3, bufferSize);
|
||||
|
||||
return dataBufferRGB5A3;
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Metaphrasis is a static conversion class for transforming RGBA image
|
||||
* buffers into verious GX texture formats for Wii homebrew development.
|
||||
* Copyright (C) 2008 Armin Tamzarian
|
||||
*
|
||||
* This file is part of Metaphrasis.
|
||||
*
|
||||
* Metaphrasis is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Metaphrasis is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Metaphrasis. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \mainpage Metaphrasis
|
||||
*
|
||||
* \section sec_intro Introduction
|
||||
*
|
||||
* Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for Wii homebrew development.
|
||||
* <br>
|
||||
* Metaphrasis is written in C++ and makes use of a community standard and newly developed algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube and Wii platforms.
|
||||
* <p>
|
||||
* This library was developed in-full by Armin Tamzarian with the support of developers in \#wiibrew on EFnet, Chaosteil of libwiisprite, and DrTwox of GRRLIB.
|
||||
*
|
||||
* \section sec_installation_source Installation (Source Code)
|
||||
*
|
||||
* -# Extract the Metaphrasis archive.
|
||||
* -# Copy the contents of the <i>src</i> directory into your project's development path.
|
||||
* -# Include the Metaphrasis header file in your code using syntax such as the following:
|
||||
* \code
|
||||
* #include "Metaphrasis.h"
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_installation_library Installation (Library)
|
||||
*
|
||||
* -# Extract the Metaphrasis archive.
|
||||
* -# Copy the contents of the <i>lib</i> directory into your <i>devKitPro/libogc</i> directory.
|
||||
* -# Include the Metaphrasis header file in your code using syntax such as the following:
|
||||
* \code
|
||||
* #include "Metaphrasis.h"
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_usage Usage
|
||||
*
|
||||
* -# Create a buffer full of 32-bit RGBA values noting both the pixel height and width of the buffer.
|
||||
* -# Call one of the many conversion routines from within your code. (Note: All methods within the Metaphrasis class are static and thus no class instance need be allocated)
|
||||
* \code
|
||||
* uint32_t* rgba8Buffer = Metaphrasis::convertBufferToRGBA8(rgbaBuffer, bufferWidth, bufferHeight);
|
||||
* \endcode
|
||||
* -# Free your temporary RGBA value buffer if you no longer need said values.
|
||||
*
|
||||
* Currently supported conversion routines are as follows:
|
||||
* \li convertBufferToI4
|
||||
* \li convertBufferToI8
|
||||
* \li convertBufferToIA4
|
||||
* \li convertBufferToIA8
|
||||
* \li convertBufferToRGBA8
|
||||
* \li convertBufferToRGB565
|
||||
* \li convertBufferToRGB5A3
|
||||
*
|
||||
* \section sec_license License
|
||||
*
|
||||
* Metaphrasis 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 METAPHRASIS_H_
|
||||
#define METAPHRASIS_H_
|
||||
|
||||
#include <gccore.h>
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
/*! \class Metaphrasis
|
||||
* \brief A static conversion class for transforming RGBA image buffers into verious GX texture formats for
|
||||
* Wii homebrew development.
|
||||
* \author Armin Tamzarian
|
||||
* \version 0.1.0
|
||||
*
|
||||
* Metaphrasis is a static conversion class for transforming RGBA image buffers into verious GX texture formats for
|
||||
* Wii homebrew development. Metaphrasis is written in C++ and makes use of a community standard and newly developed
|
||||
* algorithms for conversion of 32-bit RGBA data buffers into various GX texture formats common to both the Gamecube
|
||||
* and Wii platforms.
|
||||
*/
|
||||
class Metaphrasis {
|
||||
public:
|
||||
Metaphrasis();
|
||||
virtual ~Metaphrasis();
|
||||
|
||||
static uint32_t* convertBufferToI4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToI8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToIA4(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToIA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToRGBA8(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToRGB565(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
static uint32_t* convertBufferToRGB5A3(uint32_t* rgbaBuffer, uint16_t bufferWidth, uint16_t bufferHeight);
|
||||
|
||||
static uint8_t convertRGBAToIA4(uint32_t rgba);
|
||||
static uint16_t convertRGBAToIA8(uint32_t rgba);
|
||||
static uint16_t convertRGBAToRGB565(uint32_t rgba);
|
||||
static uint16_t convertRGBAToRGB5A3(uint32_t rgba);
|
||||
|
||||
};
|
||||
|
||||
#endif /*METAPHRASIS_H_*/
|
@ -785,13 +785,12 @@ void LoadPatch()
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
char patchpath[3][512];
|
||||
char patchpath[2][512];
|
||||
memset(patchpath, 0, sizeof(patchpath));
|
||||
sprintf(patchpath[0], "%s%s.ips",browser.dir,ROMFilename);
|
||||
sprintf(patchpath[1], "%s%s.ups",browser.dir,ROMFilename);
|
||||
sprintf(patchpath[2], "%s%s.ppf",browser.dir,ROMFilename);
|
||||
|
||||
for(; patchtype<3; patchtype++)
|
||||
for(; patchtype<2; patchtype++)
|
||||
{
|
||||
patchsize = LoadFile(patchpath[patchtype], SILENT);
|
||||
|
||||
@ -809,19 +808,15 @@ void LoadPatch()
|
||||
{
|
||||
if(patchtype == 0)
|
||||
patchApplyIPS(mf, &gbRom, &gbRomSize);
|
||||
else if(patchtype == 1)
|
||||
patchApplyUPS(mf, &gbRom, &gbRomSize);
|
||||
else
|
||||
patchApplyPPF(mf, &gbRom, &gbRomSize);
|
||||
patchApplyUPS(mf, &gbRom, &gbRomSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(patchtype == 0)
|
||||
patchApplyIPS(mf, &rom, &GBAROMSize);
|
||||
else if(patchtype == 1)
|
||||
patchApplyUPS(mf, &rom, &GBAROMSize);
|
||||
else
|
||||
patchApplyPPF(mf, &rom, &GBAROMSize);
|
||||
patchApplyUPS(mf, &rom, &GBAROMSize);
|
||||
}
|
||||
|
||||
memfclose(mf); // close memory file
|
||||
@ -874,20 +869,26 @@ bool LoadVBAROM()
|
||||
// we need to check the file extension of the first file in the archive
|
||||
char * zippedFilename = GetFirstZipFilename ();
|
||||
|
||||
if(zippedFilename != NULL)
|
||||
{
|
||||
if(utilIsGBAImage(zippedFilename))
|
||||
cartridgeType = 2;
|
||||
else if(utilIsGBImage(zippedFilename))
|
||||
cartridgeType = 1;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else // loading the file failed
|
||||
if(zippedFilename == NULL) // loading the file failed
|
||||
{
|
||||
ErrorPrompt("Empty or invalid ZIP file!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(utilIsGBAImage(zippedFilename))
|
||||
{
|
||||
cartridgeType = 2;
|
||||
}
|
||||
else if(utilIsGBImage(zippedFilename))
|
||||
{
|
||||
cartridgeType = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(zippedFilename);
|
||||
return false;
|
||||
}
|
||||
free(zippedFilename);
|
||||
}
|
||||
|
||||
// leave before we do anything
|
||||
|
Loading…
Reference in New Issue
Block a user