1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include<iostream>
#include<fstream>
#define s 256
void read(int data[s][s*3],int & h,int & w,int & c);
void read2(int data[s][s*3],int & h,int & w,int & c);
void save(int data[s][s*3],int & h,int & w,int & c);
void rotate90(int data[s][s*3],int h,int w,int c);
/* The image that I'm using, by orders of the assigment
is 'snail.ppm', which it is at
http://orion.math.iastate.edu/burkardt/data/ppm/ppm.html
at the bottom of the page. I'm required to make a menu
for the user selection of the type of modification
to the image that will be made.*/
using namespace std;
void main()
{
int data[s][s*3],heigh,witdh,color,select,select2;
do
{
cout<<"Choose an option: "<<endl;
cout<<"\n1)Rotate Clockwise"<<endl;
cout<<"2)Rotate Counter-Clockwise"<<endl;
cout<<"3)Decompose"<<endl;
cout<<"4)Zoom in"<<endl;
cout<<"5)Zoom out"<<endl;
cout<<"6)Convert into Grayscale"<<endl;
cout<<"7)Exit"<<endl;
cout<<"\nGive your selection:\t";
cin>>select;
switch(select)
{
case 1:
do{
cout<<"\nRotate:"<<endl;
cout<<"1)90 degrees"<<endl;
cout<<"2)180 degrees"<<endl;
cout<<"3)270 degrees"<<endl;
cout<<"Give your selection: ";
cin>>select2;
}while((select2<1)||(select2>3));
switch(select2)
{
case 1:
read(data,heigh,witdh,color);
rotate90(data,heigh,witdh,color);
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
case 2:
read(data,heigh,witdh,color);
for(int i=0;i<2;i++)
{
rotate90(data,heigh,witdh,color);
read2(data,heigh,witdh,color);
}
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
case 3:
read(data,heigh,witdh,color);
for(int i=0;i<3;i++)
{
rotate90(data,heigh,witdh,color);
read2(data,heigh,witdh,color);
}
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
}
case 2:
do{
cout<<"\nRotate:"<<endl;
cout<<"1)90 degrees"<<endl;
cout<<"2)180 degrees"<<endl;
cout<<"3)270 degrees"<<endl;
cout<<"\nGive your selection: ";
cin>>select2;
}while((select2<1)||(select2>3));
switch(select2)
{
case 1:
read(data,heigh,witdh,color);
for(int i=0;i<3;i++)
{
rotate90(data,heigh,witdh,color);
read2(data,heigh,witdh,color);
}
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
case 2:
read(data,heigh,witdh,color);
for(int i=0;i<2;i++)
{
rotate90(data,heigh,witdh,color);
read2(data,heigh,witdh,color);
}
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
case 3:
read(data,heigh,witdh,color);
rotate90(data,heigh,witdh,color);
cout<<"\nYour image was sucessfully rotated.\n"<<endl;
break;
}
}
}while(select!=7);
}
void read(int data[s][s*3],int & h,int & w,int & c)
{
char buffer[s];
ifstream input;
input.open("C:\\Users\\AK's\\Downloads\\snail.ppm",ios::in);
if(input==NULL)
{
cout<<"Cannot open file"<<endl;
}
input.getline(buffer,s*3);
input.getline(buffer,s*3);
input>>w>>h>>c;
for(int i=0;i<h;i++)
{
for(int j=0;j<w*3;j++)
{
input>>data[i][j];
}
}
input.close();
}
void read2(int data[s][s*3],int & h,int & w,int & c)
{
char buffer[s];
ifstream input;
input.open("C:\\Users\\AK's\\Downloads\\snail2.ppm",ios::in);
if(input==NULL)
{
cout<<"Cannot open file"<<endl;
}
input.getline(buffer,s*3);
input.getline(buffer,s*3);
input>>w>>h>>c;
for(int i=0;i<h;i++)
{
for(int j=0;j<w*3;j++)
{
input>>data[i][j];
}
}
input.close();
}
void rotate90(int data[s][s*3],int h,int w,int c)
{
ofstream output;
output.open("C:\\Users\\AK's\\Downloads\\snail2.ppm",ios::out);
output<<"P3"<<endl;
output<<"#Title"<<endl;
output<<w<<" "<<h<<endl;
output<<c<<endl;
for(int i=0;i<h;i++)
{
output<<endl;
for(int j=0;j<w;j++)
{
output<<data [w-j-1][i*3]<<" "<<data[w-j-1][i*3+1]<<" "<<data[w-j-1][i*3+2]<<" ";
}
}
}
|