Fawkes API Fawkes Development Version
difference.cpp
1
2/***************************************************************************
3 * difference.cpp - implementation of difference intensity filter
4 *
5 * Created: Sun Jun 25 23:07:35 2006 (on train to Ac, father in hospital)
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/difference.h>
25#include <fvutils/color/yuv.h>
26
27#include <cstddef>
28
29namespace firevision {
30
31/** @class FilterDifference <fvfilters/difference.h>
32 * Calculates the difference of two images.
33 */
34
35/** Constructor. */
37{
38}
39
40void
42{
43 if (src[0] == NULL)
44 return;
45 if (src[1] == NULL)
46 return;
47 if (src_roi[0] == NULL)
48 return;
49 if (src_roi[1] == NULL)
50 return;
51
52 unsigned int h = 0;
53 unsigned int w = 0;
54
55 // y-plane
56 unsigned char *byp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
57 + (src_roi[0]->start.x * src_roi[0]->pixel_step);
58 // u-plane
59 unsigned char *bup =
60 YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
61 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
62 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
63 // v-plane
64 unsigned char *bvp =
65 YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
66 + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
67 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
68
69 // y-plane
70 unsigned char *fyp = src[1] + (src_roi[1]->start.y * src_roi[1]->line_step)
71 + (src_roi[1]->start.x * src_roi[1]->pixel_step);
72 // u-plane
73 unsigned char *fup =
74 YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
75 + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2
76 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
77 // v-plane
78 unsigned char *fvp =
79 YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
80 + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2
81 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
82
83 // destination y-plane
84 unsigned char *dyp =
86 // destination u-plane
87 unsigned char *dup =
88 YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
89 + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
90 // destination v-plane
91 unsigned char *dvp =
92 YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
93 + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
94
95 // line starts
96 unsigned char *lbyp = byp; // y-plane
97 unsigned char *lbup = fup; // u-plane
98 unsigned char *lbvp = fvp; // v-plane
99 unsigned char *lfyp = fyp; // y-plane
100 unsigned char *lfup = fup; // u-plane
101 unsigned char *lfvp = fvp; // v-plane
102 unsigned char *ldyp = dyp; // destination y-plane
103 unsigned char *ldup = dup; // destination u-plane
104 unsigned char *ldvp = dvp; // destination v-plane
105
106 for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
107 for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
108 *dyp++ = ((*byp - *fyp) < 0) ? 0 : (*byp - *fyp);
109 ++byp;
110 ++fyp;
111 *dyp++ = ((*byp - *fyp) < 0) ? 0 : (*byp - *fyp);
112 ++byp;
113 ++fyp;
114
115 *dup++ = (*fup++ + *bup++) / 2;
116 *dvp++ = (*fvp++ + *bvp++) / 2;
117 }
118
119 lbyp += src_roi[0]->line_step;
120 lbup += src_roi[0]->line_step / 2;
121 lbvp += src_roi[0]->line_step / 2;
122 lfyp += src_roi[1]->line_step;
123 lfup += src_roi[1]->line_step / 2;
124 lfvp += src_roi[1]->line_step / 2;
125 ldyp += dst_roi->line_step;
126 ldup += dst_roi->line_step / 2;
127 ldvp += dst_roi->line_step / 2;
128 byp = lbyp;
129 bup = lbup;
130 bvp = lbvp;
131 fyp = lfyp;
132 fup = lfup;
133 fvp = lfvp;
134 dyp = ldyp;
135 dup = ldup;
136 dvp = ldvp;
137 }
138}
139
140} // end namespace firevision
FilterDifference()
Constructor.
Definition: difference.cpp:36
virtual void apply()
Apply the filter.
Definition: difference.cpp:41
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 image_width
width of image that contains this ROI
Definition: roi.h:121
unsigned int pixel_step
pixel step
Definition: roi.h:127
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:123
unsigned int x
x coordinate
Definition: types.h:36
unsigned int y
y coordinate
Definition: types.h:37