From 8789bd4ba650cad110c0097c2c380a9b461a13b7 Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Tue, 19 Jan 2010 05:09:58 +0000 Subject: [PATCH] [CHG] pngu.c does not required to include gx.h anymore [BUG] Fixed some examples using GRRLIB_ScrShot --- GRRLIB/GRRLIB/GRRLIB_fileIO.c | 1 + GRRLIB/lib/pngu/pngu.c | 18 +++++++++++------- examples/basic_drawing/source/main.c | 6 +++--- examples/ttf/source/main.c | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_fileIO.c b/GRRLIB/GRRLIB/GRRLIB_fileIO.c index 7cf25ea..5bbd2b1 100644 --- a/GRRLIB/GRRLIB/GRRLIB_fileIO.c +++ b/GRRLIB/GRRLIB/GRRLIB_fileIO.c @@ -85,6 +85,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) { /** * Make a PNG screenshot. + * It should be called after drawing stuff on the screen, but before GRRLIB_Render. * libfat is required to use the function. * @param filename Name of the file to write. * @return bool true=everything worked, false=problems occurred. diff --git a/GRRLIB/lib/pngu/pngu.c b/GRRLIB/lib/pngu/pngu.c index b2504b4..0d7b5de 100644 --- a/GRRLIB/lib/pngu/pngu.c +++ b/GRRLIB/lib/pngu/pngu.c @@ -9,7 +9,6 @@ More info : http://frontier-dev.net ********************************************************************************************/ #include #include -#include #include "pngu.h" #include "png.h" @@ -18,6 +17,10 @@ More info : http://frontier-dev.net #define PNGU_SOURCE_BUFFER 1 #define PNGU_SOURCE_DEVICE 2 +#define _SHIFTL(v, s, w) \ + ((png_uint_32) (((png_uint_32)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) \ + ((png_uint_32)(((png_uint_32)(v) >> (s)) & ((0x01 << (w)) - 1))) // Prototypes of helper functions int pngu_info (IMGCTX ctx); @@ -821,20 +824,21 @@ int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void // Coded by Crayon for GRRLIB (http://code.google.com/p/grrlib) int PNGU_EncodeFromEFB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stride) { + png_uint_32 regval,val; int x,y,res; unsigned char * tmpbuffer = (unsigned char *)malloc(width*height*3); memset(tmpbuffer, 0, width*height*3); - GXColor peekColor; for(y=0; y < height; y++) { for(x=0; x < width; x++) { - GX_PeekARGB(x, y, &peekColor); - - tmpbuffer[y*640*3+x*3] = peekColor.r; // R - tmpbuffer[y*640*3+x*3+1] = peekColor.g; // G - tmpbuffer[y*640*3+x*3+2] = peekColor.b; // B + regval = 0xc8000000|(_SHIFTL(x,2,10)); + regval = (regval&~0x3FF000)|(_SHIFTL(y,12,10)); + val = *(png_uint_32*)regval; + tmpbuffer[y*640*3+x*3] = _SHIFTR(val,16,8); // R + tmpbuffer[y*640*3+x*3+1] = _SHIFTR(val,8,8); // G + tmpbuffer[y*640*3+x*3+2] = val&0xff; // B } } diff --git a/examples/basic_drawing/source/main.c b/examples/basic_drawing/source/main.c index 33d8296..75260b7 100644 --- a/examples/basic_drawing/source/main.c +++ b/examples/basic_drawing/source/main.c @@ -166,8 +166,6 @@ int main() { GRRLIB_PrintBMF(left, top+420, bmf_Font2, "%s", bmf_Font2->name); } GRRLIB_Printf(500, 27, tex_BMfont5, GRRLIB_WHITE, 1, "Current FPS: %d", FPS); - GRRLIB_Render(); - FPS = CalculateFrameRate(); if(wpaddown & WPAD_BUTTON_HOME) { break; @@ -217,6 +215,9 @@ int main() { GRRLIB_ScrShot("sd:/grrlib.png"); WPAD_Rumble(WPAD_CHAN_0, 0); // Rumble off } + + GRRLIB_Render(); + FPS = CalculateFrameRate(); } GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB // Free some textures @@ -235,7 +236,6 @@ int main() { /** * This function calculates the number of frames we render each second. - * It must be called right after GRRLIB_Render. * @return The number of frames per second. */ static u8 CalculateFrameRate() { diff --git a/examples/ttf/source/main.c b/examples/ttf/source/main.c index fe99039..f0f94fe 100644 --- a/examples/ttf/source/main.c +++ b/examples/ttf/source/main.c @@ -68,7 +68,6 @@ int main(int argc, char **argv) { GRRLIB_PrintfTTF(500+1, 25+1, myFont, FPS, 12, 0x000000FF); GRRLIB_PrintfTTF(500, 25, myFont, FPS, 12, 0xFFFFFFFF); } - GRRLIB_Render(); // Render the frame buffer to the TV WPAD_ScanPads(); // Scan the Wii Remotes @@ -86,6 +85,8 @@ int main(int argc, char **argv) { ScreenShot(); // Needs to be after GRRLIB_Render() WPAD_Rumble(0, false); // Rumble off } + + GRRLIB_Render(); // Render the frame buffer to the TV } GRRLIB_FreeTexture(CopiedImg);