Refactoring

This commit is contained in:
Crayon2000 2024-02-11 14:01:37 -05:00
parent 83ed32fad9
commit 30b5aeb705
6 changed files with 10 additions and 18 deletions

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------
Copyright (c) 2009-2022 The GRRLIB Team
Copyright (c) 2009-2024 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -78,7 +78,6 @@ int GRRLIB_LoadFile(const char* filename, u8* *data) {
* If an error occurs NULL will be returned.
*/
GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
GRRLIB_texImg *tex;
u8 *data;
// Return NULL if load fails
@ -87,7 +86,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
}
// Convert to texture
tex = GRRLIB_LoadTexture(data);
GRRLIB_texImg *tex = GRRLIB_LoadTexture(data);
// Free up the buffer
free(data);
@ -102,10 +101,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
* If an error occurs NULL will be returned.
*/
GRRLIB_ttfFont* GRRLIB_LoadTTFFromFile(const char *filename) {
GRRLIB_ttfFont *ttf;
u8 *data;
s32 size = GRRLIB_LoadFile(filename, &data);
const s32 size = GRRLIB_LoadFile(filename, &data);
// Return NULL if load fails
if (size <= 0) {
@ -113,7 +111,7 @@ GRRLIB_ttfFont* GRRLIB_LoadTTFFromFile(const char *filename) {
}
// Convert to TTF
ttf = GRRLIB_LoadTTF(data, size);
GRRLIB_ttfFont *ttf = GRRLIB_LoadTTF(data, size);
// Free up the buffer
free(data);

View file

@ -48,7 +48,6 @@ bool GRRLIB_GeckoInit(void) {
* @param ... Optional arguments.
*/
void GRRLIB_GeckoPrintf (const char *text, ...) {
int size;
char tmp[1024];
if (geckoinit == false) {
@ -57,7 +56,7 @@ void GRRLIB_GeckoPrintf (const char *text, ...) {
va_list argp;
va_start(argp, text);
size = vsnprintf(tmp, sizeof(tmp), text, argp);
const int size = vsnprintf(tmp, sizeof(tmp), text, argp);
va_end(argp);
usb_sendbuffer_safe(1, tmp, size);

View file

@ -160,7 +160,7 @@ GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png) {
PNGUPROP imgProp;
IMGCTX ctx = PNGU_SelectImageFromBuffer(my_png);
PNGU_GetImageProperties(ctx, &imgProp);
my_texture->data = PNGU_DecodeTo4x4RGBA8(ctx, imgProp.imgWidth, imgProp.imgHeight, &width, &height, NULL);
my_texture->data = PNGU_DecodeTo4x4RGBA8(ctx, imgProp.imgWidth, imgProp.imgHeight, &width, &height);
if (my_texture->data != NULL) {
my_texture->w = width;
my_texture->h = height;

View file

@ -131,7 +131,6 @@ void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf3
int penX = 0;
int penY = fontSize;
FT_GlyphSlot slot = Face->glyph;
FT_UInt glyphIndex;
FT_UInt previousGlyph = 0;
const u8 cR = R(color);
const u8 cG = G(color);
@ -145,7 +144,7 @@ void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf3
/* Loop over each character, until the
* end of the string is reached, or until the pixel width is too wide */
while(*utf32) {
glyphIndex = FT_Get_Char_Index(myFont->face, *utf32++);
const FT_UInt glyphIndex = FT_Get_Char_Index(myFont->face, *utf32++);
if (myFont->kerning && previousGlyph && glyphIndex) {
FT_Vector delta;

View file

@ -564,10 +564,9 @@ static inline PNGU_u32 coordsRGBA8(PNGU_u32 x, PNGU_u32 y, PNGU_u32 w)
}
// Coded by Tantric for WiiMC (http://www.wiimc.org)
PNGU_u8 * PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight, PNGU_u8 *dstPtr)
PNGU_u8 * PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight)
{
PNGU_u8 default_alpha = 255; // default alpha value, which is used if the source image doesn't have an alpha channel.
PNGU_u8 *dst;
int x, y, x2=0, y2=0, offset;
int xRatio = 0, yRatio = 0;
png_byte *pixel;
@ -604,10 +603,7 @@ PNGU_u8 * PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, in
int len = (padWidth * padHeight) << 2;
if(len%32) len += (32-len%32);
if(dstPtr)
dst = dstPtr; // use existing allocation
else
dst = memalign (32, len);
PNGU_u8 *dst = memalign (32, len);
if(!dst)
return NULL;

View file

@ -151,7 +151,7 @@ int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *b
// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions,
// destination address.
PNGU_u8 * PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight, PNGU_u8 *dstPtr);
PNGU_u8 * PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight);
// 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).