A C++ program to show image brightness.


#include<iostream>
#include<fstream>
#include<conio.h>
#include<string.h>
using namespace std;
structpix
{
unsigned char b,g,r;
}pixel;
int B=30; // B is component used for brightness
char Header[54];
ifstream in;
ofstream out,out1;
int main()
{
charinfile[]=”e:\\p\\bf-bitma.bmp”;
charoutfile[]=”e:\\p\\bf-brightness.bmp”;
charimdata[]=”e:\\p\\imdata.dat”;
in.open(infile,ios::in|ios::binary);
in.read(( char*)(&Header),sizeof(Header));
out.open(outfile,ios::out| ios::binary);
out.write(( char*)(&Header),sizeof(Header));
out1.open(imdata, ios::out);
while(!in.eof())
{
in.read((char *)(&pixel),sizeof(pixel));
out1<<“ORIGINAL : ” <<(int)pixel.r<<” , “<<(int)pixel.g<<” ,
“<<(int)pixel.b<<endl;
int intensity= (pixel.r+pixel.g+pixel.b)/3;
intensity = intensity + B;
if(intensity > 255)
pixel.r=pixel.g=pixel.b=255;
else
pixel.r=pixel.g=pixel.b=intensity;
out.write((char *)(&pixel),sizeof(pixel));
out1<<“MODIFIFED (Brightness) : ” <<(int)pixel.r<<” , “<<(int)pixel.g<<” ,
“<<(int)pixel.b<<endl;
}
in.close();
out.close();
getch();
}