X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=pom.git;a=blobdiff_plain;f=rgb_image.h;fp=rgb_image.h;h=c0e0c432e776844157cce5bc25a22ae93bf1b95c;hp=0000000000000000000000000000000000000000;hb=97a7e68f234cc09807d2d55f550e2516be0e9093;hpb=48c9926a2ed03737a3b024a85cda348caebf4cfe diff --git a/rgb_image.h b/rgb_image.h new file mode 100644 index 0000000..c0e0c43 --- /dev/null +++ b/rgb_image.h @@ -0,0 +1,67 @@ + +////////////////////////////////////////////////////////////////////////////////// +// This program is free software: you can redistribute it and/or modify // +// it under the terms of the version 3 of the GNU General Public License // +// as published by the Free Software Foundation. // +// // +// This program is distributed in the hope that it will be useful, but // +// WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // +// General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +// // +// Written by Francois Fleuret // +// (C) Ecole Polytechnique Federale de Lausanne // +// Contact for comments & bug reports // +////////////////////////////////////////////////////////////////////////////////// + +#ifndef RGB_IMAGE_H +#define RGB_IMAGE_H + +#include "misc.h" + +using namespace std; + +class RGBImage { +protected: + int _width, _height; + unsigned char ***_bit_plans, **_bit_lines, *_bit_map; + static const int RED = 0; + static const int GREEN = 1; + static const int BLUE = 2; + static const int RGB_DEPTH = 3; + + void allocate(); + void deallocate(); + +public: + + RGBImage(); + RGBImage(int width, int height); + virtual ~RGBImage(); + + inline int width() const { return _width; } + inline int height() const { return _height; } + + inline void set_pixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) { + ASSERT(x >= 0 && x < _width && y >= 0 && y < _height, "Out of bounds."); + _bit_plans[RED][y][x] = r; + _bit_plans[GREEN][y][x] = g; + _bit_plans[BLUE][y][x] = b; + } + + inline unsigned char pixel(int x, int y, int d) const { + ASSERT(x >= 0 && x < _width && y >= 0 && y < _height && d >= 0 && d < RGB_DEPTH, "Out of bounds."); + return _bit_plans[d][y][x]; + } + + virtual void read_ppm(const char *filename); + virtual void write_ppm(const char *filename); + + virtual void read_png(const char *filename); + virtual void write_png(const char *filename); +}; + +#endif