Welcome! Log In Create A New Profile

Advanced

Using embedded images

Posted by diego_pmc 
Using embedded images
May 04, 2010 06:03PM
Hi, I would like to know if (and how) I can included an image file (JPEG in my case) as a resource and then use that and print it on the screen (with GRRLIB, in my case). In the app intro I want to show the symbols of the libraries being used. I added 'grrlib_logo.jpg' as a resource; I know that a header gets created, 'grrlib_logo_jpg.h', which has some extern u8 and u32 declarations.

I included that file, created a GRRLIB_texImg with it and tried to print it. However nothing happened; the screen just stayed black (no crashes, no nothing, and everything else behaved normally -- I was able to exit by pressing HOME). I know I once saw a homebrew app that used embedded resources, but I can't remember which one it was. Could someone please either point me to that app, or explain to me how to make this work?

This is the relevant code in my app:
#include "grrlib_logo_jpg.h"
// ...
GRRLIB_texImg* img = GRRLIB_LoadTexture(grrlib_logo_jpg);

while (/*...*/) {
    GRRLIB_DrawImg(0, 0, img, 0, 1, 1, 0xFFFFFFFF);
    GRRLIB_Render();
}

(The image, however, can be printed if I read it from a file during execution instead.)



Edited 2 time(s). Last edit at 05/05/2010 12:36AM by diego_pmc.
Re: Using embedded images
May 04, 2010 07:41PM
Instead of GRRLIB_LoadTexture try to use GRRLIB_LoadTextureJPGEx(const u8 *my_jpg, const int). It has a second parameter to specify the size of the buffer.

How did you generate the grrlib_logo_jpg.h file?
Re: Using embedded images
May 04, 2010 08:20PM
I did not generate it. I'm using Visual C++ 2010; I added the JPEG as a resource, and when I compile the header gets created automatically and placed in the 'build' folder. The exact same thing happens if I compile directly though devkitPro. The contents of the header are:
extern const u8 grrlib_logo_jpg_end[];
extern const u8 grrlib_logo_jpg[];
extern const u32 grrlib_logo_jpg_size;

Also, thanks for your answer. I can't test it now, but I should be able to tomorrow and I'll tell you if it works.



Edited 1 time(s). Last edit at 05/04/2010 08:23PM by diego_pmc.
Re: Using embedded images
May 04, 2010 08:53PM
I have a question. I looked at the source code and I see that all GRRLIB_LoadTextureJPG() does is determine the size of the JPG and then call GRRLIB_LoadTextureJPGEx(). My question is, why doesn't this work with embedded files?
Re: Using embedded images
May 04, 2010 09:20PM
GRRLIB_LoadTextureJPG tries to find the end of the file. If your JPEG file does not finish with 0xFF 0xD9 or those values appears before the end of the file, the function will failed. So that's why it's better to pass the size as parameter if you have it.
GRRLIB_texImg* img = GRRLIB_LoadTextureJPGEx(grrlib_logo_jpg, grrlib_logo_jpg_size);
The JPEG format does not include the size in the file header. PNG and Bitmap have that.
Re: Using embedded images
May 05, 2010 04:27PM
I tested it and everything works as it should. Thanks for the help!
Sorry, only registered users may post in this forum.

Click here to login