Reference no: EM132168018
Description
In this assignment, you are going to write a C program to access PGM image files (description was given in Assignment 4). In addition, you need to save the image data into 8 x 8 blocks using the struct defined below.
#define N 8
typedef struct _Matrix { double element[N][N];
} Matrix;
If the image size is not divisible by 8; then pad the boundary blocks with zeros.
First, you need to read two arguments from the command prompt, which will be used for input file and output file Then, do the following steps.
1. Open and Read the PGM image
2. Dynamically allocate the memory and Read the data into a buffer
3. Convert the data into 8 x 8 blocks and return the pointer to the main function
4. Pass the pointer to the Write function
5. Write the data buffer to the file using a binary format (either P5 or P6)
6. Release the memory
Your main function should look like the following
int main(int argc, char **argv)
{
if (argc == 3) {
int w, h, nBlock, channel;
Matrix *data = ReadImage(argv[1], &w, &h, &nBlock, &channel);
WriteImage(argv[2], data, w, h, channel); free(data);
}
else {
fprintf(stderr, "Usage: %s image_path output_path\n", argv[0]);
exit(1);
}
return 0;
}