shape_remover.cpp

00001
00002 /***************************************************************************
00003  *  shape_remover.cpp - Implementation of a shape remover
00004  *
00005  *  Created: Wed Sep 28 11:26:58 2005
00006  *  Copyright  2005-2007  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 <filters/shape_remover.h>
00025
00026
00027 #include <models/shape/shapemodel.h>
00028 
00029 /** @class FilterShapeRemover <filters/shape_remover.h>
00030  * Remove shapes from an image.
00031  */
00032 
00033 /** Constructor. */
00034 FilterShapeRemover::FilterShapeRemover()
00035   : Filter("FilterShapeRemover")
00036 {
00037   shape = NULL;
00038 }
00039
00040
00041 void
00042 FilterShapeRemover::apply()
00043 {
00044   /* Code to remove lines here
00045    * INPUT:  Pre-filtered image or part of image that has clear edges set (white
00046    *         value at edge > 240)
00047    * OUTPUT: the edges close to the given shape have been removed
00048    */
00049
00050   if (shape == NULL) return;
00051
00052   shape->setMargin( margin );
00053
00054   unsigned char *buffer = src_roi[0]->get_roi_buffer_start( src[0] );
00055   unsigned char *linestart = buffer;
00056
00057   if ( (dst == NULL) || (src[0] == dst) ) {
00058
00059     for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
00060
00061       for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
00062         if ((*buffer > 240) && (shape->isClose(w, h))) {
00063           *buffer = 0;
00064         }
00065         buffer++;
00066       }
00067
00068       linestart += src_roi[0]->line_step;
00069       buffer = linestart;
00070     }
00071   } else {
00072     unsigned char *dst_buffer = dst_roi->get_roi_buffer_start( dst );
00073     unsigned char *dst_linestart = dst_buffer;
00074
00075     for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
00076
00077       for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
00078         if ((*buffer > 240) && (shape->isClose(w, h))) {
00079           *dst_buffer = 0;
00080         } else {
00081           *dst_buffer = *buffer;
00082         }
00083         buffer++;
00084         dst_buffer++;
00085       }
00086
00087       linestart += src_roi[0]->line_step;
00088       dst_linestart += dst_roi->line_step;
00089       buffer = linestart;
00090       dst_buffer = dst_linestart;
00091     }
00092   }
00093 }
00094
00095 
00096 /** Set margin.
00097  * @param margin margin around shape to be close to a point.
00098  */
00099 void
00100 FilterShapeRemover::set_margin( unsigned int margin )
00101 {
00102   this->margin = margin;
00103 }
00104
00105 
00106 /** Set shape that is to be removed.
00107  * @param shape shape to remove
00108  */
00109 void
00110 FilterShapeRemover::set_shape( Shape *shape )
00111 {
00112   this->shape = shape;
00113 }