00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <algorithm>
00021 #include "color.h"
00022
00023 using namespace std;
00024
00025 color::color() throw() : _r(0), _g(0), _b(0) {
00026 }
00027
00028 color::color(value_type r, value_type g, value_type b) throw() : _r(r), _g(g), _b(b) {
00029 }
00030
00031 color::color(const color & c) throw() : _r(c._r), _g(c._g), _b(c._b) {
00032 }
00033
00034 color::color & color::operator=(const color & c) {
00035 _r = c._r;
00036 _g = c._g;
00037 _b = c._b;
00038 return *this;
00039 }
00040
00041 color::~color() throw() {
00042 }
00043
00044 color::value_type color::red() const throw() {
00045 return _r;
00046 }
00047
00048 color::value_type color::green() const throw() {
00049 return _g;
00050 }
00051
00052 color::value_type color::blue() const throw() {
00053 return _b;
00054 }
00055
00056 void color::delta(short * ptr) throw() {
00057
00058 int t;
00059 t = ((static_cast<int>(_r) << 7) + _r + ptr[0]) >> 7;
00060 _r = max(min(255, t), 0);
00061 t = ((static_cast<int>(_g) << 7) + _g + ptr[1]) >> 7;
00062 _g = max(min(255, t), 0);
00063 t = ((static_cast<int>(_b) << 7) + _b + ptr[2]) >> 7;
00064 _b = max(min(255, t), 0);
00065 }
00066
00067 ostream & operator <<(ostream & o, const color & c) {
00068 o << "COLOR(" << static_cast<int>(c.red()) << ", " << static_cast<int>(c.green()) << ", " << static_cast<int>(c.blue()) << ")";
00069 return o;
00070 }
00071