But a bmp file also contains some metadata

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lor, and 8 bits to signify the amount of blue in a pixel’s color. If you’ve ever heard of RGB color, well, there you have it: red, green, blue. If the R, G, and B values of some pixel in a BMP are, say, 0xff, 0x00, and 0x00 in hexadecimal, that pixel is purely red, as 0xff (otherwise known as 255 in decimal) implies “a lot of red,” while 0x00 and 0x00 imply “no green” and “no blue,” respectively. Given how red Mr. Boddy’s BMP is, it clearly has a lot of pixels with those RGB values. But it also has a few with other values. Incidentally, XHTML and CSS (languages in which webpages can be written) model colors in this same way. In fact, for more RGB “codes,” see the URL below. http://www.w3schools.com/html/html_colors.asp Now let’s get more technical. Recall that a file is just a sequence of bits, arranged in some fashion. A 24 ­bit BMP file, then, is essentially just a sequence of bits, (almost) every 24 of which happen to represent some pixel’s color. But a BMP file also contains some “metadata,” information like an image’s height and width. That metadata is stored at the beginning of the file in the form of two data structures generally referred to as “headers” (not to be confused with C’s header files).6 The first of these headers, called BITMAPFILEHEADER, is 14 bytes long. (Recall that 1 byte equals 8 bits.) The second of these headers, called BITMAPINFOHEADER, is 40 bytes long. Immediately following these headers is the actual bitmap: an array of bytes, triples of which represent a pixel’s color.7 However, BMP stores these triples backwards (i.e., as BGR), with 8 bits for blue, followed 4 Image adapted from http://www.brackeen.com/vga/bitmaps.html. BMP actually supports 1 ­, 4 ­, 8 ­, 16 ­, 24 ­, and 32 ­bit color. 6 Incidentally, these headers have evolved over time. This problem set only expects that you support version 4.0 (the latest) of Microsoft’s BMP format, which debuted with Windows 95. Ah, Windows 95. 7 In 1 ­, 4 ­, and 16 ­bit BMPs (but not 24 ­ or 32 ­), there’s an additional header right after BITMAPINFOHEADER called RGBQUAD, an array that defines “intensity values” for each of the colors in a device’s palette. 5 4 < 16 This is CS50. Harvard College Fall 2010 by 8 bits for green, followed by 8 bits for red.8 In other words, were we to convert the 1 ­bit smiley above to a 24 ­bit smiley, substituti...
View Full Document

Ask a homework question - tutors are online