[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)
This commit is contained in:
N0NameN0 2009-03-19 00:22:25 +00:00
parent e9bb506e09
commit cbe8627249
4 changed files with 97 additions and 46 deletions

View file

@ -15,14 +15,14 @@
#include "../lib/libjpeg/jpeglib.h" #include "../lib/libjpeg/jpeglib.h"
#include "GRRLIB.h" #include "GRRLIB.h"
#include <ogc/conf.h> #include <ogc/conf.h>
#include <fat.h>
#define DEFAULT_FIFO_SIZE (256 * 1024) /**< GX fifo buffer size. */ #define DEFAULT_FIFO_SIZE (256 * 1024) /**< GX fifo buffer size. */
u32 fb = 0; u32 fb = 0;
static void *xfb[2] = {NULL, NULL}; void *xfb[2] = {NULL, NULL};
static Mtx GXmodelView2D; Mtx GXmodelView2D;
GXRModeObj *rmode; GXRModeObj *rmode;
void *gp_fifo = NULL; 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. * Free memory allocated for texture.
* @param tex A GRRLIB_texImg structure. * @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. * Reads a pixel directly from the FrontBuffer.
* Since the FB is stored in YCbCr, * Since the FB is stored in YCbCr,

View file

@ -109,7 +109,7 @@ GRRLIB_texImg *GRRLIB_CreateEmptyTexture(unsigned int, unsigned int);
GRRLIB_texImg *GRRLIB_LoadTexture(const unsigned char my_img[]); GRRLIB_texImg *GRRLIB_LoadTexture(const unsigned char my_img[]);
GRRLIB_texImg *GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]); GRRLIB_texImg *GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]);
GRRLIB_texImg *GRRLIB_LoadTexturePNG(const unsigned char my_png[]); GRRLIB_texImg *GRRLIB_LoadTexturePNG(const unsigned char my_png[]);
GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename);
void GRRLIB_FreeTexture(struct GRRLIB_texImg *tex); void GRRLIB_FreeTexture(struct GRRLIB_texImg *tex);
GRRLIB_bytemapFont *GRRLIB_LoadBMF(const unsigned char my_bmf[]); GRRLIB_bytemapFont *GRRLIB_LoadBMF(const unsigned char my_bmf[]);
@ -156,8 +156,6 @@ void GRRLIB_Render();
void GRRLIB_Exit(); 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 ); void GRRLIB_GetPixelFromFB(int x, int y, u8 *R1, u8 *G1, u8 *B1, u8* R2, u8 *G2, u8 *B2 );
u8 GRRLIB_ClampVar8 (float Value); u8 GRRLIB_ClampVar8 (float Value);

View file

@ -0,0 +1,62 @@
/*===========================================
GRRLIB (GX version) 4.0.0 addon
Code : NoNameNo
Additional Code : Crayon & Xane
GX hints : RedShade
===========================================*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "../lib/libpng/pngu/pngu.h"
#include "GRRLIB.h"
#include "GRRLIBaddon.h"
#include <ogc/conf.h>
#include <fat.h>
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;
}

View file

@ -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