Question: The PPM image format You will work with Plain PPM format images. This is one of a family of simple open source image formats, designed
The PPM image format You will work with Plain PPM format images. This is one of a family of simple open source image formats, designed to be read and written easily by C programs. See the PPM specification for full details of PPM and Plain PPM. A Plain PPM file consists of ASCII text: P3 # comment1 # ... # commentN width height max r1 g1 b1 r2 g2 b2 r3 g3 b3 ... where: P3 - code indicating Plain PPM format comment - arbitrary optional comment text width - integer number of columns height - integer number of rows max - integer maximum colour value - usually 255 ri gi bi - integers between 0 and max for pixel i's red, green and blue values All integers are in decimal. (From now on, I will refer to Plain PPM just as PPM.)
Requirements This project as a whole is marked out of 20 points, and makes up 50% of your final mark for the course. The program overall should be valid C99 (or later), and should be robust against error. 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. 5 - (2 points) Report In Report.md, you should give a brief description no more than a couple of pages of text of: Your program design Your choice of data structures and algorithms Write Report.md using Markdown syntax, which will allow GitLab to render it nicely as HTML. See the Markdown Guide, or the help within GitLab, for more details.

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
