Added the images for test.
[pom.git] / rgb_image.h
1
2 //////////////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify         //
4 // it under the terms of the version 3 of the GNU General Public License        //
5 // as published by the Free Software Foundation.                                //
6 //                                                                              //
7 // This program is distributed in the hope that it will be useful, but          //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                   //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU             //
10 // General Public License for more details.                                     //
11 //                                                                              //
12 // You should have received a copy of the GNU General Public License            //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.         //
14 //                                                                              //
15 // Written by Francois Fleuret                                                  //
16 // (C) Ecole Polytechnique Federale de Lausanne                                 //
17 // Contact <pom@epfl.ch> for comments & bug reports                             //
18 //////////////////////////////////////////////////////////////////////////////////
19
20 #ifndef RGB_IMAGE_H
21 #define RGB_IMAGE_H
22
23 #include "misc.h"
24
25 using namespace std;
26
27 class RGBImage {
28 protected:
29   int _width, _height;
30   unsigned char ***_bit_plans, **_bit_lines, *_bit_map;
31   static const int RED = 0;
32   static const int GREEN = 1;
33   static const int BLUE = 2;
34   static const int RGB_DEPTH = 3;
35
36   void allocate();
37   void deallocate();
38
39 public:
40
41   RGBImage();
42   RGBImage(int width, int height);
43   virtual ~RGBImage();
44
45   inline int width() const { return _width; }
46   inline int height() const { return _height; }
47
48   inline void set_pixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
49     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height, "Out of bounds.");
50     _bit_plans[RED][y][x] = r;
51     _bit_plans[GREEN][y][x] = g;
52     _bit_plans[BLUE][y][x] = b;
53   }
54
55   inline unsigned char pixel(int x, int y, int d) const {
56     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height && d >= 0 && d < RGB_DEPTH, "Out of bounds.");
57     return _bit_plans[d][y][x];
58   }
59
60   virtual void read_ppm(const char *filename);
61   virtual void write_ppm(const char *filename);
62
63   virtual void read_png(const char *filename);
64   virtual void write_png(const char *filename);
65 };
66
67 #endif