hor_search.cpp

00001
00002 /***************************************************************************
00003  *  hor_search.cpp - Implementation of horizontal search filter
00004  *
00005  *  Created: Wed Jul 06 11:57:40 2005
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *             2005       Yuxiao Hu (Yuxiao.Hu@rwth-aachen.de)
00008  *
00009  ****************************************************************************/
00010
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024
00025 #include <filters/hor_search.h>
00026
00027 #include <fvutils/color/yuv.h>
00028
00029 #include <cstddef>
00030 #include <cstring>
00031 
00032 /** @class FilterHSearch <filters/hor_search.h>
00033  * Search horizontally for a color change. Mark these changes with white
00034  * pixels, all other with black pixels.
00035  * @author Yuxiao Hu
00036  * @author Tim Niemueller
00037  */
00038 
00039 /** Constructor.
00040  * @param cm color model to use to determine the color change
00041  * @param what what to look for, this color is considered as foreground,
00042  * all other colors are background.
00043  */
00044 FilterHSearch::FilterHSearch(ColorModel *cm, color_t what)
00045   : Filter("FilterHSearch")
00046 {
00047   this->cm = cm;
00048   this->what = what;
00049 }
00050
00051
00052 void
00053 FilterHSearch::apply()
00054 {
00055   register unsigned int h = 0;
00056   register unsigned int w = 0;
00057
00058   // y-plane
00059   register unsigned char *yp   = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
00060   // u-plane
00061   register unsigned char *up   = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00062                                    + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00063   // v-plane
00064   register unsigned char *vp   = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00065                                    + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00066
00067   // destination y-plane
00068   register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00069
00070   // line starts
00071   unsigned char *lyp  = yp;   // y-plane
00072   unsigned char *lup  = up;   // u-plane
00073   unsigned char *lvp  = vp;   // v-plane
00074   unsigned char *ldyp = dyp;  // destination y-plane
00075
00076   // left and right boundary of the current line
00077   unsigned int left;
00078   unsigned int right;
00079   bool flag;
00080
00081   for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
00082     flag = false;
00083     left = right = 0;
00084     for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); ++w) {
00085       if ( (cm->determine(*yp++, *up, *vp) == what) ) {
00086         right = w;
00087         flag = true;
00088       } else {
00089         left = flag?left:w;
00090       }
00091       if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
00092         right = ++w;
00093         flag = true;
00094       } else {
00095         ++w;
00096         left = flag?left:w;
00097       }
00098     }
00099
00100     // clear the dst buffer for this line
00101     memset(ldyp, 0, dst_roi->width);
00102
00103     // set the left- and right-most pixel to white
00104     // but if the pixel is at the boundary, we ignore it
00105     // in order to eliminate a straight line at the border.
00106     if (left != 0 && left < dst_roi->width) ldyp[left] = 255;
00107     if (right != 0 && right < dst_roi->width) ldyp[right] = 255;
00108
00109     lyp  += src_roi[0]->line_step;
00110     lup  += src_roi[0]->line_step / 2;
00111     lvp  += src_roi[0]->line_step / 2;
00112     ldyp += dst_roi->line_step;
00113     yp    = lyp;
00114     up    = lup;
00115     vp    = lvp;
00116     dyp   = ldyp;
00117   }
00118
00119 }
00120