re what does the bmp format mean in article robertsa unix tcd ie robertsa unix tcd ie andrew l roberts writes what exactly does the windows bitmap format look like i mean how is the data stored width height no of colours bitmap data i couldn t find anything in ths user manual is there any other reference material which would give me this information from thomas sunshine kodak com thomas kinsman newsgroups comp os ms windows programmer misc alt binaries pictures utilities subject dib bmp creation guide as requested keywords dib bmp bitmaps file formats message id dec kodak kodak com date dec gmt sender news kodak kodak com organization precambiran electronics rochester ny lines xref cradle titech comp os ms windows programmer misc guide to creation of dib images thomas b kinsman precambrian electronics falstaff rd rochester ny thomask kodak com copyright march abstract the format of images created for use by ms windows applications is documented in the ms windows programmer s reference guide this guide is intended as a clearify some wording of the specifications and to put forth a recommendation among the various alternatives please send updates corrections suggestions and revisions to me please thank me for writing this on my own time by keeping my name with the document thank you for your respect this document copyright by thomas b kinsman if desired a postscript version of this document is available this information is free you get more than what you pay for don t sue me if i m wrong overview the dib image file format is intended to be a device independent bitmap file format what microsoft means by device independent is unclear to me four pixel resolutions are supported bit bit bit and bit pixels these images were intended for use on dos ibm or little endian systems if you are creating them on another architecture you will have to byte swap all short and long integer values by convention dib images end in the extension bmp this is because march they are a super set of earlier bitmap image files consequently you will sometimes hear dib files referred to as bmp files since dib images files are a super set there are three flavors of dib images o dos dib images these are the recommended convention and the form which i will describe how to create they are intended for applications running under ms windows in a dos environment o os dib images my understanding is that these are the flavor of dib images that were used by the presentation manager o old style bitmap images march differences between flavors the dos dib images consist of a bitmapfileheader file header which identifies the file as a dib file this header also gives the total size of the image file and the offset to the image data a bitmapinfoheader image header which specifies the image attributes an optional palette of colors used by the image if it exists this may contain or entries each entry is a windows rgbquad structure the image data itself the os dib images consist of the same bitmapfileheader file header which identifies the file as a dib file this header also gives the total size of the image file and the offset to the image data a bitmapcoreheader image header which specifies the image attributes an optional palette of colors used by the image again if this exists it may contain or entries each entry is a windows rgbtriple structure the image data itself the old style image bitmap consists of either a bitmapinfoheader or a bitmapcoreheader which header type is determined by the first long integer dword value an optional color palette this palette may be composed of either windows rgbquad structures if the header was a bitmapinfoheader or windows rgbtriple structures if the header was a bitmapcoreheader the image data itself creating dib image files creating a dos dib image file consists of several straight forward steps the headers need to be created and then written to the file these header structures are defined in the ms windows windows h include file palette information needs to be stored for images that are not bit images the five general steps are filling in the bitmapfileheader and the bitmapinfoheader structures the basic image information if the image is a bit bit or an bit image creating the color palette of rgbquads calculating the total file size and putting this information in march the bfsize field of the bitmapfileheader calculating the offset to the image data from the start of the file and putting this in the bfoffbits field of the bitmapfileheader writing to the file the bitmapfileheader the bitmapinfoheader the color palette and the image data in that order the following sections describe structures in terms of microsoft c type defined keywords the following table describes these keywords for those not familiar with microsoft c type defined keywords in microsoft c typedef meaning byte unsigned character word two byte unsigned integer dword four byte unsigned integer march the bitmapfileheader this structure is defined in windows h as typedef struct tagbitmapfileheader word bftype dword bfsize word bfreserved word bfreserved dword bfoffbits bitmapfileheader the bftype field is the two ascii characters b and m this serves to identify the file as a dib image file on an intel byte ordered machine ibm or a compatible this constant can be formed in c as the quantity m b x d on an intel system the bfsize field is the total size of the file for our purposes this field is equal to the size of the bitmapfileheader plus the size of the bitmapinfoheader plus the number of entries in the color palette times the size of a rgbquad plus the number of bytes of image data if the image data is being written out in an uncompressed form this value can be calculated ahead of time otherwise this field needs to be filled in later both the bfreserved and the bfreserved fields are always set to zero the bfoffbits field is set to the offset to the start of the image data from the start of the file for our purposes this field should be set to the size of the bitmapfileheader plus the size of the bitmapinfoheader plus the number of entries in the color palette times the size of a rgbquad this works out because the image data is written write after the color palette if one exists march the bitmapinfoheader this structure is defined in windows h as typedef struct tagbitmapinfoheader dword bisize dword biwidth dword biheight word biplanes word bibitcount dword bicompression dword bisizeimage dword bixpelspermeter dword biypelspermeter dword biclrused dword biclrimportant bitmapinfoheader the bisize field is set to the size of the bitmapinfoheader structure itself when reading the image file this value is what is used to determine that the image contains a bitmapinfoheader and not a bitmapcoreheader the biwidth field is the width of the image in image pixels the biheight field is the height of the image in image lines the biplanes field should always be set to this data is written out as if there was one color plane the bibitcount field is the bit depth of the image this must be either or depending on the bit depth of the image data the bicompression field tells how the image data is compressed if it is compressed dib images support two forms of run length encoding however i have never seen any images which use it and don t know yet how it works set this field to zero long zero or l to indicate that the data is not compressed all subsequent fields of the bitmapinfoheader structure may be set to zero a requirement of the interpretting software that it be able to compute these fields as necessary from the previous information the field which you might want to explicitly specify might be biclrused for bit and bit images this field indicates that not all of the possible color entries are used and that the image contains biclrused colors if you are using only colors with an bit image then you may only want to save of the possible palette entries generally set this field to zero march color palettes each entry of a color palette is a rgbquad structure the rgbquad structure is defined in the windows h include file as typedef struct tagrgbquad byte rgbblue byte rgbgreen byte rgbred byte rgbreserved rgbquad the rgbreserved field is always zero for each color used the amount of blue green and red are filled into the structure and the structure is written to the file a value of zero in the rgbblue rgbgreen or rgbred fields indicates that that particular component does not contribute to the color composition a value of in any of these fields indicates that the component contributes fully to the color composition image data there are three surprises about the ordering of image data in dib image file the creator of this format was determined to be creative and certainly was within the image data each line written out is padded to the next four byte quantity so if you had an bit image which was only one pixel wide you still have to write out four bytes for every image line the number of bytes per line can be calculated as bytes per line width in pix bit depth or in terms of the fields of the bitmapinfoheader structure bytes per line biwidth bibitcount when writing out your image data you must write it out bottom line first the bottom line of the image as you would look at it on the screen is the first line of image data in the file for bit bit and bit images information is written as you would expect one bit images are padded eight pixels to a byte four bit images are padded two pixels to a byte eight bit images are written one pixel per byte twenty four bit images are written three bytes per pixel however for bit images the information must be written out in the order blue green red while most image file formats write data out in march an rgb ordering a dib image file writes the data out in an bgr ordering summary this should provide enough information to create dib images from applications such as scanners or for image exporting routines if you find out any more about dib images please pass the information on to me so that i can modify this document accordingly march thomas b kinsman rochester ny thomas acadia kodak com practice random kindness and senseless acts of beauty anon ito takayuki yuki is s u tokyo ac jp senior department of infomation science faculty of science university of tokyo japan
