Howdy, Stranger!

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

Categories

bitmaps Dos 16 colors

Hi,
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.
E.g.
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.
Rachel

Comments

  • XLoomXLoom Member Posts: 129
    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 );
    getc(f);
    // 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
    XLoom
  • Justin BibJustin Bib USAMember Posts: 0

    < http://forcoder.org /> free ebooks and video tutorials about \ Visual Basic, Swift, Scratch, Visual Basic .NET, Assembly, C++, Objective-C, Ruby, JavaScript, C, Go, C#, Python, MATLAB, Java, Perl, R, PL/SQL, Delphi, PHP Kotlin, Julia, Bash, ABAP, VBScript, LabVIEW, Lua, Erlang, Awk, Crystal, SAS, Prolog, F#, Alice, Logo, ML, Scheme, COBOL, Dart, Ada, FoxPro, Fortran, Lisp, D, Apex, Scala, Clojure, Transact-SQL, Rust, Hack \ ________

Sign In or Register to comment.