Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The current program only copies the image header. I have to make the \"ppmReadRo

ID: 3544411 • Letter: T

Question

The current program only copies the image header. I have to make the "ppmReadRow" and "ppmWriteRow" functions so the "ppmCopy" function copies the complete image file, header + body.

Most of the code is written:

http://pastebin.com/2NBp75hM


First, the only changes you are allowed to make are *inside* the {...} of the ppmReadRow and ppmWriteRow functions. Do not change ppmCopy nor the main() function. In other words, you are required to read and write the image body one row at a time using the row array passed as a parameter to each function. Second, keep in mind that numCols refers to the number of pixels in a row; each pixel has 3 RGB values, so in order to read and write a row, you must read and write all the RGB values in that row. Finally, when you write a row, don't forget to output at least one space between each value, and don't forget to output the endl at the end of the line. Add a simple menu to your program, prompting the user for what operation he/she would like to perform. Something along the lines of this - the user's keyboard input is highlighted: The first menu option to copy the image file is what you just did in step 1. Option 2, "Grayscale", converts the input image into grayscale and writes the resulting image to the output file. Conversion to grayscale is done by averaging the RGB values for a pixel, the red, green and blue, and then replacing them all by that average. So if the RGB values were 25 75 250, the average would be 116, and then all three RGB values would become 116 - i.e. 116 116 116. Note that you can do integer division, and if the computer truncates the result, that's fine; there are no decimal points in RGB values. Option 3, "Flip horizontally", reverses an image so that what's on the left is now on the right, and what's on the right is now on the left. That is, the pixel that is on the far right end of the row ends up on the far of the row, and vice versa. This is repeated as you move inwards toward the center of the row; remember preserve RGB order for each pixel! Option 4 is your choice. You must add a 4th option, but you can add whatever operation you might find interesting. Some simple operations are things like "Flatten Red", where for each pixel, you reduce that pixel's value of RED to 0. Or "Negate Red", where you reverse the value of RED in each pixel - if the red value is low, it should become high, and vice versa. The maximum color depth number is useful here; if red is 0, it becomes 255; if it's 255 it becomes 0; if red is say 100, then it becomes 155. Another option is "Extreme Contrast", which will change each RGB color value to either the max color value or 0. This change is based on whether the existing RGB value is greater than the midpoint of the color range (0..max color); if it is greater than the midpoint then replace it with max color, otherwise replace it with 0. Finally, a more challenging operation is something along the lines of "Flip Vertically", which will require a 2D array... The program performs the operation selected by the user, and then stops; if the user enters an invalid operation (e.g. 5 or -1), output an error message. You do not need to loop and ask for another operation,

Explanation / Answer

void ppmReadRow(ifstream& infile, int row[MAXCOLS], int numCols)
{
for (int i = 0; i < numCols * 3; i += 3)
infile >> row[i] >> row[i+1] >> row[i+2];
}



void ppmWriteRow(ofstream& outfile, int row[MAXCOLS], int numCols)
{
for (int i = 0; i <
numCols * 3; i += 3)
outfile << row[i] << ' ' << row[i+1] << ' ' << row[i+2] << ' ';
outfile << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote