5c886a95e9e587cbcde648257e7004d683ae8980
[folded-ctf.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) Idiap Research Institute                                          //
17 //                                                                       //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
19 ///////////////////////////////////////////////////////////////////////////
20
21 /*
22
23   A simple image class to either load color images, or produce
24   materials.
25
26  */
27
28 #ifndef RGB_IMAGE_H
29 #define RGB_IMAGE_H
30
31 #include "misc.h"
32
33 class RGBImage {
34 protected:
35   int _width, _height;
36   unsigned char ***_bit_plans, **_bit_lines, *_bit_map;
37   static const int RED = 0;
38   static const int GREEN = 1;
39   static const int BLUE = 2;
40   static const int RGB_DEPTH = 3;
41
42   void allocate();
43   void deallocate();
44
45 public:
46
47   RGBImage();
48   RGBImage(int width, int height);
49   RGBImage(RGBImage *image, scalar_t scale);
50   virtual ~RGBImage();
51
52   inline int width() const { return _width; }
53   inline int height() const { return _height; }
54
55   inline void set_pixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
56     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height);
57     _bit_plans[RED][y][x] = r;
58     _bit_plans[GREEN][y][x] = g;
59     _bit_plans[BLUE][y][x] = b;
60   }
61
62   inline unsigned char pixel(int x, int y, int d) {
63     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height && d >= 0 && d < RGB_DEPTH);
64     return _bit_plans[d][y][x];
65   }
66
67   virtual void read_ppm(const char *filename);
68   virtual void write_ppm(const char *filename);
69
70   virtual void read_png(const char *filename);
71   virtual void write_png(const char *filename);
72
73   virtual void read_jpg(const char *filename);
74   virtual void write_jpg(const char *filename, int quality);
75
76   virtual void draw_line(int thickness,
77                          unsigned char r, unsigned char g, unsigned char b,
78                          scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1);
79
80   virtual void draw_ellipse(int thickness,
81                             unsigned char r, unsigned char g, unsigned char b,
82                             scalar_t xc, scalar_t yc, scalar_t radius_1, scalar_t radius_2, scalar_t tilt);
83 };
84
85 #endif