Overview
This lab is designed to give students practice with memory manipulation and function as a primer for Project 3.
You will be using CLion, along with Windows Terminal and the test images provided on Canvas, to complete
this lab. It will make use of a C++ version of the ConsoleGfx class. You will also practice directly executing
programs from the command line. (Please note that the CLion terminal does note natively recognize UTF-8
encoding, and the C++ runtime does not do “unnecessary” re-encoding, so proper visualization requires using
Windows Terminal and a modified character set. As a result, while this activity can be done on Linux or MacOS,
the visualizations will not match the desired result on these platforms.)
Requirements
The program should be driven classless main function and Image class.
Standalone Functions (scaler.cpp)
int main()
When the program is run via the main() method, the program should:
1) Fetch ConsoleGfx singleton via ConsoleGfx.getInstance()
2) Display the welcome message
3) Display color test (ConsoleGfx.testRainbow)
4) Display the menu
5) Prompt for input
Load File
Load file via unsigned char *ConsoleGfx.loadFile(string file). Note that loadFile() allocates
an array for the file data, but the caller is responsible to deallocation.
Success (File was Loaded) Failure (File wasn’t Loaded)
Select a Menu Option: 1 Select a Menu Option: 1
Enter name of file to load: logos/uga.gfx Enter name of file to load: foo.png
File loaded. Error: could not load file.
Scaler Menu Scaler Menu
———– ———–
Load Test Image Show Image Properties
Loads ConsoleGfx.testImage: Displays the length and width of the current image.
Select a Menu Option: 2 Select a Menu Option: 6
Test image data loaded. Image Dimensions: (14, 6)
Scaler Menu Scaler Menu
———– ———–
Display Image
Displays current image by invoking ConsoleGfx.displayImage(unsigned char *imageData) method.
Success (Previously Loaded) Failure (No Image Loaded)
Enlarge / Shrink Image
Prompts the user for orders of magnitude to change (powers of two), then enlarges the image.
Select a Menu Option: 4 Select a Menu Option: 5
Enter orders of magnitude for enlargement: 3 Enter orders of magnitude for reduction: 3
Image enlarged! Image reduced!
Scaler Menu _ Scaler Menu
———– ———–
unsigned char *scaledImage(unsigned char *imageData, int orders)
Returns a scaled version of the image data based on the orders of magnitude (i.e., powers of two to scale).
The number of orders of magnitude should be in the range [-4, 4] (inclusive), which allows scaling down to
1/16 or up by a factor of 16 in each dimension. Do no implement this via recursive or iterative doubling; this
takes twice as long as creating a new image one time, and it causes memory fragmentation.
This function should never scale any image above 256 in width or height; instead, it should limit scaling such
that the image is scaled up by a power of two but remains less than or equal to 256 in each dimension. Likewise,
no image should be scaled below a height or width of one. To determine the color for reduced images, the
number of colors of each pixel should be counted, and the most common color should be used. If there is a tie,
the earliest pixel (by row, then by column) should be used. This function should allocate memory and return
it to the caller; the caller is responsible for deallocation.
Image Class
The Image class will the image data and should be constructed from the raw data.
The class must also have the following methods and behaviors (this is mandatory):
public Image(unsigned char *imageData)
This method should be the only constructor for this class. There should not be a default constructor! Its sole
argument is a pointer to an array of raw image data as loaded from the file. The data is formatted as follows:
public unsigned char *getImageData()
Returns a pointer to the raw image data (not a copy).
public unsigned char *getPixelData()
Returns a pointer to the raw pixel data (excluding the image property information). Should not be a copy.
public unsigned char getWidth()
Returns the width of the image.
public unsigned char getHeight()
Returns the height of the image.
public void setImageData(unsigned char *newData)
Changes the image data to the new pointer.
Building and Testing
For this project, students will begin to learn more details about the practical building and testing of C++ programs,
including accessing executables built by the compiler from outside of the IDE.
Building
CLion uses the standardized CMake build system, which is supported across multiple platforms and IDEs
(including CLion and Visual Studio) and supports many compilers (GCC, Clang, and MS Visual C.) When you
create a CLion project, it will create CMakeLists.txt. The CMakeLists.txt file for this lab might look like this:
You should make sure that the CMakelists.txt file correctly lists your source files and the executable. Then,
click on the “Build” button (���), which is on the toolbar to the left of the “Run” ( ) and “Debug” (�������) buttons.
Testing
Due to limitations of CLion’s (and “Command Prompt”) terminal, we will build our program using CLion but
test using Windows Terminal. You should install it via the Windows Store. You will also need to add MinGW’s
binary directory (C:ProgramDatachocolateylibmingwtoolsinstallmingw64bin) to the system’s
PATH variable (see Microsoft’s instructions).
To open Explorer , open the build folder (e.g, cmake-build-debug), right-click on scaler.exe, and select
Open In Explorer. Then, right click in Explorer and select “Open in Windows Terminal”. Once the
terminal window is open, you can run your program by typing the executable’s name (e.g., scaler):
cmake_minimum_required(VERSION 3.20)
project(scaler)
set(CMAKE_CXX_STANDARD 14)
Executable name add_executable(scaler ConsoleGfx.cpp scaler.cpp) Source files
C++ version
Submissions
NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for
your submission!
Files: scaler.cpp, Image.cpp, Image.h
Method: Submit on ZyLabs
COP3504C, Image, scaling, solved
[SOLVED] Cop3504c lab 06: image scaling
$25
File Name: Cop3504c_lab_06__image_scaling.zip
File Size: 282.6 KB
Only logged in customers who have purchased this product may leave a review.

![[SOLVED] Cop3504c lab 06: image scaling](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[SOLVED] Ecse 4540: introduction to image processing, homework 1](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.