X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=rgb_image_subpixel.cc;fp=rgb_image_subpixel.cc;h=3338f50c76ffe769f74babee33ed75c507380ab8;hb=d922ad61d35e9a6996730bec24b16f8bf7bc426c;hp=0000000000000000000000000000000000000000;hpb=3bb118f5a9462d02ff7d99ef28ecc0d7e23529f9;p=folded-ctf.git diff --git a/rgb_image_subpixel.cc b/rgb_image_subpixel.cc new file mode 100644 index 0000000..3338f50 --- /dev/null +++ b/rgb_image_subpixel.cc @@ -0,0 +1,86 @@ + +/////////////////////////////////////////////////////////////////////////// +// This program is free software: you can redistribute it and/or modify // +// it under the terms of the version 3 of the GNU General Public License // +// as published by the Free Software Foundation. // +// // +// This program is distributed in the hope that it will be useful, but // +// WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // +// General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +// // +// Written by Francois Fleuret, (C) IDIAP // +// Contact for comments & bug reports // +/////////////////////////////////////////////////////////////////////////// + +#include "rgb_image_subpixel.h" + +RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * _scale, height* _scale) { } + +RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * _scale, image->height() * _scale) { + for(int y = 0; y < _height; y++) { + for(int x = 0; x < _width; x++) { + set_pixel(x, y, + image->pixel(x / _scale, y / _scale, RGBImage::RED), + image->pixel(x / _scale, y / _scale, RGBImage::GREEN), + image->pixel(x / _scale, y / _scale, RGBImage::BLUE)); + } + } +} + +RGBImageSubpixel::~RGBImageSubpixel() { } + +void RGBImageSubpixel::read_ppm(const char *filename) { + abort(); +} + +void RGBImageSubpixel::write_ppm(const char *filename) { + abort(); +} + + +void RGBImageSubpixel::read_png(const char *filename) { + abort(); +} + +void RGBImageSubpixel::write_png(const char *filename) { + RGBImage tmp(_width / _scale, _height / _scale); + for(int y = 0; y < _height / _scale; y++) { + for(int x = 0; x < _width / _scale; x++) { + int sr = 0, sg = 0, sb = 0; + for(int yy = y * _scale; yy < (y + 1) * _scale; yy++) { + for(int xx = x * _scale; xx < (x + 1) * _scale; xx++) { + sr += int(_bit_plans[RED][yy][xx]); + sg += int(_bit_plans[GREEN][yy][xx]); + sb += int(_bit_plans[BLUE][yy][xx]); + } + } + + tmp.set_pixel(x, y, + sr / (_scale * _scale), sg / (_scale * _scale), sb / (_scale * _scale)); + } + } + tmp.write_png(filename); +} + + +void RGBImageSubpixel::read_jpg(const char *filename) { + abort(); +} + +void RGBImageSubpixel::write_jpg(const char *filename, int quality) { + abort(); +} + + +void RGBImageSubpixel::draw_line(int thickness, + unsigned char r, unsigned char g, unsigned char b, + scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) { + RGBImage::draw_line(int(thickness * _scale), + r, g, b, + x0 * _scale + _scale/2, y0 * _scale + _scale/2, + x1 * _scale + _scale/2, y1 * _scale + _scale/2); +}