Bmp is 8 by 8 pixels and so it should take up 14 40 8

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: y get made? It turns out that copy.c relies on bmp.h. Let’s take a look. Open up bmp.h (as with Nano), and you’ll see actual definitions of those headers we’ve mentioned, adapted from Microsoft’s own implementations thereof. In addition, that file defines BYTE, DWORD, LONG, and WORD, data types normally found in the world of Win32 (i.e., Windows) programming. Notice how they’re just aliases for primitives with which you are (hopefully) already familiar. It appears that BITMAPFILEHEADER and BITMAPINFOHEADER make use of these types. This file also defines a struct called RGBTRIPLE that, quite simply, “encapsulates” three bytes: one blue, one green, and one red (the order, recall, in which we expect to find RGB triples actually on disk). Why are these structs useful? Well, recall that a file is just a sequence of bytes (or, ultimately, bits) on disk. But those bytes are generally ordered in such a way that the first few represent something, the next few represent something else, and so on. “File formats” exist because the world has standardized what bytes mean what. Now, we could just read a file from disk into RAM as one big array of bytes. And we could just remember that the byte at location [i] represents one thing, while the byte at location [j] represents another. But why not give some of those bytes names so that we can retrieve them from memory more easily? That’s precisely what the structs in bmp.h allow us to do. Rather than think of some file as one long sequence of bytes, we can instead think of it as a sequence of structs. 9 Note that some programs (e.g., Photoshop) include trailing zeroes at the ends of some BMPs. Our version of copy throws those away, so don’t be too worried if you try to copy a BMP (that you’ve downloaded or made) only to find that the copy is actually a few bytes smaller than the original. 8 < 16 This is CS50. Harvard College Fall 2010 Recall that smiley.bmp is 8 by 8 pixels, and so it should take up 14 + 40 + 8  8  3 = 246 bytes on disk. (Confirm as much if you’d like using ls.) Here’s what it thus looks like on disk according to Microsoft: offset 0 2 6 8 10 14 18 22 26 28 30 34 38 42 46 50 54 55 56 57 58 59 type WORD DWORD WORD WORD DWORD DWORD LONG LONG WORD WORD DWORD DWORD LONG LONG DWORD DWORD BYTE BYTE BYTE BYTE BYTE BYTE name bfType bfSize bfReserved1 bfReserved2 bfOffBits biSize biWidth biHeight biPlanes biBitCount biCompression biSizeImage biXPelsPerMeter biYPelsPerMeter biClrUsed biClrImportant rgbtBlue rgbtG...
View Full Document

Ask a homework question - tutors are online