DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Image Class

Digital images are rectangular collections of pixels stored in a grid layout. Images are usually stored row by row, starting with the top row. Each row is a collection of pixels (small square areas) stored from left to right. Each pixel is often stored as a collection of three numbers, representing how much red, green, and blue light is in the pixel.

The location of a single number in the image is identified by the row of the pixel (how far from the top of the image), the column of the pixel (how far from the left of the image), and the channel of the number (channel just means red, green, or blue).

Each of the values is a non-negative (0 or positive) integer describing the amount of that primary color to include in the pixel’s color.

channels pixels rows description

A channel is a single integer value. It represents how much of that color is in a pixel.

A pixel is a group of three channels: one for red, one for green, and one for blue.

A row is a horizontal group of pixels. The number of pixels in a row is equal to the width of the image.

A column is a vertical group of pixels. They are not adjacent in memory, but are all the same distance from the left of the image.

An image is a vertical group of rows. The number of rows in an image is equal to the height of the image.

A one-dimensional vector stores all of the channels for an image in a line. Organized into pixels and rows.

In the diagram above, notice how each channel is located in the vector. In the document below, and in your notes from class, find the arithmetic for locating a channel based on its row, column, and channel number.

Assignment

In this assignment, you will update the project from the previous assignment by adding a program to create an image and display the image in ASCII (all text) characters. In order to complete this task, you will be required to create an Image class used to store image information in your program, and a few more functions to interact with the user.

Potential Session

This is an example of what the program may look like to a user.

$ ./ascii_image 
Image height? 40
Image width? 80
                                       .;;;;;;;;;;;;;;;;;;;;;;;;++++++++++++++++
                                      ..;;;;;;;;;;;;;;;;;;;;;;;+++++++++++++++++
                                     ...;;;;;;;;;;;;;;;;;;;;;;++++++++++++++++++
                                    ....;;;;;;;;;;;;;;;;;;;;;+++++++++++++++++++
                                   .....;;;;;;;;;;;;;;;;;;;;++++++++++++++++++++
                                  ......;;;;;;;;;;;;;;;;;;;+++++++++++++++++++++
                                 .......;;;;;;;;;;;;;;;;;;++++++++++++++++++++++
                                ........;;;;;;;;;;;;;;;;;+++++++++++++++++++++++
                               .........;;;;;;;;;;;;;;;;++++++++++++++++++++++++
                              ..........;;;;;;;;;;;;;;;+++++++++++++++++++++++++
                             ...........;;;;;;;;;;;;;;++++++++++++++++++++++++++
                            ............;;;;;;;;;;;;;+++++++++++++++++++++++++++
                           .............;;;;;;;;;;;;++++++++++++++++++++++++++++
                          ..............;;;;;;;;;;;+++++++++++++++++++++++++++++
                         ...............;;;;;;;;;;++++++++++++++++++++++++++++++
                        ................;;;;;;;;;+++++++++++++++++++++++++++++++
                       .................;;;;;;;;++++++++++++++++++++++++++++++++
                      ..................;;;;;;;+++++++++++++++++++++++++++++++++
                     ...................;;;;;;++++++++++++++++++++++++++++++++++
                    ....................;;;;;+++++++++++++++++++++++++++++++++++
~~~~~~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##########
~~~~~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%###########
~~~~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%%%%%%%%%%%%%%%%%%%%%%%%%%%%############
~~~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%%%%%%%%%%%%%%%%%%%%%%%%%%%#############
~~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%%%%%%%%%%%%%%%%%%%%%%%%%%##############
~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+%%%%%%%%%%%%%%%%%%%%%%%%%###############
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++%%%%%%%%%%%%%%%%%%%%%%%%################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+++%%%%%%%%%%%%%%%%%%%%%%%#################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++++%%%%%%%%%%%%%%%%%%%%%%##################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+++++%%%%%%%%%%%%%%%%%%%%%###################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++++++%%%%%%%%%%%%%%%%%%%%####################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+++++++%%%%%%%%%%%%%%%%%%%#####################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++++++++%%%%%%%%%%%%%%%%%%######################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+++++++++%%%%%%%%%%%%%%%%%#######################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++++++++++%%%%%%%%%%%%%%%%########################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+++++++++++%%%%%%%%%%%%%%%#########################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;++++++++++++%%%%%%%%%%%%%%##########################
;;;;;;;;;;;;;;;;;;;;;;;;;;;+++++++++++++%%%%%%%%%%%%%###########################
;;;;;;;;;;;;;;;;;;;;;;;;;;++++++++++++++%%%%%%%%%%%%############################
;;;;;;;;;;;;;;;;;;;;;;;;;+++++++++++++++%%%%%%%%%%%#############################
$ 

Programming Requirements

The following files must be updated or created and stored in the src directory of your repository.

Create Image.h

This file must include the declaration of the Image class.

Image Class Data Storage

The Image class needs to store 3 integers for each pixel in the image. There are height rows of pixels in the image, and each row holds width pixels. That is a total of height times width times 3 integers for the data values. One way to store this many values is to have a std::vector as a data member, that is resize()’d when setWidth() or setHeight() is called.

When a channel is set’d or get’d, into a pixel channel identified by row, column and channel, the index into the vector is calculated using (row * width * 3 + column * 3) + channel.

The class will also need data members for width and height.

Image Class Methods

Your Image class must have the following methods.

Create Image.cpp

This file must implement all of the methods of the Image class declared in Image.h.

Update image_menu.h

Add the following function declarations to the file. Don’t forget to include Image.h in this file too.

Create image_drawing.cpp

This file must include the implementations for these new functions:

Create image_output.cpp

This file must include the implementations for these new functions:

Update controllers.cpp

Add the following functions:

Create ascii_image.cpp

This file must include the implementations of the following functions:

Update Makefile

This file must now also include the rules to build the program ascii_image. The following commands should work correctly.

Additional Documentation

Show Off Your Work

To receive credit for this assignment, you must

Additionally, the program must build, run and give correct output.

Last Updated 09/11/2023