Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. Programming language c++
  2. Edit main.cpp to accomplish the following in order:
    1. Read the image test1.gif.
    2. For every pixel of this image:
      1. 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.
      2. Add col mod 9 to the red component of the pixel, col is the column of the current pixel.
      3. The green component should be unchanged.
      4. 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.
    3. 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.)
    4. Save the new image to a file called output.gif.
    5. Read output.gif back into a new image variable.
    6. Compare each pixel in the newly read image to the one that you saved in step d (not the original). Are there any differences?
    7. 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.)

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How flying airoplane?

Answered: 1 week ago

Question

explain what is meant by the terms unitarism and pluralism

Answered: 1 week ago