Removed the definition of basename, which confuses an existing system one.
[folded-ctf.git] / rgb_image_subpixel.cc
1 /*
2  *  folded-ctf is an implementation of the folded hierarchy of
3  *  classifiers for object detection, developed by Francois Fleuret
4  *  and Donald Geman.
5  *
6  *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of folded-ctf.
10  *
11  *  folded-ctf is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  folded-ctf 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 folded-ctf.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "rgb_image_subpixel.h"
26
27 RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * scale, height* scale) { }
28
29 RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * scale, image->height() * scale) {
30   for(int y = 0; y < _height; y++) {
31     for(int x = 0; x < _width; x++) {
32       set_pixel(x, y,
33                 image->pixel(x / scale, y / scale, RGBImage::RED),
34                 image->pixel(x / scale, y / scale, RGBImage::GREEN),
35                 image->pixel(x / scale, y / scale, RGBImage::BLUE));
36     }
37   }
38 }
39
40 RGBImageSubpixel::~RGBImageSubpixel() { }
41
42 void RGBImageSubpixel::read_png(const char *filename) {
43   abort();
44 }
45
46 void RGBImageSubpixel::write_png(const char *filename) {
47   RGBImage tmp(_width / scale, _height / scale);
48   for(int y = 0; y < _height / scale; y++) {
49     for(int x = 0; x < _width / scale; x++) {
50       int sr = 0, sg = 0, sb = 0;
51       for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
52         for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
53           sr += int(_bit_plans[RED][yy][xx]);
54           sg += int(_bit_plans[GREEN][yy][xx]);
55           sb += int(_bit_plans[BLUE][yy][xx]);
56         }
57       }
58
59       tmp.set_pixel(x, y,
60                     sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
61     }
62   }
63   tmp.write_png(filename);
64 }
65
66
67 void RGBImageSubpixel::read_jpg(const char *filename) {
68   abort();
69 }
70
71 void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
72   RGBImage tmp(_width / scale, _height / scale);
73
74   for(int y = 0; y < _height / scale; y++) {
75     for(int x = 0; x < _width / scale; x++) {
76       int sr = 0, sg = 0, sb = 0;
77       for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
78         for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
79           sr += int(_bit_plans[RED][yy][xx]);
80           sg += int(_bit_plans[GREEN][yy][xx]);
81           sb += int(_bit_plans[BLUE][yy][xx]);
82         }
83       }
84
85       tmp.set_pixel(x, y,
86                     sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
87     }
88   }
89
90   tmp.write_jpg(filename, quality);
91 }
92
93
94 void RGBImageSubpixel::draw_line(int thickness,
95                                  unsigned char r, unsigned char g, unsigned char b,
96                                  scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) {
97   RGBImage::draw_line(int(thickness * scale),
98                       r, g, b,
99                       x0 * scale + scale/2, y0 * scale + scale/2,
100                       x1 * scale + scale/2, y1 * scale + scale/2);
101 }