int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
unsigned char PixelGrid[WIDTH][HEIGHT]; // Image loaded from file
// unsigned char TitleGrid[WIDTH][MASKHEIGHT]; // Title overlay - needed for final function
// If the file "Parrot.png" cannot be loaded ...
if (!loadImage(PixelGrid, "Parrot.png"))
{
// Display an error message
cout << "Error loading file \"Parrot.png\"" << endl;
}
else
{
cout << "File \"Parrot.png\" opened successfully" << endl;
// Set the pixels in the top 15 rows to be black
setBorder(PixelGrid);
// Demo of use of saveImage - to save the modified file as "ParrotBorder.png"
if (saveImage(PixelGrid, "ParrotBorder.png"))
{
cout << "File \"ParrotBorder.png\" saved successfully" << endl;
}
else
{
cout << "Could not save \"ParrotBorder.png\"" << endl;
}
}
return a.exec();
}
/******************************************************************************
*
* Name: setBorder
* Parameters: pixels - 2D image matrix to modify
* Returns: nothing
* Globals: none
* Description: set top bottom and sides of the first 15 pixels to be gray
*
*****************************************************************************/
void setBorder(unsigned char pixels[WIDTH][HEIGHT])
{
// For each row ...
for (int row = 0; row < HEIGHT; row++)
{
// For each pixel in that row ...
for (int col = 0; col < WIDTH; col++)
{
// If the row number is less than 15 ...
if (row < 15)
{
// Set the pixel to be grey
pixels[col][row] = 128;
{
// For each row ...
for (int row = 0; row < HEIGHT; row++)
{
// For each pixel in that row ...
for (int col = 0; col < WIDTH; col++)
{ // If the row number is more than 135 ...
if (row > 185)
{ // Set the pixel to be grey
pixels[col][row] = 128;
{ // For each row ...
for (int row = 0; row < HEIGHT; row++)
{
// For each pixel in that row ...
for (int col = 0; col < WIDTH; col++)
{ // If the column is less than 15...
if (col < 15)
{ // Set the pixel to be gray
pixels[row][col]= 128;
{ // For each row ...
for (int row = 0; row < HEIGHT; row++)
{
// For each pixel in that row ...
for (int col = 0; col < WIDTH; col++)
{ // If the column is more than 135...
if (col > 135)
{ // Set the pixel to be gray
pixels[row][col]= 128;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/******************************************************************************
*
* Name: countblackpixels
* Parameters: pixels - 2D image matrix to modify
* Returns: nothing
* Globals: none
* Description: This functions counts the number of black pixels in the image.
*
*****************************************************************************/
#include <QCoreApplication>
#include <iostream>
#include "ImageHandle.h"
unsigned char PixelGrid[WIDTH][HEIGHT]; // Image loaded from file
// unsigned char TitleGrid[WIDTH][MASKHEIGHT]; // Title overlay - needed for final function
{
// If the file "Parrot.png" cannot be loaded ...
if (!loadImage(PixelGrid, "Parrot.png"))
{
// Display an error message
cout << "Error loading file \"Parrot.png\"" << endl;
else
{
cout << "File \"Parrot.png\" opened successfully" << endl;
{
// For each row ...
for (int row = 0; row < HEIGHT; row++)
{
// For each pixel in that row ...
for (int col = 0; col < WIDTH; col++)
{
// Count the number of black pixels in the photo
if (row + col) = 0
{
// Display the number of black pixels
cout << (row + col = 0) << 0 <<endl;