Fawkes API  Fawkes Development Version
min.cpp
1 
2 /***************************************************************************
3  * min.cpp - implementation of min intensity filter
4  *
5  * Created: Mon Jun 05 16:57:57 2006
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/min.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 FilterMin <fvfilters/min.h>
38  * Minimum filter
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor. */
43 FilterMin::FilterMin()
44  : Filter("FilterMin", 2)
45 {
46 }
47 
48 
49 void
51 {
52  if ( src[0] == NULL ) throw NullPointerException("FilterInvert: src buffer 0 is NULL");
53  if ( src[1] == NULL ) throw NullPointerException("FilterInvert: src buffer 1 is NULL");
54  if ( src_roi[0] == NULL ) throw NullPointerException("FilterInvert: src ROI 0 is NULL");
55  if ( src_roi[1] == NULL ) throw NullPointerException("FilterInvert: src ROI 1 is NULL");
56 
57  register unsigned int h = 0;
58  register unsigned int w = 0;
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  unsigned char u1, u2, v1, v2;
101 
102  for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
103  for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
104  if ( *byp < *fyp ) {
105  *dyp++ = *byp;
106  u1 = *bup;
107  v1 = *bvp;
108  } else {
109  *dyp++ = *fyp;
110  u1 = *fup;
111  v1 = *fvp;
112  }
113  ++byp;
114  ++fyp;
115 
116  if ( *byp < *fyp ) {
117  *dyp++ = *byp;
118  u2 = *bup;
119  v2 = *bvp;
120  } else {
121  *dyp++ = *fyp;
122  u2 = *fup;
123  v2 = *fvp;
124  }
125  ++byp;
126  ++fyp;
127 
128  *dup++ = (u1 + u2) / 2;
129  *dvp++ = (v1 + v2) / 2;
130 
131  ++bup;
132  ++bvp;
133  ++fup;
134  ++fvp;
135  }
136 
137  lbyp += src_roi[0]->line_step;
138  lbup += src_roi[0]->line_step / 2;
139  lbvp += src_roi[0]->line_step / 2;
140  lfyp += src_roi[1]->line_step;
141  lfup += src_roi[1]->line_step / 2;
142  lfvp += src_roi[1]->line_step / 2;
143  ldyp += dst_roi->line_step;
144  ldup += dst_roi->line_step / 2;
145  ldvp += dst_roi->line_step / 2;
146  byp = lbyp;
147  bup = lbup;
148  bvp = lbvp;
149  fyp = lfyp;
150  fup = lfup;
151  fvp = lfvp;
152  dyp = ldyp;
153  dup = ldup;
154  dvp = ldvp;
155  }
156 
157 }
158 
159 } // 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
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
virtual void apply()
Apply the filter.
Definition: min.cpp:50
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