mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-01 08:25:12 +01:00
add pngu and metaphrasis to project
This commit is contained in:
parent
a5272b8cf5
commit
ffb8c8945f
@ -41,7 +41,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# any extra libraries we wish to link with
|
# any extra libraries we wish to link with
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBS := -lpngu -lpng -lmxml -lmetaphrasis -lfat -lz -logc -lfreetype
|
LIBS := -lpng -lmxml -lfat -lz -logc -lfreetype
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
@ -41,7 +41,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# any extra libraries we wish to link with
|
# any extra libraries we wish to link with
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBS := -ldb -ldi -lpngu -lpng -lmxml -lmetaphrasis -lwiikeyboard \
|
LIBS := -ldb -ldi -lpng -lmxml -lwiikeyboard \
|
||||||
-lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb
|
-lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
@ -155,7 +155,7 @@
|
|||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include FT_BITMAP_H
|
#include FT_BITMAP_H
|
||||||
#include <Metaphrasis.h>
|
#include "Metaphrasis.h"
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
383
source/ngc/Metaphrasis.cpp
Normal file
383
source/ngc/Metaphrasis.cpp
Normal file
@ -0,0 +1,383 @@
|
|||||||
|
/*
|
||||||
|
* 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(uint16_t y = 0; y < bufferHeight; y += 8) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 8) {
|
||||||
|
for(uint16_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(uint16_t y = 0; y < bufferHeight; y += 4) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 8) {
|
||||||
|
for(uint16_t rows = 0; rows < 4; rows++) {
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 0)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 1)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 2)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 3)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 4)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 5)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (x + 6)] & 0xff;
|
||||||
|
*dst++ = src[((y + rows) * bufferWidth) + (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, a;
|
||||||
|
|
||||||
|
i = (rgba >> 8) & 0xf0;
|
||||||
|
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(uint16_t y = 0; y < bufferHeight; y += 4) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 8) {
|
||||||
|
for(uint16_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) {
|
||||||
|
uint8_t i, a;
|
||||||
|
|
||||||
|
i = (rgba >> 8) & 0xff;
|
||||||
|
a = (rgba ) & 0xff;
|
||||||
|
|
||||||
|
return (i << 8) | a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(uint16_t y = 0; y < bufferHeight; y += 4) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 4) {
|
||||||
|
for(uint16_t rows = 0; rows < 4; rows++) {
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 0)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 1)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (x + 2)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToIA8(src[((y + rows) * bufferWidth) + (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(uint16_t block = 0; block < bufferHeight; block += 4) {
|
||||||
|
for(uint16_t i = 0; i < bufferWidth; i += 4) {
|
||||||
|
for (uint16_t c = 0; c < 4; c++) {
|
||||||
|
for (uint16_t ar = 0; ar < 4; ar++) {
|
||||||
|
*dst++ = src[(((i + ar) + ((block + c) * bufferWidth)) * 4) + 3];
|
||||||
|
*dst++ = src[((i + ar) + ((block + c) * bufferWidth)) * 4];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (uint16_t c = 0; c < 4; c++) {
|
||||||
|
for (uint16_t gb = 0; gb < 4; gb++) {
|
||||||
|
*dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 1];
|
||||||
|
*dst++ = src[(((i + gb) + ((block + c) * bufferWidth)) * 4) + 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
r = (((rgba >> 24) & 0xff) * 31) / 255;
|
||||||
|
g = (((rgba >> 16) & 0xff) * 63) / 255;
|
||||||
|
b = (((rgba >> 8) & 0xff) * 31) / 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(uint16_t y = 0; y < bufferHeight; y += 4) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 4) {
|
||||||
|
for(uint16_t rows = 0; rows < 4; rows++) {
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 0)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 1)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (x + 2)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB565(src[((y + rows) * bufferWidth) + (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, g, b, a;
|
||||||
|
uint16_t color;
|
||||||
|
|
||||||
|
r = (rgba >> 24) & 0xff;
|
||||||
|
g = (rgba >> 16) & 0xff;
|
||||||
|
b = (rgba >> 8) & 0xff;
|
||||||
|
a = (rgba ) & 0xff;
|
||||||
|
|
||||||
|
if (a > 0xe0) {
|
||||||
|
r = r >> 3;
|
||||||
|
g = g >> 3;
|
||||||
|
b = b >> 3;
|
||||||
|
|
||||||
|
color = (r << 10) | (g << 5) | b;
|
||||||
|
color |= 0x8000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
r = r >> 4;
|
||||||
|
g = g >> 4;
|
||||||
|
b = b >> 4;
|
||||||
|
a = 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(uint16_t y = 0; y < bufferHeight; y += 4) {
|
||||||
|
for(uint16_t x = 0; x < bufferWidth; x += 4) {
|
||||||
|
for(uint16_t rows = 0; rows < 4; rows++) {
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 0)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 1)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 2)]);
|
||||||
|
*dst++ = Metaphrasis::convertRGBAToRGB5A3(src[((y + rows) * bufferWidth) + (x + 3)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DCFlushRange(dataBufferRGB5A3, bufferSize);
|
||||||
|
|
||||||
|
return dataBufferRGB5A3;
|
||||||
|
}
|
116
source/ngc/Metaphrasis.h
Normal file
116
source/ngc/Metaphrasis.h
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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_*/
|
@ -41,7 +41,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <asndlib.h>
|
#include <asndlib.h>
|
||||||
#include <wiiuse/wpad.h>
|
#include <wiiuse/wpad.h>
|
||||||
#include "pngu/pngu.h"
|
#include "pngu.h"
|
||||||
#include "FreeTypeGX.h"
|
#include "FreeTypeGX.h"
|
||||||
#include "vba.h"
|
#include "vba.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
1266
source/ngc/pngu.c
Normal file
1266
source/ngc/pngu.c
Normal file
File diff suppressed because it is too large
Load Diff
176
source/ngc/pngu.h
Normal file
176
source/ngc/pngu.h
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
/********************************************************************************************
|
||||||
|
|
||||||
|
PNGU Version : 0.2a
|
||||||
|
|
||||||
|
Coder : frontier
|
||||||
|
|
||||||
|
More info : http://frontier-dev.net
|
||||||
|
|
||||||
|
Modified by Tantric, 2009
|
||||||
|
|
||||||
|
********************************************************************************************/
|
||||||
|
#ifndef __PNGU__
|
||||||
|
#define __PNGU__
|
||||||
|
|
||||||
|
// Return codes
|
||||||
|
#define PNGU_OK 0
|
||||||
|
#define PNGU_ODD_WIDTH 1
|
||||||
|
#define PNGU_ODD_STRIDE 2
|
||||||
|
#define PNGU_INVALID_WIDTH_OR_HEIGHT 3
|
||||||
|
#define PNGU_FILE_IS_NOT_PNG 4
|
||||||
|
#define PNGU_UNSUPPORTED_COLOR_TYPE 5
|
||||||
|
#define PNGU_NO_FILE_SELECTED 6
|
||||||
|
#define PNGU_CANT_OPEN_FILE 7
|
||||||
|
#define PNGU_CANT_READ_FILE 8
|
||||||
|
#define PNGU_LIB_ERROR 9
|
||||||
|
|
||||||
|
// Color types
|
||||||
|
#define PNGU_COLOR_TYPE_GRAY 1
|
||||||
|
#define PNGU_COLOR_TYPE_GRAY_ALPHA 2
|
||||||
|
#define PNGU_COLOR_TYPE_PALETTE 3
|
||||||
|
#define PNGU_COLOR_TYPE_RGB 4
|
||||||
|
#define PNGU_COLOR_TYPE_RGB_ALPHA 5
|
||||||
|
#define PNGU_COLOR_TYPE_UNKNOWN 6
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Types
|
||||||
|
typedef unsigned char PNGU_u8;
|
||||||
|
typedef unsigned short PNGU_u16;
|
||||||
|
typedef unsigned int PNGU_u32;
|
||||||
|
typedef unsigned long long PNGU_u64;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
PNGU_u8 r;
|
||||||
|
PNGU_u8 g;
|
||||||
|
PNGU_u8 b;
|
||||||
|
} PNGUCOLOR;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
PNGU_u32 imgWidth; // In pixels
|
||||||
|
PNGU_u32 imgHeight; // In pixels
|
||||||
|
PNGU_u32 imgBitDepth; // In bitx
|
||||||
|
PNGU_u32 imgColorType; // PNGU_COLOR_TYPE_*
|
||||||
|
PNGU_u32 validBckgrnd; // Non zero if there is a background color
|
||||||
|
PNGUCOLOR bckgrnd; // Backgroun color
|
||||||
|
PNGU_u32 numTrans; // Number of transparent colors
|
||||||
|
PNGUCOLOR *trans; // Transparent colors
|
||||||
|
} PNGUPROP;
|
||||||
|
|
||||||
|
// Image context, always initialize with SelectImageFrom* and free with ReleaseImageContext
|
||||||
|
struct _IMGCTX;
|
||||||
|
typedef struct _IMGCTX *IMGCTX;
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pixel conversion *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Macro to convert RGB8 values to RGB565
|
||||||
|
#define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) )
|
||||||
|
|
||||||
|
// Macro to convert RGBA8 values to RGB5A3
|
||||||
|
#define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \
|
||||||
|
(0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \
|
||||||
|
(((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4)))
|
||||||
|
|
||||||
|
// Function to convert two RGB8 values to YCbYCr
|
||||||
|
PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2);
|
||||||
|
|
||||||
|
// Function to convert an YCbYCr to two RGB8 values.
|
||||||
|
void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2);
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Image context handling *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Selects a PNG file, previosly loaded into a buffer, and creates an image context for subsequent procesing.
|
||||||
|
IMGCTX PNGU_SelectImageFromBuffer (const void *buffer);
|
||||||
|
|
||||||
|
// Selects a PNG file, from any devoptab device, and creates an image context for subsequent procesing.
|
||||||
|
IMGCTX PNGU_SelectImageFromDevice (const char *filename);
|
||||||
|
|
||||||
|
// Frees resources associated with an image context. Always call this function when you no longer need the IMGCTX.
|
||||||
|
void PNGU_ReleaseImageContext (IMGCTX ctx);
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Miscelaneous *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors.
|
||||||
|
int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties);
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Image conversion *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions,
|
||||||
|
// destination address and stride in pixels (stride = buffer width - image width).
|
||||||
|
int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||||
|
|
||||||
|
// Macro for decoding an image inside a buffer at given coordinates.
|
||||||
|
#define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||||
|
\
|
||||||
|
PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||||
|
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||||
|
|
||||||
|
// Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions,
|
||||||
|
// destination address and stride in pixels (stride = buffer width - image width).
|
||||||
|
int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||||
|
|
||||||
|
// Macro for decoding an image inside a buffer at given coordinates.
|
||||||
|
#define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||||
|
\
|
||||||
|
PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||||
|
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||||
|
|
||||||
|
// Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions,
|
||||||
|
// destination address, stride in pixels and default alpha value, which is used if the source image
|
||||||
|
// doesn't have an alpha channel.
|
||||||
|
int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha);
|
||||||
|
|
||||||
|
// Macro for decoding an image inside a buffer at given coordinates.
|
||||||
|
#define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \
|
||||||
|
\
|
||||||
|
PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||||
|
(coordX) * 2, (bufferWidth) - (imgWidth), default_alpha)
|
||||||
|
|
||||||
|
// Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions
|
||||||
|
// and destination address.
|
||||||
|
int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
|
||||||
|
|
||||||
|
// Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions,
|
||||||
|
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
|
||||||
|
int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
|
||||||
|
|
||||||
|
// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions,
|
||||||
|
// destination address and default alpha value, which is used if the source image doesn't have an alpha channel.
|
||||||
|
int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
|
||||||
|
|
||||||
|
// Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to
|
||||||
|
// specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width).
|
||||||
|
int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||||
|
|
||||||
|
int PNGU_EncodeFromRGB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||||
|
int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
|
||||||
|
|
||||||
|
// Macro for encoding an image stored into an YCbYCr buffer at given coordinates.
|
||||||
|
#define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
|
||||||
|
\
|
||||||
|
PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
|
||||||
|
(coordX) * 2, (bufferWidth) - (imgWidth))
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -16,7 +16,7 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <ogc/lwp_watchdog.h>
|
#include <ogc/lwp_watchdog.h>
|
||||||
|
|
||||||
#include "pngu/pngu.h"
|
#include "pngu.h"
|
||||||
|
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user