cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/21/00:46:22

From: "Charles Crawshaw" <c_crawshaw AT thefree DOT net>
Newsgroups: comp.os.msdos.djgpp
References: <01bd3cb6$33fd61c0$LocalHost AT none>
Subject: Re: Reading a bitmap (.bmp)
Date: Fri, 20 Feb 1998 11:51:56 -0000
Lines: 52
NNTP-Posting-Host: nas10-32.thefree.net
Message-ID: <34ed6f79.0@news.thefree.net>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mark wrote in message <01bd3cb6$33fd61c0$LocalHost AT none>...
>I've been trying to read a bitmap file recently,
>and have been having difficulty locating pallete
>entries, as well as finding inconsistencies in the way
>bmp files are written.
>
>Does anybody know where all the stuff to do with the pallete
>is actually located? I've managed to locate the actual data,
>and the resolution indicators by myself. I know I'll eventually
>be able to figure this out on my own, I just want to save a little
>time. If anybody could give me a little background on why the
>files are changing so slightly when they are saved, that would
>be even better. Failing that, resources where this information
>is availible would also be appreciated.
>
>Thanks in advance.
>
> -Mark
> -apocalypse AT BTinternet DOT com

I assume your talking about 256 color bitmaps when you want the palette.
24bit ones have no palette. The palette in 256 color bitmaps is stored at
offset (dec) 54 into the file.

The file format is such that you read the byte for blue then green then red
and then an alignment byte (which you ignore). This means the palette does
not take up 3*256 bytes as you might expect, but rather 4*256. The data
comes straight after the palette. The data starts at offset 1078 (dec).

Be careful when reading the data because the bitmap format aligns the data
in a strange way. This only happens with files which have an odd number
width. Say you have a file which is 3x3 and is just one color (index 10).
The data will look as follows:

0a 0a 0a 00 0a 0a 0a 00 0a 0a 0a 00

If you had a 5x5 file it would look like this:

0a 0a 0a 0a 0a 00 00 00 0a 0a 0a 0a 0a 00 00 00 0a...

I hope you understand this. Look at a file in a hex editor to get a better
understanding.

24bit bitmaps start the data at offset 54 (dec) and have no palette. They
just have blue then green then red data for each pixel.






- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019