Question: #ifndef _ _ ANSWER 0 4 _ H _ _ #define _ _ ANSWER 0 4 _ H _ _ #include #include #include #pragma pack

#ifndef __ANSWER04_H__
#define __ANSWER04_H__
#include
#include
#include
#pragma pack(push)// save the original data alignment
#pragma pack(1)// Set data alignment to 1 byte boundary
/*
* BMP files are laid out in the following fashion:
*--------------------------
*|Header |54 bytes
*|-------------------------
*| Image Data | file size -54(for 24-bit images)
*--------------------------
*/
/**
* BMP header (54 bytes).
* uint16_t is 16-bit unsigned integer
* uint32_t is 32-bit unsigned integer
* int32_t is 32-bit signed integer
*/
typedef struct _BMP_header {
uint16_t type; // Magic identifier
uint32_t size; // File size in bytes
uint16_t reserved1; // Not used
uint16_t reserved2; // Not used
uint32_t offset; // Offset to image data in bytes from
// beginning of file (54 bytes)
uint32_t DIB_header_size; // DIB header size in bytes (40 bytes)
int32_t width; // Width of the image
int32_t height; // Height of image
uint16_t planes; // Number of color planes
uint16_t bits; // Bits per pixel
uint32_t compression; // Compression type
uint32_t imagesize; // Image size in bytes
int32_t xresolution; // Pixels per meter
int32_t yresolution; // Pixels per meter
uint32_t ncolours; // Number of colors
uint32_t importantcolours; // Important colors
} BMP_header;
#pragma pack(pop)// restore the previous pack setting
typedef struct _BMP_image {
BMP_header header;
unsigned char *data;
} BMP_image;
// Given a BMP_image, create a new 16-bit image that is converted from a given //24-bit image // BMP_image *convert_24_to_16_BMP_image(BMP_image *image); For the given image, you may assume that it is a valid 24-bit image; otherwise, this function should not be called at all. You have to take the 24-bit representation and convert it into a 16-bit representation. Note that you should not modify the original image. Instead, the function should allocate new memory spaces to store the new header information and the new image data. The header information of the new image should not be identical to that of the original image. In particular, you would have to compute the number of bytes in each row and the total image size, and therefore the file size. You have to downscale 8 bits to 5 bits for each color. You have to scale 0 through 255 to 0 through 31. A division of a color value by 8 or a right shift of 3 position should achieve similar outcome because you are ECE26400 Purdue University 3 c Cheng-Kok Koh dealing with non-negative numbers. You also have to combine the three colors into two bytes (using perhaps bit-wise OR operation). Lastly, you have to store the two bytes into the data array of the new BMP image. It is important that the padding bytes, if required, are all assigned 0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!