Loading Png Files


zaephen

Member
Joined
Apr 3, 2010
Messages
126
Age
52
Location
KY, USA
I'm having a problem loading PNG images on the WIZ with SDL. Can anyone spot anything wrong with this code? It worked before on WinXP/Linux.
Here is the image loader function:
Code:
SDL_Surface* LoadImage(char* file_name) {
    /* Temporary storage for the image that is loaded. */
    SDL_Surface* loaded_image = NULL;

	/* The optimized image that will be used. */
    SDL_Surface* optimized_image = NULL;

    /* Load the image. */
    loaded_image = IMG_Load(file_name);

    /* Create an optimized image if nothing went wrong in loading the
       image. */
    if (loaded_image != NULL) {
		optimized_image = SDL_DisplayFormat(loaded_image);
		Uint32 colorkey = SDL_MapRGB(optimized_image->format, 255, 0, 255);
		/* Set all pixels of colorkey color to be transparent. */
		SDL_SetColorKey(optimized_image, SDL_SRCCOLORKEY, colorkey);
		/* Free the original image. */
		SDL_FreeSurface(loaded_image);
    }

    /* Return the optimized image. */
    return optimized_image;
}
This is how I'm trying to load the image:
Code:
player = LoadImage("test.png");
    if (player == NULL) {
		printf("Error loading player image!\n");
		return;
    }
The WIZ just hangs on the "Loading..." screen. I checked it on the PC and the error file says it failed to load the image. The image of course is present. I can change it to a .bmp file and it works perfect.
Any ideas why it won't work with PNG files?
 
do you have all the libs on your wiz?

try a wrapper script that captures the stdout/stderr output, this helps a lot finding some errors :)

Code:
#!/bin/sh
./nameofexecutableonwiz >stdout.txt 2>stderr.txt
cd /usr/gp2x/
./gp2xmenu
 
crow_riot said:
do you have all the libs on your wiz?
I'm not sure about that. I have firmware 1.2.1 installed and I assumed it had everything I needed in it (SDL stuff "just works"). PNG loading is handled by the SDL_image library I believe. Would it not be on the WIZ? Where could I get a copy of it for the WIZ?
Oh, thanks for the reply by the way ;).
 
Last edited by a moderator:
If the Wiz hangs in the "Loading" screen, probably a needed library is missing. For example there isn't SDL_gfx.so or libiconv.so in the firmware. Check your link project settings and quit the libraries that you don't use. You can use the next Linux command to see the libraries needed:

Code:
readelf -d program.gpe | grep "NEEDED"
 
I'm half way there now. I took the libSDL_image.so.0 or whatever it was called from my /tools/arm-gp2x-linux/lib directory and put it in with my executable on the WIZ. Now, the program doesn't hang but it doesn't display my sprites and tiles either?!
Any ideas?

Edit:
Actually, after thinking about it, SDL_image was working the whole time. In the above code example, if I changed my images to .bmp files they would load and work perfectly but SDL_image was still doing the work with the IMG_Load() function. Anyone else have problems using SDL_image?
 
SDL_imagen needs to load libpng.so if you use pngs. Check with pngs of 16 bpp or 24 bpp, 32 bpp could not be supported. Try to launch the program using termula, is a Linux terminal for wiz and you can see the error messages.
 
if you don't want to fiddle around with termula - really give the wrapper script a try. those two txt's (stderr.txt and stdout.txt) in combination with logview from the archives http://dl.openhandhelds.org/cgi-bin/wiz.cgi?0,0,0,0,14,232 makes it easy to get such problems solved.
 
Back
Top