Forums Archived

The forums are being archived. See this topic for more information.

Problem loading palettized images

Get help and support with Rubygame

Problem loading palettized images

Postby Cyrus » Thu Apr 02, 2009 9:21 pm

Hi!

I'm having trouble in loading palettized (png) images with rubygame. Using Surface#load just returns a grayscale surface, with all wrong pixel values.

I know that SDL can handle palettized images, so i would like to know if Rubygame can do so, and if it can, how to do that.

Thats it, my first post (of many i hope :D ).
Hope you can help me, its for a personal project that i'll post here later.
Cyrus
 
Posts: 4
Joined: Thu Apr 02, 2009 8:19 pm
Location: Paraíba - Brazil

Re: Problem loading palettized images

Postby jacius » Fri Apr 03, 2009 12:34 am

Rubygame doesn't have any methods for modifying the palette of images (i.e. there's no wrapper for SDL_SetPalette), but it should be able to load and display palettized images properly.

Trying now with a test image (a smiley face with a light blue squiggle, attached below), it loads and displays correctly for me, using this image and script:

indexed_image_test.png
indexed_image_test.png (1.26 KiB) Viewed 1531 times

Code: Select all
require "rubygame"
include Rubygame
s = Screen.new([150,150])
image = Surface.load("indexed_image_test.png")
image.blit( s, [0,0] )
s.update
sleep 5
Rubygame.quit

But perhaps there's an important difference between my image and yours. Could you attach the image that doesn't display correctly?

Also, it would help to know the versions of Rubygame and the SDL libs on your system. You can get that easily by running this command in bash:

Code: Select all
ruby -rrubygame -rpp -e "pp Rubygame::VERSIONS"
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Re: Problem loading palettized images

Postby Cyrus » Fri Apr 03, 2009 2:42 am

I've found out the true problem. :D

Looking again, I noticed that the loaded Surface wasn't grayscale. The problem was that I was getting the palette index of each pixel (using the data string returned by Surface#pixels), and using the index itself (and not the corresponding color) to paint the surface. I figured the error wasn't related to loading when testing that script you posted with your image, and again with mine, and both were displayed correctly.

I'm actually doing this to apply a kind of color mask effect over the Surfaces I load, without have to do get_at/set_at pixel by pixel, which is a little slower (I really don't know if there is a better/faster way to do that, but getting the pixel data String is working fine for me).

Thanks for your help man!
Cyrus
 
Posts: 4
Joined: Thu Apr 02, 2009 8:19 pm
Location: Paraíba - Brazil


Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron