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