bitmaps Dos 16 colors

I am writting C code for DOS 12h mode that reads a bitmap and displays
the image to the screen.

My problem is that when I generate an image in MS Paint (16 color mode) the index values are different from the expected values assigned in dos.
The expected index value for blue 1
When I use a hex editor to look at the values from the 16 color bmp from MS paint the value is 4.

Why are there discrepencies and is there a way such that I can match the colors from paint when I draw them with my dos program?
Thanks in advance.


  • Hi,
    there are a few things you could check:
    1. Do you change the palette according to the bitmap? Because the bitmap palette almost always differs, especially when using MS Paint, from DOS default palette. And unless you use for example Photoshop, which lets you define a palette for bitmap, you should change the palette after changing to mode 0x12 (12h). This is done like this (I hope it works with mode 0x12 as I have only tried it with 0x13):

    // A function to set a specific color in palette
    void set_palette ( int index, int red, int green, int blue){
    outportb ( 0x3c8, index );
    outportb ( 0x3c9, red );
    outportb ( 0x3c9, green );
    outportb ( 0x3c9, blue );

    Now if blue is the fourth color in bitmap, you set it like this

    set_palette ( 3, 0, 0, 63 );

    Index starts from zero, so we write 3 instead of 4 into the index field, zeros for red and green and 63 for blue. This whole thing is quite stupid, but DOS colors do not vary from 0-255, but instead from
    0-63, and then they start all over again. I think it is true for mode 0x12 as well. So when loading a file you need to divide all values with 4.

    I had a lot more written here, but this stupid thing logs out in time and AAARGHHH it was all gone. And I am out of time, so here is what I would do very shortly:

    1. Load bitmap stuff before palette

    2. Load palette ('f' is the filehandle 'FILE *f')

    for ( int i=0 ; i<16 ; i++ ){
    set_palette( i, getc(f)/4, getc(f)/4, getc(f)/4 );
    // An extra getc() because palettes tend to use word alignment,
    // if it won't work, delete it

    3. The loading of the rest of the bitmap

    I hope this helps you, as messy as it is
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion