RGB像素类头文件 C++
/*-----------------------------------------------*/
/* 像素类表示一个图片,一个像素由RGB组成 */
/*Pixel class declaration. */
/*File name : pixel.h */
#ifndef PIXEL_H
#define PIXEL_H
#include <fstream>
#include <iostream>
using namespace std;
class pixel;//vc6中遇到的bug,在类的声明前加这两句
pixel operator+(const pixel p1,const pixel p2);
class pixel
{
public:
//Constructor Functions
pixel();
pixel(int);
pixel(int,int,int);
//Accessor Functions
int get_red() const;
int get_green() const;
int get_blue() const;
//Functions to set the value of pixel.
void set_pixel_value(int r,int g, int b);
void set_red(int);
void set_green(int);
void set_blue(int);
//Overloaded operators.
//Addition
//Add two pixel
pixel operator+(pixel p) const;
//Multiplication. multiply a pixel by a floating point value.
pixel operator*(double v) const;
//Division. divide a pxel by an integer value.
pixel operator/(int v) const;
//friend +
friend pixel operator+(const pixel p1,const pixel p2);
//Input operator.
//<<不能定义为成员函数,因为该函数的第一个变量必须是ostream引用,所以只用使用friend。
//第二个形参const通过引用进行传递提高效率,同时阻止对变量进行修改
friend ostream& operator <<(ostream& out,const pixel& p){
out<<p.red<<' ';
out<<p.green<<' ';
out<<p.blue<<' ';
return out;
}
//Output operator.
//>>的重载实现,没有考虑输入错误
friend istream& operator >>(istream& in, pixel& p){
in>> p.red >> p.green >> p.blue;
return in;
}
private:
unsigned int red,green,blue;
};
#endif
/*------------------------------------------------------------*/
/* 像素类表示一个图片,一个像素由RGB组成 */
/*Pixel class declaration. */
/*File name : pixel.h */
#ifndef PIXEL_H
#define PIXEL_H
#include <fstream>
#include <iostream>
using namespace std;
class pixel;//vc6中遇到的bug,在类的声明前加这两句
pixel operator+(const pixel p1,const pixel p2);
class pixel
{
public:
//Constructor Functions
pixel();
pixel(int);
pixel(int,int,int);
//Accessor Functions
int get_red() const;
int get_green() const;
int get_blue() const;
//Functions to set the value of pixel.
void set_pixel_value(int r,int g, int b);
void set_red(int);
void set_green(int);
void set_blue(int);
//Overloaded operators.
//Addition
//Add two pixel
pixel operator+(pixel p) const;
//Multiplication. multiply a pixel by a floating point value.
pixel operator*(double v) const;
//Division. divide a pxel by an integer value.
pixel operator/(int v) const;
//friend +
friend pixel operator+(const pixel p1,const pixel p2);
//Input operator.
//<<不能定义为成员函数,因为该函数的第一个变量必须是ostream引用,所以只用使用friend。
//第二个形参const通过引用进行传递提高效率,同时阻止对变量进行修改
friend ostream& operator <<(ostream& out,const pixel& p){
out<<p.red<<' ';
out<<p.green<<' ';
out<<p.blue<<' ';
return out;
}
//Output operator.
//>>的重载实现,没有考虑输入错误
friend istream& operator >>(istream& in, pixel& p){
in>> p.red >> p.green >> p.blue;
return in;
}
private:
unsigned int red,green,blue;
};
#endif
/*------------------------------------------------------------*/