GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Apr-2009, 03:08
Alkaselzer Alkaselzer is offline
New Member
 
Join Date: Apr 2009
Posts: 1
Alkaselzer is on a distinguished road
Exclamation

Arrays, .ppm images manipulation


Hi there again! I've been working on an assignment since it was given to me on Thursday, that involves making a C++ console application that manipulates .ppm images.The program is supposed to rotate the image 90,180,and 270 degrees clockwise and counterclockwise, flip the image horizontally and vertically, decompose the image in red, green and blue components in separated files, zoom in and zoom out the image by 2x and 4x, and convert the image in gray scale. Although this project is from Computer Programing 2, and not for Computer Programing 1(in which I am), I'm sincere... I have no freaking idea how to deal with this. I already (with help from my professor in class, of course), managed to rotate the image,yes, from Thursday to today, this is the only things that I have managed to do. I'm really worried because this is supposed to hand over this Thursday, April 9, 2009. I'm not pretending that someone of you will make all the program for me, but, if someone could point me and teach me how to deal with this, I think I will be capable of making the program, or a little more than I already have. This is what i have for now:

CPP / C++ / C Code:
#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 
	[url]http://orion.math.iastate.edu/burkardt/data/ppm/ppm.html[/url]
	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]<<" ";
		}
	}
}

I will be very very grateful if someone could lend me a hand with this... Thank You!
Last edited by LuciWiz : 08-Apr-2009 at 03:24. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Loading wrong images. Sujith MS Visual C++ / MFC Forum 0 08-May-2007 05:48
Dynamic vs Static Arrays WaltP Miscellaneous Programming Forum 5 16-Feb-2006 16:54
I am reviewing Arrays and need help converting some strings to arrays jenmaz C Programming Language 22 23-Nov-2004 00:26
Why are my images distorted? rhino1616 Graphics Forum 0 27-Jun-2003 10:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.