*** empty log message ***
[folded-ctf.git] / rgb_image_subpixel.cc
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, (C) IDIAP                                //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
17 ///////////////////////////////////////////////////////////////////////////
18
19 #include "rgb_image_subpixel.h"
20
21 RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * _scale, height* _scale) { }
22
23 RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * _scale, image->height() * _scale) {
24   for(int y = 0; y < _height; y++) {
25     for(int x = 0; x < _width; x++) {
26       set_pixel(x, y,
27                 image->pixel(x / _scale, y / _scale, RGBImage::RED),
28                 image->pixel(x / _scale, y / _scale, RGBImage::GREEN),
29                 image->pixel(x / _scale, y / _scale, RGBImage::BLUE));
30     }
31   }
32 }
33
34 RGBImageSubpixel::~RGBImageSubpixel() { }
35
36 void RGBImageSubpixel::read_ppm(const char *filename) {
37   abort();
38 }
39
40 void RGBImageSubpixel::write_ppm(const char *filename) {
41   abort();
42 }
43
44
45 void RGBImageSubpixel::read_png(const char *filename) {
46   abort();
47 }
48
49 void RGBImageSubpixel::write_png(const char *filename) {
50   RGBImage tmp(_width / _scale, _height / _scale);
51   for(int y = 0; y < _height / _scale; y++) {
52     for(int x = 0; x < _width / _scale; x++) {
53       int sr = 0, sg = 0, sb = 0;
54       for(int yy = y * _scale; yy < (y + 1) * _scale; yy++) {
55         for(int xx = x * _scale; xx < (x + 1) * _scale; xx++) {
56           sr += int(_bit_plans[RED][yy][xx]);
57           sg += int(_bit_plans[GREEN][yy][xx]);
58           sb += int(_bit_plans[BLUE][yy][xx]);
59         }
60       }
61
62       tmp.set_pixel(x, y,
63                     sr / (_scale * _scale), sg / (_scale * _scale), sb / (_scale * _scale));
64     }
65   }
66   tmp.write_png(filename);
67 }
68
69
70 void RGBImageSubpixel::read_jpg(const char *filename) {
71   abort();
72 }
73
74 void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
75   abort();
76 }
77
78
79 void RGBImageSubpixel::draw_line(int thickness,
80                                  unsigned char r, unsigned char g, unsigned char b,
81                                  scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) {
82   RGBImage::draw_line(int(thickness * _scale),
83                       r, g, b,
84                       x0 * _scale + _scale/2, y0 * _scale + _scale/2,
85                       x1 * _scale + _scale/2, y1 * _scale + _scale/2);
86 }