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 
29 #include <fvmodels/color/colormodel.h>
30 #include <fvmodels/scanlines/scanlinemodel.h>
31 
32 #include <fvutils/color/yuv.h>
33 #include <cstddef>
34 
35 
36 namespace firevision {
37 #if 0 /* just to make Emacs auto-indent happy */
38 }
39 #endif
40 
41 /** @class FilterScanlineSegmentation <fvfilters/segment_scanline.h>
42  * Segmentation filter.
43  * Visually marks pixels depending of their classification determined by the
44  * supplied color model to make the segmentation visible - but only the pixels
45  * at scanline points.
46  * The pixels are marked with the color matching the segmentation with an
47  * appropriate place holder color.
48  * @author Tim Niemueller
49  */
50 
51 /** Constructor.
52  * @param cm color model to use
53  * @param slm scanline model to use
54  */
56  : Filter("FilterScanlineSegmentation")
57 {
58  this->cm = cm;
59  this->slm = slm;
60 }
61 
62 
63 void
65 {
66  unsigned int x = 0, y = 0;
67  unsigned char py = 0, pu = 0, pv = 0;
68  register unsigned char *dyp, *dup, *dvp;
69  color_t c;
70 
71 
72  slm->reset();
73  while (! slm->finished()) {
74 
75  x = (*slm)->x;
76  y = (*slm)->y;
77 
78 
79  // Get source pixel values
80  YUV422_PLANAR_YUV(src[0], src_roi[0]->image_width, src_roi[0]->image_height, x, y, py, pu, pv);
81 
82  // destination y-plane
83  dyp = dst + (y * dst_roi->line_step) + (x * dst_roi->pixel_step);
84  // destination u-plane
85  dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
86  + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2) ;
87  // destination v-plane
88  dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
89  + (((y * dst_roi->line_step) + (x * dst_roi->pixel_step)) / 2);
90 
91  c = cm->determine(py, pu, pv);
92 
93  switch (c) {
94  case C_ORANGE:
95  *dyp++ = 128;
96  *dyp++ = 128;
97  *dup++ = 0;
98  *dvp++ = 255;
99  break;
100  case C_MAGENTA:
101  *dyp++ = 128;
102  *dyp++ = 128;
103  *dup++ = 128;
104  *dvp++ = 255;
105  break;
106  case C_CYAN:
107  *dyp++ = 128;
108  *dyp++ = 128;
109  *dup++ = 255;
110  *dvp++ = 0;
111  break;
112  case C_BLUE:
113  *dyp++ = 128;
114  *dyp++ = 128;
115  *dup++ = 255;
116  *dvp++ = 128;
117  break;
118  case C_YELLOW:
119  *dyp++ = 255;
120  *dyp++ = 255;
121  *dup++ = 0;
122  *dvp++ = 128;
123  break;
124  case C_GREEN:
125  *dyp++ = 128;
126  *dyp++ = 128;
127  *dup++ = 0;
128  *dvp++ = 0;
129  break;
130  case C_WHITE:
131  *dyp++ = 255;
132  *dyp++ = 255;
133  *dup++ = 128;
134  *dvp++ = 128;
135  break;
136  case C_RED:
137  *dyp++ = 196;
138  *dyp++ = 196;
139  *dup++ = 0;
140  *dvp++ = 255;
141  break;
142  default:
143  *dyp++ = 0;
144  *dyp++ = 0;
145  *dup++ = 128;
146  *dvp++ = 128;
147  break;
148  }
149  ++(*slm);
150  }
151 }
152 
153 } // end namespace firevision
FilterScanlineSegmentation(ColorModel *cm, ScanlineModel *slm)
Constructor.
Color model interface.
Definition: colormodel.h:34
Scanline model interface.
Definition: scanlinemodel.h:55
unsigned int x
x coordinate
Definition: types.h:35
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:125
virtual void apply()
Apply the filter.
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:65
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:127
Filter interface.
Definition: filter.h:35
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
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
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.