BPP issues

Hi,

I know quite a bit of discussion has already gone on about this subject
but I have a question that’s bugging me.

I was told that the SDL blit routines do not do colour conversion
between the different surfaces. So why is it that when I
load a 24 bit BMP file using SDL_LoadBMP() and then blit it to the (16
bit) screen, it works fine. I’m confused!

-Lea.

Hi,

I know quite a bit of discussion has already gone on about this subject
but I have a question that’s bugging me.

I was told that the SDL blit routines do not do colour conversion
between the different surfaces. So why is it that when I
load a 24 bit BMP file using SDL_LoadBMP() and then blit it to the (16
bit) screen, it works fine. I’m confused!

They do color conversion when blitting. :slight_smile:

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Sam Lantinga wrote:

They do color conversion when blitting. :slight_smile:

Thanks Sam. I thought they did, I just didn’t know if I’d discovered a
"feature". Do you think it’d be too much of an overhead to do all low level
GFX manipulations in 32 bits then blit to the screen? You mentioned before
that 24 bit operations being the slowest so do you have any benchmarks?

Cheers Sam,

-Lea.

Lea Anthony wrote:

Hi,

I know quite a bit of discussion has already gone on about this subject
but I have a question that’s bugging me.

I was told that the SDL blit routines do not do colour conversion
between the different surfaces. So why is it that when I
load a 24 bit BMP file using SDL_LoadBMP() and then blit it to the (16
bit) screen, it works fine. I’m confused!

I think that this color conversion refers to palette quantization, which
is not performed in any version of SDL. Blit a 24-bit BMP to a
15/16/24/32-bit and you have no problems. But blit a true color BMP to
an 8-bit surface and everying will go to hell.–

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

College of Engineering, University of the Philippines, Diliman

“Rafael R. Sevilla” wrote:

Lea Anthony wrote:

Hi,

I know quite a bit of discussion has already gone on about this subject
but I have a question that’s bugging me.

I was told that the SDL blit routines do not do colour conversion
between the different surfaces. So why is it that when I
load a 24 bit BMP file using SDL_LoadBMP() and then blit it to the (16
bit) screen, it works fine. I’m confused!

I think that this color conversion refers to palette quantization, which
is not performed in any version of SDL. Blit a 24-bit BMP to a
15/16/24/32-bit and you have no problems. But blit a true color BMP to
an 8-bit surface and everying will go to hell.

Doh! Thanks for the info. Any pointers on 32 -> 8 bit colour conversion?
Presumably
I’ll have to scan the picture for most used colours and set up palette values
based on
that information and do a best match for the rest? Is it in Foley, Van Damme,
et all?

Thanks for your help,

-Lea.

Lea Anthony wrote:

“Rafael R. Sevilla” wrote:

Lea Anthony wrote:

Hi,

I know quite a bit of discussion has already gone on about this subject
but I have a question that’s bugging me.

I was told that the SDL blit routines do not do colour conversion
between the different surfaces. So why is it that when I
load a 24 bit BMP file using SDL_LoadBMP() and then blit it to the (16
bit) screen, it works fine. I’m confused!

I think that this color conversion refers to palette quantization, which
is not performed in any version of SDL. Blit a 24-bit BMP to a
15/16/24/32-bit and you have no problems. But blit a true color BMP to
an 8-bit surface and everying will go to hell.

Doh! Thanks for the info. Any pointers on 32 -> 8 bit colour conversion?
Presumably
I’ll have to scan the picture for most used colours and set up palette values
based on
that information and do a best match for the rest? Is it in Foley, Van Damme,
et all?

Unfortunately, Foley and van Dam don’t really discuss the algorithms in
great detail in their excellent book. They just mention the various
algorithms like Paul Heckbert’s popularity and median cut algorithms (if
you have access to a copy of the SIGGRAPH 82 proceedings you can find
his own paper on it there: “Color Image Quantization for Frame Buffer
Display”). In Chris Watkins’ book “Photorealism and Ray Tracing in C”,
there’s a small program there that implements the median cut algorithm
in order to convert the true color images his ray tracer makes into
GIFs. Mail me privately if you want a copy. Shouldn’t be too hard to
adapt to what you need to do. I used to have an old issue of Dr. Dobb’s
Journal that described an interesting new algorithm for color
quantization (octree quantization), but I can’t seem to find it right
now. Around 1995-1996 I think. Check their archives.–

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

College of Engineering, University of the Philippines, Diliman

Rafael,

Thanks for your reply. I’d love to have a copy of that code. I guess I could deduce
what’s going on from that.
Are you sure it was octree quantisation and not quadtree quantisation? I did some
research on images stored in quadtrees and I can see how you could easily do a
recursive quantisation algorithm using that data structure.
I always thought octrees were for 3D space partitioning, to speed up ray tacers
etc. Maybe I’m wrong (I’d love to be :slight_smile: ).
I’m all ears for new algorithms. There is good stuff at ftp://ftp.oulu.fi/ but I
cannot use FTP from my terminal here so I’m lost :frowning:

Thanks for the discussion!

-Lea.

“Rafael R. Sevilla” wrote:> Unfortunately, Foley and van Dam don’t really discuss the algorithms in

great detail in their excellent book. They just mention the various
algorithms like Paul Heckbert’s popularity and median cut algorithms (if
you have access to a copy of the SIGGRAPH 82 proceedings you can find
his own paper on it there: “Color Image Quantization for Frame Buffer
Display”). In Chris Watkins’ book “Photorealism and Ray Tracing in C”,
there’s a small program there that implements the median cut algorithm
in order to convert the true color images his ray tracer makes into
GIFs. Mail me privately if you want a copy. Shouldn’t be too hard to
adapt to what you need to do. I used to have an old issue of Dr. Dobb’s
Journal that described an interesting new algorithm for color
quantization (octree quantization), but I can’t seem to find it right
now. Around 1995-1996 I think. Check their archives.

| Rafael R. Sevilla dido at pacific.net.ph |
| Instrumentation, Robotics, and Control Laboratory |

College of Engineering, University of the Philippines, Diliman

Lea Anthony wrote:

Rafael,

Thanks for your reply. I’d love to have a copy of that code. I guess I could deduce
what’s going on from that.
Are you sure it was octree quantisation and not quadtree quantisation? I did some

If you think about it, color processing is 3d, so using octrees is a
feasible solution. I believe that algorithm uses bounding boxes of
equal size to determine what colors to use.

-Eric