You are not logged in.

#1 2008-11-30 02:03:35

DrTwox
Member

GRRLIB with libjpeg support

Hello again.

This is a basic example of loading a jpg image and using GRRLIB_DrawImg to draw in on screen.  The jpg loading function (GRRLIB_LoadJPG) is as close to GRRLIB_LoadImg as I could make it.  See the included source for a useage example, or try the included .dol file to see it in action.

Note: This is not using the JPEG_Decompress wrapper from jpgogc.h to draw onto a framebuffer, this decodes into a texture format usable by GX, just like the LoadImg function does.

link

Offline

 

#2 2008-11-30 10:57:53

JustWoody
Member

Re: GRRLIB with libjpeg support

Nice one DrTwox I was looking at something like this a while back to use for the backgrounds to my game as jpeg way smaller than png and no need for transparency for backgrounds.

Never got round to doing a through investigation myself so thanks very much for posting this big_smile

Offline

 

#3 2008-11-30 14:33:59

JustWoody
Member

Re: GRRLIB with libjpeg support

OK now that I have tried to use this I can't seem to get it working!

Firstly I was getting this error:-

Code:

In file included from d:/projects/wii/mahjongg/source/GRRLIB/../libjpeg/jpeglib.h:26,
                 from d:/projects/wii/mahjongg/source/GRRLIB/GRRLIB.h:18,
                 from d:/projects/wii/mahjongg/source/game.h:15,
                 from d:/projects/wii/mahjongg/source/game.c:7:
d:/projects/wii/mahjongg/source/GRRLIB/../libjpeg/jmorecfg.h:227: error: conflicting types for 'u8'
d:/devkitPro/libogc/include/gctypes.h:22: error: previous declaration of 'u8' was here

I commented out the typedef int boolean; (not sure what this has to do with u8 but this is the line with the error on it) within jmorecfg.h and this got rid of the error and all compiled correctly.

I changed my splash screen to jpg and all I get when running is a black screen. I know its not much to go on, but does anyone know what this may be.

For more background I am letting the compliation process create my c and h files for my jpeg by putting it the data file along with all my other resources + am using the source version of the libjpeg

Cheers

Justin

Last edited by JustWoody (2008-11-30 14:34:48)

Offline

 

#4 2008-11-30 15:09:56

JustWoody
Member

Re: GRRLIB with libjpeg support

I got it working!

All I did was to add this before including jpeglib.h

Code:

#undef boolean

This enable the define in jpeglib.h to override the existing on defined in gctypes and all seems to work alright still!

Offline

 

#5 2008-11-30 22:22:38

DrTwox
Member

Re: GRRLIB with libjpeg support

Thanks for the positive feedback; it's very appreciated smile

As you have seen from my help request over at wiibrew, I did have some problems "backporting" this code from my own library, and could only get the example app to compile with careful ordering of the #includes.  The post that suggests a better solution came after I posted the .zip file, so I'll update my example code when I get home from work.

As I point out in the code, you won't really save much memory (only the difference between the original jpg vs png) as the texture is still "uncompressed" to a RGBA format for GX (GX_TF_RGBA8 specifically).  However, something I plan on doing (though not for a while though) is using some of the more efficient texture formats GX supports.  Once it's working, I'll port the changes over to GRRLIB.

Offline

 

#6 2009-01-03 10:33:01

sammystag
Member

Re: GRRLIB with libjpeg support

This is very useful thanks. As well as saving runtime memory, a big advantage is reducing the size of the distribution.

I've used the following simple function to load the jpeg from a file (very similar to my function for PNGs posted elsewhere on here). This should save more memory as the file contents are not stored in memory once the image is loaded.

Code:

u8 * GRRLIB_LoadFileJPG(const char *filename) {

    FILE *fd = fopen(filename, "rb");

    // obtain file size:
    fseek(fd , 0 , SEEK_END);
    long lSize = ftell(fd);
    rewind(fd);

    // read the file
    unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lSize);
    fread (buffer, 1, lSize, fd);
    fclose(fd);

    // load data into a texture
    u8 *tex = GRRLIB_LoadJPG(buffer, (unsigned int)lSize);
    
    free(buffer);
    return tex;
}

NOTE: you will need to initialise the file system before using this as follows

Code:

#include <fat.h>

.....

fatInitDefault ();

Offline

 

Board footer

Powered by FluxBB