Question: Work through the steps below in order. 1 - (2 points) Storing PPM images In steg.c, complete the declaration of struct PPM, which holds the

Work through the steps below in order. 1 - (2 points) Storing PPM images In steg.c, complete the declaration of struct PPM, which holds the image read from a PPM file. This will need to include the information from the PPM header (width, height, max), and a pointer to a dynamically-allocated array containing the pixel data. Your program should be able to deal with PPM files with arbitrary numbers of rows and columns. 2 - PPM functions Implement in steg.c the following functions. You may also write additional helper functions or type declarations if you like. The template includes some already, e.g. struct Pixel and readPPM, but you can rename or remove these provided you implement struct PPM, getPPM, showPPM, encode and decode. 2a - (2 points) Reading PPM files struct PPM *getPPM(FILE *f); To return a new struct PPM, containing the PPM image read from open file f. Use the fscanf function to read numbers from the file. Once you know width and height, construct a dynamic array of the appropriate size. Don't worry about handling comments in the PPM file for now. 2b - (2 points) Writing PPM files void showPPM(const struct PPM *img); To output the PPM image img to stdout (e.g. by using printf), following the syntax in the PPM specification. You should test this function by using it to write out an image loaded with getPPM. The template code's main function has an extra t t mode for this. 2c - (2 points) Encode data struct PPM *encode(const char *text, const struct PPM *img); To return a copy of PPM image img with message text hidden in its red pixel values. You will need to make it replace successive random red pixels with the characters from the message. How you select pixels is up to you, but make sure that the pixels are chosen in a consistent order (e.g. left to right, top to bottom) and enough pixels are selected to encode all of the message.

2d - (2 points) Decode data char *decode(const struct PPM *oldimg, const struct PPM *newimg); to return a new string containing the message hidden in the red pixel values of PPM image newimg, by comparing it with the red pixel values of PPM image oldimg. The length of the string that it allocates and returns will depend on the length of the message. You may impose a limit on the maximum length of a decoded message if this makes the implementation easier. 3 - (6 points) Steganography program Complete the main behaviour of the steg program, which encodes or decodes images based on its command-line arguments as described above. 4 - (2 points) Additional PPM features For an additional 2 points, implement one of the following two features: Make getPPM and showPPMread and write comments, by storing the comments as a linked list of strings in struct PPM. You can assume that any comment lines will always be immediately before width (although the PPM specification says they're allowed to occur anywhere in the file). You will need to rework how you read width if the first character you read is a #, then you have a comment, else it must be a digit and should be counted as part of width . Make getPPM handle normal PPM files as well as Plain PPM. Normal PPM files start with P6 instead of P3, and have the image data stored directly as bytes (one or two bytes per colour, depending on max) rather than as decimal numbers see the PPM specification for more details. You can read data like this using the fread function.

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 Databases Questions!