Fawkes API  Fawkes Development Version
colorthreshold.cpp
1 /*
2  * colorthreshold.cpp
3  *
4  * Created on: 23.01.2014
5  * Author: Victor MatarĂ©
6  */
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version. A runtime exception applies to
12  * this software (see LICENSE.GPL_WRE file mentioned below for details).
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
20  */
21 
22 #include <fvfilters/colorthreshold.h>
23 #include <fvutils/color/rgbyuv.h>
24 #include <fvutils/color/yuv.h>
25 #include <fvutils/color/threshold.h>
26 #include <math.h>
27 
28 namespace firevision
29 {
30 #if 0 /* just to make Emacs auto-indent happy */
31 }
32 #endif
33 
34 
36  : Filter("FilterColorThreshold", 1),
37  color_model_(color_model)
38 {}
39 
40 FilterColorThreshold::~FilterColorThreshold() {
41 }
42 
44 {
45  register unsigned int h = 0;
46  register unsigned int w = 0;
47 
48  register unsigned char *p_src_y = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
49  register unsigned char *p_src_u = YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
50  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
51  register unsigned char *p_src_v = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
52  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
53 
54  register unsigned char *p_dst_y = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
55  register unsigned char *p_dst_u = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
56  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
57  register unsigned char *p_dst_v = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
58  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
59 
60  unsigned const char *p_line_src_y = p_src_y,
61  *p_line_src_u = p_src_u,
62  *p_line_src_v = p_src_v,
63  *p_line_dst_y = p_dst_y,
64  *p_line_dst_u = p_dst_u,
65  *p_line_dst_v = p_dst_v;
66 
67  for (h = 0; (h < src_roi[0]->height) && (h < dst_roi->height); ++h) {
68  for (w = 0; (w < src_roi[0]->width) && (w < dst_roi->width); w += 2) {
69 
70  // just copy Y plane from src to dst
71  *p_dst_y++ = *p_src_y++;
72  *p_dst_y++ = *p_src_y++;
73 
74  if (color_model_->determine(*p_src_y, *p_src_u, *p_src_v) != C_OTHER) {
75  *p_dst_u++ = *p_src_u;
76  *p_dst_v++ = *p_src_v;
77  }
78  else {
79  *p_dst_u++ = 0x80;
80  *p_dst_v++ = 0x80;
81  }
82  p_src_u++;
83  p_src_v++;
84  }
85 
86  p_line_src_y += src_roi[0]->line_step;
87  p_line_src_u += src_roi[0]->line_step / 2;
88  p_line_src_v += src_roi[0]->line_step / 2;
89 
90  p_line_dst_y += src_roi[0]->line_step;
91  p_line_dst_u += src_roi[0]->line_step / 2;
92  p_line_dst_v += src_roi[0]->line_step / 2;
93  }
94 
95 }
96 
97 
98 } /* namespace firevision */
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Determine the color class of a given YUV value.
Definition: similarity.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 int image_width
width of image that contains this ROI
Definition: roi.h:125
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 height
ROI height.
Definition: roi.h:123
FilterColorThreshold(ColorModelSimilarity *color_model)
Constructor.
unsigned int line_step
line step
Definition: roi.h:129
virtual void apply()
Apply the filter.
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
Matches colors that are similar to given reference colors.
Definition: similarity.h:40