#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void main()
{
//decleration
ifstream source;
ofstream target;
char * box;
int width, height, numlevel;
string s;
int amount= 100;
//--------------------
source.open("1.ppm",ios::binary);
while(source.fail())
{
cout<<"can not open the file"<<endl; // to make sure the file is opened
}
source>> s;
if ( s != "P6" )
cout<<" the file is invailid " <<endl;
source>> width>>height >>numlevel;
source.get();
// start reading into the array
box= new char[width*height*3];
source.read(box,width*height*3);
source.close();
for ( int i=0; i<height; i++ )
for( int j=0; j<width; j++ )
{
unsigned char red= box[i*width*3 + j*3 ];
unsigned char green= box[i*width*3 + j*3 + 1];
unsigned char blue= box[i*width*3 + j*3 + 2];
if ( (red + amount > 255) )
red = 255;
else if( red + amount < 0 )
red = 0;
else red+=amount;
if ( (green + amount > 255) )
green = 255;
else if( green + amount < 0 )
green = 0;
else green+=amount;
if ( (blue + amount > 255) )
blue = 255;
else if( blue + amount < 0 )
blue = 0;
else blue+=amount;
box[i*width*3 + j*3] = red ;
box[i*width*3 + j*3 + 1] = green;
box[i*width*3 + j*3 + 2] = blue;
//---------------------
//writing to new file
target.open("new.ppm");
target << s << width<<height<< numlevel;
for( int k=0; k<width*height*3; k++)
target<<box[k];
while(target.fail() )
cout<<"can't write"<<endl;
target.close();
}
cout<<" hello"<<endl;
}
moqbel -2 Newbie Poster
moqbel -2 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.