The simplest representation scheme is the BMP (bitmap), in which the image is re
ID: 3636845 • Letter: T
Question
The simplest representation scheme is the BMP (bitmap), in which the image is represented as an mxn grid, with m rows, n columns, and therefore mn picture elements ("pixels"), plus a 56-byte (=448 bits) header. In this scheme, the color of each pixel is stored separately as a number with a fixed number of bits (usually either 8, 16, 24, or 32 bits). This is a quite space-intensive format! Representing each pixel with a k-bit number allows a selection of 2k distinct colors to appear in an image, but increases the storage requirements proportionately. For instance, the MCS Society logo (pictured below) measures 246 x 263, for a total of 64,698 pixels. A 16-bit BMP of this picture will therefore require 64698*16=1,035,168 bits to represent the grid, plus 56 additional bytes for the header, for a total of 1,035,616 bits.Of course, your computer system will report the size of the image in bytes or kilobytes (or even megabytes or gigabytes), not bits. Recall that there are 8 bits in a byte, 1024 bytes in a kilobyte, 1024 kilobytes in a megabyte, 1024 megabytes in a gigabyte. Thus, a 16-bit BMP version of this image will require 129,452 bytes, or 126.418 kilobytes. (This is one reason why the BMP format is so seldom used -- the logo as shown on this web page is in PNG format, and occupies only 10.4 kilobytes of space.)
For this exercise, you are to write a program that will determine the amount of storage space needed for a BMP image with a given width and height (in pixels) and number of bits per pixel ("pixel depth"). You should output the amount in terms of bytes, kilobytes, and megabytes.
Example: (computer prompts in bold, user responses in italics):
Name of image: MCS_Society_logo_2005_16bit.bmp
width (in pixels): 246-user response
height (in pixels): 263-user response
Number of bits per pixel: 16-user response
The image 'MCS_Society_logo_2005_16bit.bmp'
will require 1035616 bits of storage to represent in BMP format,
which is 129452 bytes, or 126.418 KB, or 0.123455 MB.
Explanation / Answer
Since you did not specify the language that this program must be written in, I will answer it in C++. If you are using C or Java, the syntax will be slightly different. #include using namespace std; int main( int argc, char **argv ) { string image_file; int width, height, bpp; // bpp = bits per pixel cout > image_file; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.