Question
Programming language c++ Edit main.cpp to accomplish the following in order: Read the image test1.gif . For every pixel of this image: Subtract row mod
- Programming language c++
- Edit main.cpp to accomplish the following in order:
- Read the image test1.gif.
- For every pixel of this image:
- Subtract row mod 7 from the blue component of the pixel, where row is the row of the current pixel. The modoperator uses the % symbol.
- Add col mod 9 to the red component of the pixel, col is the column of the current pixel.
- The green component should be unchanged.
- As you are doing this, make sure to check for overflow and underflow, since bytes are unable to store values below 0 or above 255. If you find overflow, set the byte to 255. If you find underflow, set the byte to 0.
- Create a new image that is the mirror-image of the image from the previous step. (The left side and the right side are reversed.)
- Save the new image to a file called output.gif.
- Read output.gif back into a new image variable.
- Compare each pixel in the newly read image to the one that you saved in step d (not the original). Are there any differences?
- Count and output to the console the number of pixels that have a different values in red, green, or blue. (If a pixel has a difference in any of the three values, then that pixels counts once toward the count. A pixel cannot count more than once.)
Given Interface:
#pragma once
#include
using namespace std;
/*
* Type definitions
*/
typedef unsigned char byte; // A single byte of data
typedef struct { // A pixel stores 3 bytes of data:
byte red; // intensity of the red component
byte green; // intensity of the green component
byte blue; // intensity of the blue component
} pixel;
// A simple image data structure:
// rows is the height of the image (the number of rows of pixels)
// cols is the width of the image (the number of columns of pixels)
// pixels is a 2D array of the image pixels
// The first dimension of pixels varies from 0 to rows-1
// The second dimension of pixels varies from 0 to cols-1
// The pixel at row i and column j is accessed by pixels[i][j].
// With the following definition:
// image myimage;
// We could access the red component of the pixel at row 10, column 20 by:
// myimage.pixels[10][20].red
typedef struct {
int rows, cols; /* pic size */
pixel **pixels; /* image data */
} image;
/*
* Function prototypes
*/
/*
* ReadGIF:
* Preconditions: filename refers to a file that stores a GIF image.
* Postconditions: returns the image contained in "filename" using the
* conventions described for the image type above.
* If the load is unsuccessful, returns an image with
* rows = 0, cols = 0, pixels = nullptr.
*/
image ReadGIF(string filename);
/*
* WriteGIF:
* Preconditions: filename is valid filename to store a GIF image.
* inputImage holds an image using the conventions described
* for the image type above.
* Postconditions: inputImage is saved as a GIF image at the location
* specified by filename.
*/
void WriteGIF(string filename, image inputImage);
/*
* DeallocateImage:
* Preconditions: inputImage contains an image using the conventions
* for the image type described above.
* Postconditions: the memory allocated to the pixels of inputImage has
* been deallocated. Also, the image values are set to:
* rows = 0, cols = 0, pixels = nullptr.
*/
void DeallocateImage(image &inputImage);
/*
* CopyImage:
* Preconditions: inputImage contains an image using the conventions
* for the image type described above.
* Postconditions: if sufficient memory is available, a copy of inputImage
* is returned using newly allocated memory.
* Otherwise, the returned image has:
* rows = 0, cols =0 , pixels = nullptr.
*/
image CopyImage(image inputImage);
/*
* CreateImage:
* Preconditions: rows and cols describe the desired size of the new image.
* Postconditions: if sufficient memory is available, a new image
* is returned using newly allocated memory.
* Each pixel has red = 0, green =0, blue = 0.
* Otherwise, the returned image has:
* rows = 0, cols =0, pixels = nullptr.
*/
image CreateImage(int rows, int cols);
This is the only information that it needs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started