Added the non-disclosed problems.
[svrt.git] / rgb_image.h
1 /*
2  *  svrt is the ``Synthetic Visual Reasoning Test'', an image
3  *  generator for evaluating classification performance of machine
4  *  learning systems, humans and primates.
5  *
6  *  Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of svrt.
10  *
11  *  svrt is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  svrt is distributed in the hope that it will be useful, but
16  *  WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 /*
26
27   A simple image class to either load color images, or produce
28   materials.
29
30  */
31
32 #ifndef RGB_IMAGE_H
33 #define RGB_IMAGE_H
34
35 #include "misc.h"
36
37 class RGBImage {
38 protected:
39   int _width, _height;
40   unsigned char ***_bit_plans, **_bit_lines, *_bit_map;
41   static const int RED = 0;
42   static const int GREEN = 1;
43   static const int BLUE = 2;
44   static const int RGB_DEPTH = 3;
45
46   void allocate();
47   void deallocate();
48
49 public:
50
51   RGBImage();
52   RGBImage(int width, int height);
53   RGBImage(RGBImage *image, scalar_t scale);
54   virtual ~RGBImage();
55
56   inline int width() const { return _width; }
57   inline int height() const { return _height; }
58
59   inline void set_pixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
60     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height);
61     _bit_plans[RED][y][x] = r;
62     _bit_plans[GREEN][y][x] = g;
63     _bit_plans[BLUE][y][x] = b;
64   }
65
66   inline unsigned char pixel(int x, int y, int d) {
67     ASSERT(x >= 0 && x < _width && y >= 0 && y < _height && d >= 0 && d < RGB_DEPTH);
68     return _bit_plans[d][y][x];
69   }
70
71   virtual void read_png(const char *filename);
72   virtual void write_png(const char *filename);
73
74   virtual void read_jpg(const char *filename);
75   virtual void write_jpg(const char *filename, int quality);
76
77   virtual void draw_line(int thickness,
78                          unsigned char r, unsigned char g, unsigned char b,
79                          scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1);
80
81   virtual void draw_ellipse(int thickness,
82                             unsigned char r, unsigned char g, unsigned char b,
83                             scalar_t xc, scalar_t yc, scalar_t radius_1, scalar_t radius_2, scalar_t tilt);
84 };
85
86 #endif