Removed the definition of basename, which confuses an existing system one.
[folded-ctf.git] / rgb_image_subpixel.cc
index 3338f50..4c3e16a 100644 (file)
@@ -1,58 +1,55 @@
-
-///////////////////////////////////////////////////////////////////////////
-// 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 <http://www.gnu.org/licenses/>.  //
-//                                                                       //
-// Written by Francois Fleuret, (C) IDIAP                                //
-// Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
-///////////////////////////////////////////////////////////////////////////
+/*
+ *  folded-ctf is an implementation of the folded hierarchy of
+ *  classifiers for object detection, developed by Francois Fleuret
+ *  and Donald Geman.
+ *
+ *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
+ *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
+ *
+ *  This file is part of folded-ctf.
+ *
+ *  folded-ctf is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 3 as
+ *  published by the Free Software Foundation.
+ *
+ *  folded-ctf 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 folded-ctf.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 
 #include "rgb_image_subpixel.h"
 
-RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * _scale, height* _scale) { }
+RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * scale, height* scale) { }
 
-RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * _scale, image->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));
+                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++) {
+  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++) {
+      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]);
@@ -60,7 +57,7 @@ void RGBImageSubpixel::write_png(const char *filename) {
       }
 
       tmp.set_pixel(x, y,
-                    sr / (_scale * _scale), sg / (_scale * _scale), sb / (_scale * _scale));
+                    sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
     }
   }
   tmp.write_png(filename);
@@ -72,15 +69,33 @@ void RGBImageSubpixel::read_jpg(const char *filename) {
 }
 
 void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
-  abort();
+  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_jpg(filename, quality);
 }
 
 
 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),
+  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);
+                      x0 * scale + scale/2, y0 * scale + scale/2,
+                      x1 * scale + scale/2, y1 * scale + scale/2);
 }