Fawkes API  Fawkes Development Version
hor_search.cpp
1 
2 /***************************************************************************
3  * hor_search.cpp - Implementation of horizontal search filter
4  *
5  * Created: Wed Jul 06 11:57:40 2005
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  * 2005 Yuxiao Hu (Yuxiao.Hu@rwth-aachen.de)
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #include <fvfilters/hor_search.h>
26 
27 #include <fvutils/color/yuv.h>
28 
29 #include <cstddef>
30 #include <cstring>
31 
32 namespace firevision {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 /** @class FilterHSearch <fvfilters/hor_search.h>
38  * Search horizontally for a color change. Mark these changes with white
39  * pixels, all other with black pixels.
40  * @author Yuxiao Hu
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor.
45  * @param cm color model to use to determine the color change
46  * @param what what to look for, this color is considered as foreground,
47  * all other colors are background.
48  */
50  : Filter("FilterHSearch")
51 {
52  this->cm = cm;
53  this->what = what;
54 }
55 
56 
57 void
59 {
60  register unsigned int h = 0;
61  register unsigned int w = 0;
62 
63  // y-plane
64  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);
65  // u-plane
66  register unsigned char *up = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
67  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
68  // v-plane
69  register unsigned char *vp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
70  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
71 
72  // destination y-plane
73  register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
74 
75  // line starts
76  unsigned char *lyp = yp; // y-plane
77  unsigned char *lup = up; // u-plane
78  unsigned char *lvp = vp; // v-plane
79  unsigned char *ldyp = dyp; // destination y-plane
80 
81  // left and right boundary of the current line
82  unsigned int left;
83  unsigned int right;
84  bool flag;
85 
86  for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
87  flag = false;
88  left = right = 0;
89  for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); ++w) {
90  if ( (cm->determine(*yp++, *up, *vp) == what) ) {
91  right = w;
92  flag = true;
93  } else {
94  left = flag?left:w;
95  }
96  if ( (cm->determine(*yp++, *up++, *vp++) == what) ) {
97  right = ++w;
98  flag = true;
99  } else {
100  ++w;
101  left = flag?left:w;
102  }
103  }
104 
105  // clear the dst buffer for this line
106  memset(ldyp, 0, dst_roi->width);
107 
108  // set the left- and right-most pixel to white
109  // but if the pixel is at the boundary, we ignore it
110  // in order to eliminate a straight line at the border.
111  if (left != 0 && left < dst_roi->width) ldyp[left] = 255;
112  if (right != 0 && right < dst_roi->width) ldyp[right] = 255;
113 
114  lyp += src_roi[0]->line_step;
115  lup += src_roi[0]->line_step / 2;
116  lvp += src_roi[0]->line_step / 2;
117  ldyp += dst_roi->line_step;
118  yp = lyp;
119  up = lup;
120  vp = lvp;
121  dyp = ldyp;
122  }
123 
124 }
125 
126 } // end namespace firevision
Color model interface.
Definition: colormodel.h:34
virtual void apply()
Apply the filter.
Definition: hor_search.cpp:58
fawkes::upoint_t start
ROI start.
Definition: roi.h:119
unsigned int y
y coordinate
Definition: types.h:36
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:121
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
Filter interface.
Definition: filter.h:35
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
unsigned int height
ROI height.
Definition: roi.h:123
unsigned int line_step
line step
Definition: roi.h:129
unsigned char * dst
Destination buffer.
Definition: filter.h:67
unsigned int pixel_step
pixel step
Definition: roi.h:131
ROI * dst_roi
Destination ROI.
Definition: filter.h:72
FilterHSearch(ColorModel *cm, color_t what)
Constructor.
Definition: hor_search.cpp:49
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.