From cbe862724914e164b9534735f23ad6d82edc5f7f Mon Sep 17 00:00:00 2001 From: N0NameN0 Date: Thu, 19 Mar 2009 00:22:25 +0000 Subject: [PATCH] [CHG] Created a GRRLIB.c/.h and move GRRLIB_ScrShot and GRRLIB_LoadTextureFromFile to it since it's not really Lib related. (need to fix warning) --- GRRLIB/GRRLIB/GRRLIB.c | 46 ++------------------------- GRRLIB/GRRLIB/GRRLIB.h | 4 +-- GRRLIB/GRRLIB/GRRLIBaddon.c | 62 +++++++++++++++++++++++++++++++++++++ GRRLIB/GRRLIB/GRRLIBaddon.h | 31 +++++++++++++++++++ 4 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 GRRLIB/GRRLIB/GRRLIBaddon.c create mode 100644 GRRLIB/GRRLIB/GRRLIBaddon.h diff --git a/GRRLIB/GRRLIB/GRRLIB.c b/GRRLIB/GRRLIB/GRRLIB.c index c739954..4d00037 100644 --- a/GRRLIB/GRRLIB/GRRLIB.c +++ b/GRRLIB/GRRLIB/GRRLIB.c @@ -15,14 +15,14 @@ #include "../lib/libjpeg/jpeglib.h" #include "GRRLIB.h" #include -#include + #define DEFAULT_FIFO_SIZE (256 * 1024) /**< GX fifo buffer size. */ u32 fb = 0; -static void *xfb[2] = {NULL, NULL}; -static Mtx GXmodelView2D; +void *xfb[2] = {NULL, NULL}; +Mtx GXmodelView2D; GXRModeObj *rmode; void *gp_fifo = NULL; @@ -485,28 +485,6 @@ GRRLIB_texImg *GRRLIB_LoadTexture(const unsigned char my_img[]) { } } -/** - * Load a texture from a file. - * @param filename The JPEG or PNG filename to load. - * @return A GRRLIB_texImg structure filled with image informations. - */ -GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename) { - fatInitDefault(); - FILE *fd = fopen(filename, "rb"); - - fseek(fd, 0, SEEK_END); - long lsize = ftell(fd); - rewind(fd); - - unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lsize); - fread (buffer, 1, lsize, fd); - GRRLIB_texImg *tex = GRRLIB_LoadTexture(buffer); - free(buffer); - - fclose(fd); - return tex; -} - /** * Free memory allocated for texture. * @param tex A GRRLIB_texImg structure. @@ -1257,24 +1235,6 @@ void GRRLIB_Exit() { } } -/** - * Make a PNG screenshot on the SD card. - * libfat is required to use the function. - * @param File name of the file to write. - * @return true if every thing worked, false otherwise. - */ -bool GRRLIB_ScrShot(const char* File) { - int ErrorCode = -1; - IMGCTX pngContext; - - if(fatInitDefault() && (pngContext = PNGU_SelectImageFromDevice(File))) { - ErrorCode = PNGU_EncodeFromYCbYCr(pngContext, rmode->fbWidth, rmode->efbHeight, xfb[fb], 0); - PNGU_ReleaseImageContext(pngContext); - } - return !ErrorCode; -} - - /** * Reads a pixel directly from the FrontBuffer. * Since the FB is stored in YCbCr, diff --git a/GRRLIB/GRRLIB/GRRLIB.h b/GRRLIB/GRRLIB/GRRLIB.h index 453035f..d4882c7 100644 --- a/GRRLIB/GRRLIB/GRRLIB.h +++ b/GRRLIB/GRRLIB/GRRLIB.h @@ -109,7 +109,7 @@ GRRLIB_texImg *GRRLIB_CreateEmptyTexture(unsigned int, unsigned int); GRRLIB_texImg *GRRLIB_LoadTexture(const unsigned char my_img[]); GRRLIB_texImg *GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]); GRRLIB_texImg *GRRLIB_LoadTexturePNG(const unsigned char my_png[]); -GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename); + void GRRLIB_FreeTexture(struct GRRLIB_texImg *tex); GRRLIB_bytemapFont *GRRLIB_LoadBMF(const unsigned char my_bmf[]); @@ -156,8 +156,6 @@ void GRRLIB_Render(); void GRRLIB_Exit(); -bool GRRLIB_ScrShot(const char*); - void GRRLIB_GetPixelFromFB(int x, int y, u8 *R1, u8 *G1, u8 *B1, u8* R2, u8 *G2, u8 *B2 ); u8 GRRLIB_ClampVar8 (float Value); diff --git a/GRRLIB/GRRLIB/GRRLIBaddon.c b/GRRLIB/GRRLIB/GRRLIBaddon.c new file mode 100644 index 0000000..b2e3bfc --- /dev/null +++ b/GRRLIB/GRRLIB/GRRLIBaddon.c @@ -0,0 +1,62 @@ +/*=========================================== + GRRLIB (GX version) 4.0.0 addon + Code : NoNameNo + Additional Code : Crayon & Xane + GX hints : RedShade +===========================================*/ + +#include +#include +#include +#include +#include +#include +#include "../lib/libpng/pngu/pngu.h" +#include "GRRLIB.h" +#include "GRRLIBaddon.h" +#include +#include + +extern u32 fb; +extern void *xfb[2]; +extern GXRModeObj *rmode; + + +/** + * Load a texture from a file. + * @param filename The JPEG or PNG filename to load. + * @return A GRRLIB_texImg structure filled with image informations. + */ +GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename) { + fatInitDefault(); + FILE *fd = fopen(filename, "rb"); + + fseek(fd, 0, SEEK_END); + long lsize = ftell(fd); + rewind(fd); + + unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lsize); + fread (buffer, 1, lsize, fd); + GRRLIB_texImg *tex = GRRLIB_LoadTexture(buffer); + free(buffer); + + fclose(fd); + return tex; +} + +/** + * Make a PNG screenshot on the SD card. + * libfat is required to use the function. + * @param File name of the file to write. + * @return true if every thing worked, false otherwise. + */ +bool GRRLIB_ScrShot(const char* File) { + int ErrorCode = -1; + IMGCTX pngContext; + + if(fatInitDefault() && (pngContext = PNGU_SelectImageFromDevice(File))) { + ErrorCode = PNGU_EncodeFromYCbYCr(pngContext, rmode->fbWidth, rmode->efbHeight, xfb[fb], 0); + PNGU_ReleaseImageContext(pngContext); + } + return !ErrorCode; +} diff --git a/GRRLIB/GRRLIB/GRRLIBaddon.h b/GRRLIB/GRRLIB/GRRLIBaddon.h new file mode 100644 index 0000000..3b34eb7 --- /dev/null +++ b/GRRLIB/GRRLIB/GRRLIBaddon.h @@ -0,0 +1,31 @@ +/*=========================================== + GRRLIB (GX version) 4.0.0 addon + Code : NoNameNo + Additional Code : Crayon & Xane + GX hints : RedShade +===========================================*/ + +#ifndef __GXHDR__ +#define __GXHDR__ + +/** + * @file GRRLIBaddon.h + * GRRLIB library. + */ + + +#ifdef __cplusplus + extern "C" { +#endif /* __cplusplus */ + + +GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename); +bool GRRLIB_ScrShot(const char*); + + +#ifdef __cplusplus + } +#endif /* __cplusplus */ + +#endif +