Welcome! Log In Create A New Profile

Advanced

[SDL_image]can't load png

Posted by TheDrev 
[SDL_image]can't load png
April 13, 2009 01:16PM
Hello;

I can't load png with port of sdl_image, bmp and jpg works...
I've linked with libpng from the ported library page and the one in libwiisprite but I got the sdl error : "unsupported image format" with a core dump on the first line that use the surface...



Edited 1 time(s). Last edit at 04/13/2009 01:46PM by TheDrev.
Re: [SDL_image]can't load png
April 13, 2009 07:03PM
you have to recompile SDL Image lib with PNG support. It's defined out in the SDL PNG image C file.
Re: [SDL_image]can't load png
April 13, 2009 08:30PM
Ok, I installed msys and mount mingw to devkitPPC toolchaine
I also downloaded the SDL_Image source from libsdl site.

and continue as in this tuto :
[blog.pantokrator.net]

Is that what you mean ?
Re: [SDL_image]can't load png
April 13, 2009 09:13PM
in SDL_Image there are several c files for each image type. IMG_png.c contains the functions for png support. When building the SDL_Image libs you have to define "#define LOAD_PNG" else the SDL IMG_Load will call these funtions:


/* See if an image is contained in a data source */
int IMG_isPNG(SDL_RWops *src)
{
	return(0);
}

/* Load a PNG type image from an SDL datasource */
SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
{
	return(NULL);
}


Unfortunately the SDL libraries on WiiBrew were not built with PNG support so you'll need to rebuild the SDL_Image from it's source.
Re: [SDL_image]can't load png
April 14, 2009 10:23PM
Thanks again for your help.

So, I try to compile SDL_Image with PNG, JPG and BMP support.
It the first time that I use cross compilation so I learned a lot since yesterday, and I've finnaly created the Makefile with configure having powerpc-gekko as host.

The google codewii SDL_Image for wii is 'Slightly modified SDL_image port to accept various types'.
I don't know what is 'Slightly modified' because there are no sources; I hope the SDL_Image 1.2.7 sources from libSDL page will be fine.
The only differance that diff show me is on the SDL_Image.h,

#include "SDL.h"
#include "SDL_version.h"
#include "begin_code.h"
.. 
#include "close_code.h"


is now

#include <SDL/SDL.h>
#include <SDL/SDL_version.h>
#include <SDL/begin_code.h>
...
#include <SDL/close_code.h>

I assum it is the same for other headers because I got errors like

MG_bmp.c:52:23: error: SDL_error.h: No such file or directory
IMG_bmp.c:53:23: error: SDL_video.h: No such file or directory
IMG_bmp.c:54:24: error: SDL_endian.h: No such file or directory

I'll figure that out later.....



I've finally understand how Makefile really works : makefile export to env vars the prefix for the toochain e.g powerpc-gekko and define some preprocessor cmd, so I include the wii_rule makefile in the begining of the makefile generated by SDL_Image's configure and I got a lot of pre-set option beside export CC, CXX and FLAGS myself in the shell.... (I'm sure this tips in know but anyway....)
For the moment, I'll try to compile only with -DLOAD_BMP=1, and I'll add jpg and png latter.


PS : I don't understand why png is not supported by libs provided in the wiki ???



Edited 10 time(s). Last edit at 04/15/2009 12:28AM by TheDrev.
Re: [SDL_image]can't load png
April 15, 2009 03:17AM
PS : I don't understand why png is not supported by libs provided in the wiki ???

I think at the time there were no ports of png or jpeg available. You will also need the png and jpeg libraries from the Wiki if you are using them in SDL. SDL is a wrapper for these and does not provide any real decoding for these formats.

If you just want to use a BMP then you don't need the SDL_Image library. You can just use - SDL_LoadBMP which is in the main libSDL.

A word of warning about the SDL library! It only uses hardware rendering for the primary screen, everything else is software so the performance is not that great. I found this out the hard way after writing my apps using it.
Re: [SDL_image]can't load png
April 15, 2009 01:42PM
All right, I've at last compiled the lib with PNG and JPG support, and link it with a SDL game. I'll test that later and if it works I'll put it on the sdl-port page :)

---------------------------

Edit

Ok ! I can load png, but the pixels colours are wrong, the there is some kind on blue shift (with every formats)
Original colour -> rendered coulour
white -> light blue
brown -> deep blue
blue -> red

SDL_TTF rendered font are in the good colour...



Edited 1 time(s). Last edit at 04/15/2009 09:46PM by TheDrev.
Re: [SDL_image]can't load png
April 16, 2009 12:59AM
make sure your surface masks are correct. Something like so. if red is blue then I bet the endianness is wrong,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        rmask = 0x00ff0000;
        gmask = 0x0000ff00;
        bmask = 0x000000ff;
        amask = 0x00000000;
#else
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0x00000000;
#endif


Also, like I said the quality of SDL blits is not very good as it's using software rendering. You'll notice this if you use GRRLIB and SDL to draw the same picture onscreen. The GRRLIB looks a hell of a lot better.
Re: [SDL_image]can't load png
April 16, 2009 02:09AM
Your probably right ! I'll see that tomorrow (I remember that I've played around some time ago with put pixel and bitwise, the render was depending on that byte order)

It's also strange that the .a is only 79ko ! (the one on the wiki is about 353).... ?

I'll check grrlib, it seems quit interessting, also SDL port is very slow if the bpp is >= 16 !

Thanks your help has been this time againe very helpfull !

I've learned a lot with that porting, msys, makefile, configure, CC vars & co, cross compiling...
I hope I can now port SDL_mixer with mp3 enabled (libmad) in no time :D



Edited 1 time(s). Last edit at 04/16/2009 02:12AM by TheDrev.
Re: [SDL_image]can't load png
April 16, 2009 07:02PM
I've solved the colour problem ! That was indeed a matter of endianess.

Looking to SDL_endian.h, we can see

/* The two types of endianness */
#define SDL_LIL_ENDIAN	1234
#define SDL_BIG_ENDIAN	4321

#ifndef SDL_BYTEORDER	/* Not defined in SDL_config.h? */
#if defined(__hppa__) || \
    defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
    (defined(__MIPS__) && defined(__MISPEB__)) || \
    defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
    defined(__sparc__)
#define SDL_BYTEORDER	SDL_BIG_ENDIAN
#else
#define SDL_BYTEORDER	SDL_LIL_ENDIAN
#endif
#endif /* !SDL_BYTEORDER */

None of them was declared in my configure or makefile, and the default choice is SDL_LIL_ENDIAN (certainly because intel architecture is most spreaded than powerpc)

It could be a good idea to add here ... #if (GEKKO) ... as displayed in the gcc -v command for powerpc-gekko-gcc toolchaine, but anyway I've simply added directly -DSDL_BIG_ENDIAN in the makefile.

I've also activated other display format but i dont have test them.
I'm gonna upload the lib and the header to the wiki (the header is the same than the actual SDL_Image on the wiki)



Edited 1 time(s). Last edit at 04/17/2009 11:38PM by TheDrev.
Sorry, only registered users may post in this forum.

Click here to login