Fawkes API  Fawkes Development Version
segment_scanline.cpp
1 
2 /***************************************************************************
3  * segment_scanline.cpp - Implementation of scanline segmentation filter
4  * This filter can be used to draw the segmentation for
5  * all objects into a colored YUV422_PLANAR buffer
6  * but only on the scanline model points
7  *
8  * Created: Thu Jul 14 15:04:23 2005
9  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
10  *
11  ****************************************************************************/
12 
13 /* This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version. A runtime exception applies to
17  * this software (see LICENSE.GPL_WRE file mentioned below for details).
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Library General Public License for more details.
23  *
24  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
25  */
26 
27 #include <fvfilters/segment_scanline.h>
28 #include <fvmodels/color/colormodel.h>
29 #include <fvmodels/scanlines/scanlinemodel.h>
30 #include <fvutils/color/yuv.h>
31 
32 #include <cstddef>
33 
34 namespace firevision {
35 
36 /** @class FilterScanlineSegmentation <fvfilters/segment_scanline.h>
37  * Segmentation filter.
38  * Visually marks pixels depending of their classification determined by the
39  * supplied color model to make the segmentation visible - but only the pixels
40  * at scanline points.
41  * The pixels are marked with the color matching the segmentation with an
42  * appropriate place holder color.
43  * @author Tim Niemueller
44  */
45 
46 /** Constructor.
47  * @param cm color model to use
48  * @param slm scanline model to use
49  */
51 : Filter("FilterScanlineSegmentation")
52 {
53  this->cm = cm;
54  this->slm = slm;
55 }
56 
57 void
59 {
60  unsigned int x = 0, y = 0;
61  unsigned char py = 0, pu = 0, pv = 0;
62  unsigned char *dyp, *dup, *dvp;
63  color_t c;
64 
65  slm->reset();
66  while (!slm->finished()) {
67  x = (*slm)->x;
68  y = (*slm)->y;
69 
70  // Get source pixel values
71  YUV422_PLANAR_YUV(src[0], src_roi[0]->image_width, src_roi[0]->image_height, x, y, py, pu, pv);
72 
73  // destination y-plane
74  dyp = dst + (y * dst_roi->line_step) + (x * dst_roi->pixel_step);
75  // destination u-plane
76  dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
77  + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2);
78  // destination v-plane
79  dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
80  + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2);
81 
82  c = cm->determine(py, pu, pv);
83 
84  switch (c) {
85  case C_ORANGE:
86  *dyp++ = 128;
87  *dyp++ = 128;
88  *dup++ = 0;
89  *dvp++ = 255;
90  break;
91  case C_MAGENTA:
92  *dyp++ = 128;
93  *dyp++ = 128;
94  *dup++ = 128;
95  *dvp++ = 255;
96  break;
97  case C_CYAN:
98  *dyp++ = 128;
99  *dyp++ = 128;
100  *dup++ = 255;
101  *dvp++ = 0;
102  break;
103  case C_BLUE:
104  *dyp++ = 128;
105  *dyp++ = 128;
106  *dup++ = 255;
107  *dvp++ = 128;
108  break;
109  case C_YELLOW:
110  *dyp++ = 255;
111  *dyp++ = 255;
112  *dup++ = 0;
113  *dvp++ = 128;
114  break;
115  case C_GREEN:
116  *dyp++ = 128;
117  *dyp++ = 128;
118  *dup++ = 0;
119  *dvp++ = 0;
120  break;
121  case C_WHITE:
122  *dyp++ = 255;
123  *dyp++ = 255;
124  *dup++ = 128;
125  *dvp++ = 128;
126  break;
127  case C_RED:
128  *dyp++ = 196;
129  *dyp++ = 196;
130  *dup++ = 0;
131  *dvp++ = 255;
132  break;
133  default:
134  *dyp++ = 0;
135  *dyp++ = 0;
136  *dup++ = 128;
137  *dvp++ = 128;
138  break;
139  }
140  ++(*slm);
141  }
142 }
143 
144 } // end namespace firevision
FilterScanlineSegmentation(ColorModel *cm, ScanlineModel *slm)
Constructor.
Color model interface.
Definition: colormodel.h:31
Scanline model interface.
Definition: scanlinemodel.h:52
unsigned int x
x coordinate
Definition: types.h:36
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:121
virtual void apply()
Apply the filter.
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:123
Filter interface.
Definition: filter.h:32
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
unsigned int line_step
line step
Definition: roi.h:125
unsigned char * dst
Destination buffer.
Definition: filter.h:63
unsigned int pixel_step
pixel step
Definition: roi.h:127
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.