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 
26 #include <fvutils/color/yuv.h>
27 #include <cstddef>
28 
29 namespace firevision {
30 #if 0 /* just to make Emacs auto-indent happy */
31 }
32 #endif
33 
34 /** @class FilterDifference <fvfilters/difference.h>
35  * Calculates the difference of two images.
36  */
37 
38 /** Constructor. */
40  : Filter("FilterDifference", 2)
41 {
42 }
43 
44 
45 void
47 {
48  if ( src[0] == NULL ) return;
49  if ( src[1] == NULL ) return;
50  if ( src_roi[0] == NULL ) return;
51  if ( src_roi[1] == NULL ) return;
52 
53  register unsigned int h = 0;
54  register unsigned int w = 0;
55 
56 
57  // y-plane
58  register unsigned char *byp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step) + (src_roi[0]->start.x * src_roi[0]->pixel_step);
59  // u-plane
60  register unsigned char *bup = 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 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
62  // v-plane
63  register unsigned char *bvp = YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
64  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
65 
66 
67  // y-plane
68  register unsigned char *fyp = src[1] + (src_roi[1]->start.y * src_roi[1]->line_step) + (src_roi[1]->start.x * src_roi[1]->pixel_step);
69  // u-plane
70  register unsigned char *fup = YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
71  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2) ;
72  // v-plane
73  register unsigned char *fvp = YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
74  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
75 
76 
77  // destination y-plane
78  register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
79  // destination u-plane
80  register unsigned char *dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
81  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
82  // destination v-plane
83  register unsigned char *dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
84  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
85 
86  // line starts
87  unsigned char *lbyp = byp; // y-plane
88  unsigned char *lbup = fup; // u-plane
89  unsigned char *lbvp = fvp; // v-plane
90  unsigned char *lfyp = fyp; // y-plane
91  unsigned char *lfup = fup; // u-plane
92  unsigned char *lfvp = fvp; // v-plane
93  unsigned char *ldyp = dyp; // destination y-plane
94  unsigned char *ldup = dup; // destination u-plane
95  unsigned char *ldvp = dvp; // destination v-plane
96 
97  for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
98  for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
99  *dyp++ = ((*byp - *fyp) < 0) ? 0 : (*byp - *fyp);
100  ++byp; ++fyp;
101  *dyp++ = ((*byp - *fyp) < 0) ? 0 : (*byp - *fyp);
102  ++byp; ++fyp;
103 
104  *dup++ = (*fup++ + *bup++) / 2;
105  *dvp++ = (*fvp++ + *bvp++) / 2;
106  }
107 
108  lbyp += src_roi[0]->line_step;
109  lbup += src_roi[0]->line_step / 2;
110  lbvp += src_roi[0]->line_step / 2;
111  lfyp += src_roi[1]->line_step;
112  lfup += src_roi[1]->line_step / 2;
113  lfvp += src_roi[1]->line_step / 2;
114  ldyp += dst_roi->line_step;
115  ldup += dst_roi->line_step / 2;
116  ldvp += dst_roi->line_step / 2;
117  byp = lbyp;
118  bup = lbup;
119  bvp = lbvp;
120  fyp = lfyp;
121  fup = lfup;
122  fvp = lfvp;
123  dyp = ldyp;
124  dup = ldup;
125  dvp = ldvp;
126  }
127 
128 }
129 
130 } // end namespace firevision
FilterDifference()
Constructor.
Definition: difference.cpp:39
virtual void apply()
Apply the filter.
Definition: difference.cpp:46
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
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