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