Difference between a 1-bit image and an indexed image when loaded into surface

Hi.

I’m writing a bit of code to convert SDL_Surface structures into OpenGL
textures.

Is it possible to programmatically tell the difference between:

  • 1-bit monochrome image
  • 1-bit monochrome image with alpha
  • indexed image
  • indexed image with alpha

The last two, I can distinguish between with:

if (images[ind].img->flags & SDL_SRCCOLORKEY)
gltxload.flags |= GLTEX_ALPHA;

So that’s not a problem, but how can I tell the difference between
an indexed or monochrome image? The ‘file’ utility can tell for PNGs,
so at least for PNG files the images are structurally distinct:

IMAGES/1bit_alpha.png: PNG image data, 128 x 128, 1-bit colormap,
non-interlaced
IMAGES/1bit_noalpha.png: PNG image data, 128 x 128, 1-bit colormap,
non-interlaced
IMAGES/indexed.png: PNG image data, 128 x 128, 2-bit colormap,
non-interlaced
IMAGES/indexed_alpha.png: PNG image data, 128 x 128, 2-bit colormap,
non-interlaced

The point of this exercise is that I want to be able to load 1 bit
images into OpenGL as (memory) efficiently as possible, for things
such as bitmap fonts. The color can obviously be set at load time.

Any help would be appreciated.
MC

Hello !

  • 1-bit monochrome image
  • 1-bit monochrome image with alpha

I am not sure, but i don’t think
SDL supports Monochrome Surfaces.

As SDL was created in times when you had
at least 8 Bit Color Support with VGA.

Personally i would write a converter to
convert from normal PNG (Alpha) Images to
your own Monochrome Format or just do it runtime.

When you loaded a normal PNG (Alpha) and converted it,
you can just free the PNG (Alpha) Image and instead use
your own Mono. Format. As Mono.

CU

Ok, thanks!

I’ll get to work on a quick PNG loader.

MCOn 16/02/07, Torsten Giebl wrote:

Hello !

  • 1-bit monochrome image
  • 1-bit monochrome image with alpha

I am not sure, but i don’t think
SDL supports Monochrome Surfaces.

As SDL was created in times when you had
at least 8 Bit Color Support with VGA.

Personally i would write a converter to
convert from normal PNG (Alpha) Images to
your own Monochrome Format or just do it runtime.

When you loaded a normal PNG (Alpha) and converted it,
you can just free the PNG (Alpha) Image and instead use
your own Mono. Format. As Mono.

Hello !

I’ll get to work on a quick PNG loader.

For an “On the fly” or "Do it Once Forever"
Converter you can look at how SDL_image handles
PNG files and Copy&Paste the needed Code or you
can just use SDL_image in your app.

CU