155 lines
3.8 KiB
C++
155 lines
3.8 KiB
C++
/*
|
|
Noah Woodlee
|
|
CPE212-01
|
|
Project 1, due Sunday, Febuary 21, 2020
|
|
*/
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
// LoadImage defintion
|
|
void LoadImage(const string imagefile, int image[MAXROWS][MAXCOLS])
|
|
{
|
|
ifstream input;
|
|
input.open(imagefile.c_str());
|
|
if (!input)
|
|
{
|
|
cout << "Error - File unable to be opened." << endl;
|
|
return;
|
|
}
|
|
int rows, cols, nums;
|
|
string str;
|
|
getline(input, str);
|
|
//cout << str;
|
|
for (int r = 0; r < MAXROWS ; r++) // iterate number of rows
|
|
{
|
|
for (int c = 0; c < MAXCOLS; c++) // iterate number of columns
|
|
{
|
|
input >> nums;
|
|
image[r][c]=nums;
|
|
}
|
|
}
|
|
|
|
} // End of LoadImage
|
|
|
|
// Flip Horozontal defintion
|
|
void FlipHorizontal(int image[MAXROWS][MAXCOLS])
|
|
{
|
|
int temp;
|
|
for (int r = 0; r < MAXROWS; r++) // loop for columns 1 & 10
|
|
{
|
|
temp=image[r][0];
|
|
image[r][0]=image[r][MAXCOLS-1];
|
|
image[r][MAXCOLS-1]=temp;
|
|
}
|
|
for (int r = 0; r < MAXROWS; r++) // loop for columns 2 & 9
|
|
{
|
|
temp=image[r][1];
|
|
image[r][1]=image[r][MAXCOLS-2];
|
|
image[r][MAXCOLS-2]=temp;
|
|
}
|
|
for (int r = 0; r < MAXROWS; r++) // loop for columns 3 & 8
|
|
{
|
|
temp=image[r][2];
|
|
image[r][2]=image[r][MAXCOLS-3];
|
|
image[r][MAXCOLS-3]=temp;
|
|
}
|
|
for (int r = 0; r < MAXROWS; r++) // loop for column 4 & 7
|
|
{
|
|
temp=image[r][3];
|
|
image[r][3]=image[r][MAXCOLS-4];
|
|
image[r][MAXCOLS-4]=temp;
|
|
}
|
|
for (int r = 0; r < MAXROWS; r++) // loop for column 5 & 6
|
|
{
|
|
temp=image[r][4];
|
|
image[r][4]=image[r][MAXCOLS-5];
|
|
image[r][MAXCOLS-5]=temp;
|
|
}
|
|
} // End of FlipHorizontal function
|
|
|
|
// FlipVertical defintion
|
|
void FlipVertical(int image[MAXROWS][MAXCOLS])
|
|
{
|
|
int temp;
|
|
for (int c = 0; c < MAXCOLS; c++) // loop for rows 1 & 10
|
|
{
|
|
temp = image[0][c];
|
|
image[0][c] = image[MAXROWS-1][c];
|
|
image[MAXROWS-1][c] = temp;
|
|
}
|
|
for (int c = 0; c < MAXCOLS; c++) // loop for rows 2 & 9
|
|
{
|
|
temp = image[1][c];
|
|
image[1][c] = image[MAXROWS-2][c];
|
|
image[MAXCOLS-2][c] = temp;
|
|
}
|
|
for (int c = 0; c < MAXCOLS; c++) // loop for rows 3 & 8
|
|
{
|
|
temp = image[2][c];
|
|
image[2][c] = image[MAXROWS-3][c];
|
|
image[MAXCOLS-3][c]=temp;
|
|
}
|
|
for (int c = 0; c < MAXCOLS; c++) // loop for rows 4 & 7
|
|
{
|
|
temp = image[3][c];
|
|
image[3][c] = image[MAXROWS-4][c];
|
|
image[MAXCOLS-4][c] = temp;
|
|
}
|
|
for (int c = 0; c < MAXCOLS; c++) // loop for rows 5 & 6
|
|
{
|
|
temp = image[4][c];
|
|
image[4][c] = image[MAXROWS-5][c];
|
|
image[MAXCOLS-5][c] = temp;
|
|
}
|
|
}
|
|
|
|
// RotateCW defintion
|
|
void RotateCW(int image[MAXROWS][MAXCOLS])
|
|
{
|
|
int n = MAXCOLS;
|
|
for (int i = 0; i < n/2; i++)
|
|
{
|
|
for (int j = i; j < n-i-1; j++)
|
|
{
|
|
int temp = image[i][j];
|
|
image[i][j]=image[n-1-j][i];
|
|
image[n - 1 - j][i] = image[n - 1 - i][n - 1 - j];
|
|
image[n - 1 - i][n - 1 - j] = image[j][n - 1 - i];
|
|
image[j][n - 1 - i] = temp;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// RotateCCW defintion
|
|
void RotateCCW(int image[MAXROWS][MAXCOLS])
|
|
{
|
|
int n=MAXROWS;
|
|
for(int i=0;i<n/2;i++)
|
|
{
|
|
for(int j=i;j<n-i-1;j++)
|
|
{
|
|
int temp=image[i][j];
|
|
image[i][j]=image[j][n-i-1];
|
|
image[j][n-i-1]=image[n-i-1][n-j-1];
|
|
image[n-i-1][n-j-1]=image[n-j-1][i];
|
|
image[n-j-1][i]=temp;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Transpose defintion
|
|
void Transpose(int image[MAXROWS][MAXCOLS])
|
|
{
|
|
int temp;
|
|
for (int r = 0; r < MAXROWS; r++){ // loop to increment rows
|
|
for (int c = 0; c < r; c++) // loop to increment columns
|
|
{
|
|
temp = image[r][c];
|
|
image[r][c] = image[c][r];
|
|
image[c][r] = temp;
|
|
}
|
|
}
|
|
} |