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 namespace firevision {
00033 #if 0 /* just to make Emacs auto-indent happy */
00034 }
00035 #endif
00036 
00037 /** @class FilterHSearch <filters/hor_search.h>
00038  * Search horizontally for a color change. Mark these changes with white
00039  * pixels, all other with black pixels.
00040  * @author Yuxiao Hu
00041  * @author Tim Niemueller
00042  */
00043 
00044 /** Constructor.
00045  * @param cm color model to use to determine the color change
00046  * @param what what to look for, this color is considered as foreground,
00047  * all other colors are background.
00048  */
00049 FilterHSearch::FilterHSearch(ColorModel *cm, color_t what)
00050   : Filter("FilterHSearch")
00051 {
00052   this->cm = cm;
00053   this->what = what;
00054 }
00055 
00056 
00057 void
00058 FilterHSearch::apply()
00059 {
00060   register unsigned int h = 0;
00061   register unsigned int w = 0;
00062 
00063   // y-plane
00064   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);
00065   // u-plane
00066   register unsigned char *up   = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00067                                    + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
00068   // v-plane
00069   register unsigned char *vp   = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
00070                                    + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
00071 
00072   // destination y-plane
00073   register unsigned char *dyp  = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
00074 
00075   // line starts
00076   unsigned char *lyp  = yp;   // y-plane
00077   unsigned char *lup  = up;   // u-plane
00078   unsigned char *lvp  = vp;   // v-plane
00079   unsigned char *ldyp = dyp;  // destination y-plane
00080 
00081   // left and right boundary of the current line
00082   unsigned int left;
00083   unsigned int right;
00084   bool flag;
00085 
00086   for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
00087     flag = false;
00088     left = right = 0;
00089     for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); ++w) {
00090       if ( (cm->determine(*yp++, *up, *vp) == what) ) {
00091         right = w;
00092         flag = true;
00093       } else {
00094         left = flag?left:w;
00095       }
00096       if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
00097         right = ++w;
00098         flag = true;
00099       } else {
00100         ++w;
00101         left = flag?left:w;
00102       }
00103     }
00104 
00105     // clear the dst buffer for this line
00106     memset(ldyp, 0, dst_roi->width);
00107 
00108     // set the left- and right-most pixel to white
00109     // but if the pixel is at the boundary, we ignore it
00110     // in order to eliminate a straight line at the border.
00111     if (left != 0 && left < dst_roi->width) ldyp[left] = 255;
00112     if (right != 0 && right < dst_roi->width) ldyp[right] = 255;
00113 
00114     lyp  += src_roi[0]->line_step;
00115     lup  += src_roi[0]->line_step / 2;
00116     lvp  += src_roi[0]->line_step / 2;
00117     ldyp += dst_roi->line_step;
00118     yp    = lyp;
00119     up    = lup;
00120     vp    = lvp;
00121     dyp   = ldyp;
00122   }
00123 
00124 }
00125 
00126 } // end namespace firevision

Generated on Tue Feb 22 13:32:15 2011 for Fawkes API by  doxygen 1.4.7