Fawkes API  Fawkes Development Version
max.cpp
1 
2 /***************************************************************************
3  * max.cpp - implementation of max intensity filter
4  *
5  * Created: Sat Jun 10 16:43:41 2006 (FIFA WM 2006, England vs. Paraguay)
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/max.h>
25 
26 #include <core/exceptions/software.h>
27 #include <fvutils/color/yuv.h>
28 #include <cstddef>
29 
30 using namespace fawkes;
31 
32 namespace firevision {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 /** @class FilterMax <fvfilters/max.h>
38  * Maximum filter.
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor. */
43 FilterMax::FilterMax()
44  : Filter("FilterMax", 2)
45 {
46 }
47 
48 void
50 {
51  if ( src[0] == NULL ) throw NullPointerException("FilterInvert: src buffer 0 is NULL");
52  if ( src[1] == NULL ) throw NullPointerException("FilterInvert: src buffer 1 is NULL");
53  if ( src_roi[0] == NULL ) throw NullPointerException("FilterInvert: src ROI 0 is NULL");
54  if ( src_roi[1] == NULL ) throw NullPointerException("FilterInvert: src ROI 1 is NULL");
55 
56  register unsigned int h = 0;
57  register unsigned int w = 0;
58 
59  // y-plane
60  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);
61  // u-plane
62  register unsigned char *bup = 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 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2) ;
64  // v-plane
65  register unsigned char *bvp = 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 + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
67 
68 
69  // y-plane
70  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);
71  // u-plane
72  register unsigned char *fup = YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
73  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2) ;
74  // v-plane
75  register unsigned char *fvp = YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
76  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2 + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
77 
78 
79  // destination y-plane
80  register unsigned char *dyp = dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step);
81  // destination u-plane
82  register unsigned char *dup = YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
83  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2) ;
84  // destination v-plane
85  register unsigned char *dvp = YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
86  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
87 
88  // line starts
89  unsigned char *lbyp = byp; // y-plane
90  unsigned char *lbup = fup; // u-plane
91  unsigned char *lbvp = fvp; // v-plane
92  unsigned char *lfyp = fyp; // y-plane
93  unsigned char *lfup = fup; // u-plane
94  unsigned char *lfvp = fvp; // v-plane
95  unsigned char *ldyp = dyp; // destination y-plane
96  unsigned char *ldup = dup; // destination u-plane
97  unsigned char *ldvp = dvp; // destination v-plane
98 
99  unsigned char u1, u2, v1, v2;
100 
101  for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
102  for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
103  if ( *byp > *fyp ) {
104  *dyp++ = *byp;
105  u1 = *bup;
106  v1 = *bvp;
107  } else {
108  *dyp++ = *fyp;
109  u1 = *fup;
110  v1 = *fvp;
111  }
112  ++byp;
113  ++fyp;
114 
115  if ( *byp > *fyp ) {
116  *dyp++ = *byp;
117  u2 = *bup;
118  v2 = *bvp;
119  } else {
120  *dyp++ = *fyp;
121  u2 = *fup;
122  v2 = *fvp;
123  }
124  ++byp;
125  ++fyp;
126 
127  *dup++ = (u1 + u2) / 2;
128  *dvp++ = (v1 + v2) / 2;
129 
130  ++bup;
131  ++bvp;
132  ++fup;
133  ++fvp;
134  }
135 
136  lbyp += src_roi[0]->line_step;
137  lbup += src_roi[0]->line_step / 2;
138  lbvp += src_roi[0]->line_step / 2;
139  lfyp += src_roi[1]->line_step;
140  lfup += src_roi[1]->line_step / 2;
141  lfvp += src_roi[1]->line_step / 2;
142  ldyp += dst_roi->line_step;
143  ldup += dst_roi->line_step / 2;
144  ldvp += dst_roi->line_step / 2;
145  byp = lbyp;
146  bup = lbup;
147  bvp = lbvp;
148  fyp = lfyp;
149  fup = lfup;
150  fvp = lfvp;
151  dyp = ldyp;
152  dup = ldup;
153  dvp = ldvp;
154  }
155 
156 }
157 
158 } // end namespace firevision
Fawkes library namespace.
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
A NULL pointer was supplied where not allowed.
Definition: software.h:34
virtual void apply()
Apply the filter.
Definition: max.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
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