Fawkes API  Fawkes Development Version
compare.cpp
1 
2 /***************************************************************************
3  * compare.cpp - implementation of compare filter
4  *
5  * Created: Mon Jun 05 16:57:57 2006
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvfilters/compare.h>
25 #include <fvutils/color/yuv.h>
26 
27 #include <cstddef>
28 
29 namespace firevision {
30 
31 /** Background image. */
32 const unsigned int FilterCompare::BACKGROUND = 0;
33 /** Foreground image. */
34 const unsigned int FilterCompare::FOREGROUND = 1;
35 
36 /** @class FilterCompare <fvfilters/compare.h>
37  * Comparison filter.
38  */
39 
40 /** Constructor. */
41 FilterCompare::FilterCompare() : Filter("FilterCompare", 2)
42 {
43 }
44 
45 void
47 {
48  if (src[BACKGROUND] == NULL)
49  return;
50  if (src[FOREGROUND] == NULL)
51  return;
52  if (src_roi[BACKGROUND] == NULL)
53  return;
54  if (src_roi[FOREGROUND] == NULL)
55  return;
56 
57  unsigned int h = 0;
58  unsigned int w = 0;
59 
60  // y-plane
61  unsigned char *byp = src[BACKGROUND]
64 
65  // y-plane
66  unsigned char *fyp = src[FOREGROUND]
69  // u-plane
70  unsigned char *fup = YUV422_PLANAR_U_PLANE(src[FOREGROUND],
71  src_roi[FOREGROUND]->image_width,
72  src_roi[FOREGROUND]->image_height)
74  + (src_roi[FOREGROUND]->start.x * src_roi[FOREGROUND]->pixel_step) / 2);
75  // v-plane
76  unsigned char *fvp = YUV422_PLANAR_V_PLANE(src[FOREGROUND],
77  src_roi[FOREGROUND]->image_width,
78  src_roi[FOREGROUND]->image_height)
80  + (src_roi[FOREGROUND]->start.x * src_roi[FOREGROUND]->pixel_step) / 2);
81 
82  // destination y-plane
83  unsigned char *dyp =
85  // destination u-plane
86  unsigned char *dup =
87  YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
88  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
89  // destination v-plane
90  unsigned char *dvp =
91  YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
92  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
93 
94  // line starts
95  unsigned char *lbyp = byp; // y-plane
96  unsigned char *lfyp = fyp; // y-plane
97  unsigned char *lfup = fup; // u-plane
98  unsigned char *lfvp = fvp; // v-plane
99  unsigned char *ldyp = dyp; // destination y-plane
100  unsigned char *ldup = dup; // destination u-plane
101  unsigned char *ldvp = dvp; // destination v-plane
102 
103  for (h = 0; (h < src_roi[FOREGROUND]->height) && (h < dst_roi->height); ++h) {
104  for (w = 0; (w < src_roi[FOREGROUND]->width) && (w < dst_roi->width); w += 2) {
105  if (*byp < *fyp) {
106  *dyp++ = *byp;
107  } else {
108  *dyp++ = *fyp;
109  }
110  byp++;
111  fyp++;
112 
113  if (*byp < *fyp) {
114  *dyp++ = *byp;
115  } else {
116  *dyp++ = *fyp;
117  }
118  byp++;
119  fyp++;
120 
121  *dup++ = *fup++;
122  *dvp++ = *fvp++;
123  }
124 
125  lbyp += src_roi[BACKGROUND]->line_step;
126  lfyp += src_roi[FOREGROUND]->line_step;
127  lfup += src_roi[FOREGROUND]->line_step / 2;
128  lfvp += src_roi[FOREGROUND]->line_step / 2;
129  ldyp += dst_roi->line_step;
130  ldup += dst_roi->line_step / 2;
131  ldvp += dst_roi->line_step / 2;
132  byp = lbyp;
133  fyp = lfyp;
134  fup = lfup;
135  fvp = lfvp;
136  dyp = ldyp;
137  dup = ldup;
138  dvp = ldvp;
139  }
140 }
141 
142 } // end namespace firevision
firevision::ROI::width
unsigned int width
ROI width.
Definition: roi.h:117
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
firevision::FilterCompare::FilterCompare
FilterCompare()
Constructor.
Definition: compare.cpp:41
firevision::ROI::image_width
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:121
firevision::ROI::image_height
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:123
firevision::FilterCompare::apply
virtual void apply()
Apply the filter.
Definition: compare.cpp:46
firevision::FilterCompare::BACKGROUND
static const unsigned int BACKGROUND
Background image.
Definition: compare.h:38
firevision::FilterCompare::FOREGROUND
static const unsigned int FOREGROUND
Foreground image.
Definition: compare.h:39
firevision::ROI::height
unsigned int height
ROI height.
Definition: roi.h:119
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition: types.h:37
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition: roi.h:127
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
firevision::ROI::line_step
unsigned int line_step
line step
Definition: roi.h:125
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition: types.h:36
firevision::Filter
Filter interface.
Definition: filter.h:33
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:63