Other graphic format

Hello all !!!

Someone knows how to implement other graphics format diferent from .bmp
?

I’m using the libpng lib but can’t make graphics appear on screen.
I load the graphic, uncompress it, and then I allocate a new
SDL_Surface,
but when I make blit, it does nothing.

I think I am using 5,6,5 graphics format so I use this bitmask but…
nothing.

Can someone help me.

PNG should be fine, but I want use jpg too…

Sorry if nobody can undestand my english :wink:

Gonzalo Aguilar wrote:

Hello all !!!

Someone knows how to implement other graphics format diferent from .bmp
?

I’m using the libpng lib but can’t make graphics appear on screen.
I load the graphic, uncompress it, and then I allocate a new
SDL_Surface,
but when I make blit, it does nothing.

I think I am using 5,6,5 graphics format so I use this bitmask but…
nothing.

Can someone help me.

PNG should be fine, but I want use jpg too…

You haven’t given enough information about your code to let us
give you accurate help, but I have not had any trouble loading
PNG images onto SDL surfaces. Here’s what I did:

  • Open the PNG file and load the image header.
  • Allocate a 24-bpp or 32-bpp surface with the same dimensions
    as the image. Choosing 32-bpp or 24-bpp depends on whether the
    PNG image has an alpha channel or not.
  • Tell pnglib to invert alpha values.
  • Lock the surface
  • Allocate a vector of row pointers that point into the SDL
    pixel buffer
  • Read the image into the memory pointed at by the row vector.
  • Unlock the surface
  • Optionally, copy the surface onto another a surface with the
    same format as the display. This is to optimise the drawing
    of large backdrops that do not have an alpha channel.

I’m deliberately ignoring paletted images and images with 16-bit
pixels, since I have control over the format of graphics that will
being used by the program.

Cheers,
Nat.–
±-----------------------------------------±--------------------+
| Name: Nat Pryce MEng ACGI | Dept. of Computing, |
| Email: np2 at doc.ic.ac.uk | Imperial College, |
| Tel: +44 (0)171 594 8394 | 180 Queen’s Gate, |
| Fax: +44 (0)171 581 8024 | London SW7 2BZ, |
| WWW: http://www-dse.doc.ic.ac.uk/~np2 | United Kingdom |
±-----------------------------------------±--------------------+

You should try the imglib! It’s one of the SDL examples available at the
SDL hompage. This is the way most SDL programs load their graphics.

Karl

Aguilar wrote:>

Hello all !!!

Someone knows how to implement other graphics format diferent from .bmp
?

I’m using the libpng lib but can’t make graphics appear on screen.
I load the graphic, uncompress it, and then I allocate a new
SDL_Surface,
but when I make blit, it does nothing.

I think I am using 5,6,5 graphics format so I use this bitmask but…
nothing.

Can someone help me.

PNG should be fine, but I want use jpg too…

Sorry if nobody can undestand my english :wink:

Gonzalo Aguilar wrote:

Hello all !!!

Someone knows how to implement other graphics format diferent from .bmp
?

I’m using the libpng lib but can’t make graphics appear on screen.
I load the graphic, uncompress it, and then I allocate a new
SDL_Surface,
but when I make blit, it does nothing.

I think I am using 5,6,5 graphics format so I use this bitmask but…
nothing.

I’m not too familiar with libpng, but I’ll hazard a guess that the raw
bitmap data that you’re getting from libpng isn’t quite the same as the
raw bitmap data you’ll find in the ‘pixels’ member of an SDL_Surface.
You’ll probably have to do some conversions, which may not be trivial,
before squeezing the thing into the surface. If it’s also a true-color
mode, then you may have to do some shifting and masking of the PNG data
before feeding it to the pixels array. And be careful about doing this!
Each scan line in the pixels array contains a number of pixels equal to
the ‘pitch’ member of the SDL_Surface, not its ‘w’ member! I choked on
this once, trying to load a custom graphics format. If it’s a
true-color PNG and you’re trying to display it on an 8-bit palettized
mode, then you have a lot of problems indeed! You’ll need to quantize
the palette first, and that is not incredibly easy to do. I think I
still have some code to do that if you really need it, but it does not
run with any speed approximating real-time! You should convert such
pictures to a palettized mode first, if you wish to keep your sanity
(ImageMagick comes to mind…).

PNG should be fine, but I want use jpg too…

I suppose libjpeg ought to be sufficient for you to decompress and read
a JPEG image. But unless you are operating in a true color mode of some
kind, things are difficult, and you may have to perform conversions like
those above. And you 'll really have no choice but to use a
palette-quantization algorithm to display it on an 8-bit color display!

Sorry if nobody can undestand my english :wink:

Your English is passable enough.–

| Rafael R. Sevilla @Rafael_R_Sevilla |
| Instrumentation, Robotics, and Control Laboratory |

College of Engineering, University of the Philippines, Diliman

Karl Bartel wrote:

You should try the imglib! It’s one of the SDL examples available at the
SDL hompage. This is the way most SDL programs load their graphics.

  1. How does Loki do it?

  2. Should this be in the FAQ?

  3. Same questions regarding text.–
    Marc Lepage
    Software Developer
    Molecular Mining Corporation
    http://www.molecularmining.com/