An instance maintains a row-major order array of pixels for an image.
Use the methods getPixel and setPixel to get and set the various pixels in this image. Pixels are represented as 3-element tuples, with each element in the range 0..255. For example, red is (255,0,0).
These pixels are not RGB objects, like in Assignment 3. They are tuples, which are lists that cannot be modified (so you can slice them to get new tuples, but not assign or append to them).
Constructor: Create an ImageArray of the given size.
param rows: The number of rows in this image. Precondition: an int >= 0
param cols: The number of columns in this image. Precondition: an int >= 0
param data: The pixel array for this image. Precondition: an array of pixels (i.e. 3-element tuples, each element an int in 0..255) of size rows*cols
In general, you should leave the parameter data as None. If you wish to initialize the image with some data, use one of the alternate constructors like Copy or LoadFile.
The following class methods provide for alternate constructors.
Constructor (alternate): Create an ImageArray for the given image file
param filename: image file to initialize array Precondition: a string representing an image file.
If filename is not the name of a valid image file, this constructor will raise an exception.
Constructor (alternate): Create a copy of the given ImageArray
param data: image array to copy Precondition: an ImageArray object
Once the copy is created, changes to the original will not affect this instance.
These attributes may be read (e.g. used in an expression), but not altered.
The number of rows in this image
This attribute is set by the constructor and may not be altered
The number of columns in this image
This attribute is set by the constructor and may not be altered
Length of pixel array
This attribute is set by the constructor and may not be altered
An OpenGL texture for this image (used for rendering)
This attribute is recomputed each time by the getter and may not be altered directly.
An Image object for this ImageArray. Used to save results.
This attribute is recomputed each time by the getter and may not be altered directly.
Returns: The pixel value at (row, col)
param row: The pixel row Precondition: an int for a valid pixel row
param col: The pixel col Precondition: an int for a valid pixel column
Value returned is an 3-element tuple (r,g,b).
This method does not enforce the preconditions; that is the responsibility of the user.
Sets the pixel value at (row, col) to pixel
param row: The pixel row Precondition: an int for a valid pixel row
param col: The pixel column Precondition: an int for a valid pixel column
param pixel: The pixel value Precondition: a 3-element tuple (r,g,b) where each value is 0..255
This method does not enforce the preconditions; that is the responsibility of the user.
Swaps the pixel at (row1, col1) with the pixel at (row2, col2)
param row1: The pixel row to swap from Precondition: an int for a valid pixel row
param row2: The pixel row to swap to Precondition: an int for a valid pixel row
param col1: The pixel column to swap from Precondition: an int for a valid pixel column
param col2: The pixel column to swap to Precondition: an int for a valid pixel column
Preconditions are enforced only if enforced in getPixel, setPixel.
Returns: Pixel number n of the image (in row major order)
param n: The pixel number to access Precondition: an int in 0..(length of the image buffer - 1)
This method is used when you want to treat an image as a flat, one-dimensional list rather than a 2-dimensional image. It is useful for the steganography part of the assignment.
Value returned is a 3-element tuple (r,g,b).
This method does not enforce the preconditions; that is the responsibility of the user.
Sets pixel number n of the image (in row major order) to pixel
param n: The pixel number to access Precondition: an int in 0..(length of the image buffer - 1)
param pixel: The pixel value Precondition: a 3-element tuple (r,g,b) where each value is 0..255
This method is used when you want to treat an image as a flat, one-dimensional list rather than a 2-dimensional image. It is useful for the steganography part of the assignment.
This method does not enforce the preconditions; that is the responsibility of the user.