square_shrinker.cpp
00001 00002 /*************************************************************************** 00003 * square_shrinker.cpp - Implementation of SquareShrinker 00004 * 00005 * Created: Tue Apr 22 2008 20:58:40 (GO2008, day 4) 00006 * Copyright 2005-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <classifiers/square_shrinker.h> 00025 00026 #include <fvutils/color/colorspaces.h> 00027 #include <fvutils/base/roi.h> 00028 00029 #include <models/scanlines/scanlinemodel.h> 00030 #include <models/color/colormodel.h> 00031 00032 #include <cstddef> 00033 00034 /** @class SquareShrinker <classifiers/square_shrinker.h> 00035 * Square shrinker. 00036 * This shrinker makes sure that a ROI is always squared. 00037 * @author Tim Niemueller 00038 */ 00039 00040 /** Constructor. */ 00041 SquareShrinker::SquareShrinker() 00042 : Shrinker() 00043 { 00044 } 00045 00046 00047 /** Shrink! 00048 * Do the actual shrinking. 00049 * @param roi ROI to shrink 00050 */ 00051 void 00052 SquareShrinker::shrink( ROI *roi ) 00053 { 00054 if ( roi->width < roi->height ) { 00055 roi->start.y += (roi->height - roi->width) / 2; 00056 roi->height = roi->width; 00057 } else if ( roi->width > roi->height) { 00058 roi->start.x += (roi->width - roi->height) / 2; 00059 roi->width = roi->height; 00060 } 00061 }

