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#include <fvutils/color/yuv.h>
27
28#include <cstddef>
29#include <cstring>
30
31namespace firevision {
32
33/** @class FilterHSearch <fvfilters/hor_search.h>
34 * Search horizontally for a color change. Mark these changes with white
35 * pixels, all other with black pixels.
36 * @author Yuxiao Hu
37 * @author Tim Niemueller
38 */
39
40/** Constructor.
41 * @param cm color model to use to determine the color change
42 * @param what what to look for, this color is considered as foreground,
43 * all other colors are background.
44 */
45FilterHSearch::FilterHSearch(ColorModel *cm, color_t what) : Filter("FilterHSearch")
46{
47 this->cm = cm;
48 this->what = what;
49}
50
51void
53{
54 unsigned int h = 0;
55 unsigned int w = 0;
56
57 // y-plane
58 unsigned char *yp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
59 + (src_roi[0]->start.x * src_roi[0]->pixel_step);
60 // u-plane
61 unsigned char *up =
62 YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
63 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
64 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
65 // v-plane
66 unsigned char *vp =
67 YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
68 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
69 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
70
71 // destination y-plane
72 unsigned char *dyp =
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)
112 ldyp[left] = 255;
113 if (right != 0 && right < dst_roi->width)
114 ldyp[right] = 255;
115
116 lyp += src_roi[0]->line_step;
117 lup += src_roi[0]->line_step / 2;
118 lvp += src_roi[0]->line_step / 2;
119 ldyp += dst_roi->line_step;
120 yp = lyp;
121 up = lup;
122 vp = lvp;
123 dyp = ldyp;
124 }
125}
126
127} // end namespace firevision
Color model interface.
Definition: colormodel.h:32
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.
FilterHSearch(ColorModel *cm, color_t what)
Constructor.
Definition: hor_search.cpp:45
virtual void apply()
Apply the filter.
Definition: hor_search.cpp:52
Filter interface.
Definition: filter.h:33
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
unsigned char * dst
Destination buffer.
Definition: filter.h:63
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
unsigned int height
ROI height.
Definition: roi.h:119
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
unsigned int line_step
line step
Definition: roi.h:125
unsigned int width
ROI width.
Definition: roi.h:117
unsigned int pixel_step
pixel step
Definition: roi.h:127
unsigned int x
x coordinate
Definition: types.h:36
unsigned int y
y coordinate
Definition: types.h:37