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 <core/exceptions/software.h>
25 #include <fvfilters/min.h>
26 #include <fvutils/color/yuv.h>
27 
28 #include <cstddef>
29 
30 using namespace fawkes;
31 
32 namespace firevision {
33 
34 /** @class FilterMin <fvfilters/min.h>
35  * Minimum filter
36  * @author Tim Niemueller
37  */
38 
39 /** Constructor. */
40 FilterMin::FilterMin() : Filter("FilterMin", 2)
41 {
42 }
43 
44 void
46 {
47  if (src[0] == NULL)
48  throw NullPointerException("FilterInvert: src buffer 0 is NULL");
49  if (src[1] == NULL)
50  throw NullPointerException("FilterInvert: src buffer 1 is NULL");
51  if (src_roi[0] == NULL)
52  throw NullPointerException("FilterInvert: src ROI 0 is NULL");
53  if (src_roi[1] == NULL)
54  throw NullPointerException("FilterInvert: src ROI 1 is NULL");
55 
56  unsigned int h = 0;
57  unsigned int w = 0;
58 
59  // y-plane
60  unsigned char *byp = src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
61  + (src_roi[0]->start.x * src_roi[0]->pixel_step);
62  // u-plane
63  unsigned char *bup =
64  YUV422_PLANAR_U_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
65  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
66  + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
67  // v-plane
68  unsigned char *bvp =
69  YUV422_PLANAR_V_PLANE(src[0], src_roi[0]->image_width, src_roi[0]->image_height)
70  + ((src_roi[0]->start.y * src_roi[0]->line_step) / 2
71  + (src_roi[0]->start.x * src_roi[0]->pixel_step) / 2);
72 
73  // y-plane
74  unsigned char *fyp = src[1] + (src_roi[1]->start.y * src_roi[1]->line_step)
75  + (src_roi[1]->start.x * src_roi[1]->pixel_step);
76  // u-plane
77  unsigned char *fup =
78  YUV422_PLANAR_U_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
79  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2
80  + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
81  // v-plane
82  unsigned char *fvp =
83  YUV422_PLANAR_V_PLANE(src[1], src_roi[1]->image_width, src_roi[1]->image_height)
84  + ((src_roi[1]->start.y * src_roi[1]->line_step) / 2
85  + (src_roi[1]->start.x * src_roi[1]->pixel_step) / 2);
86 
87  // destination y-plane
88  unsigned char *dyp =
90  // destination u-plane
91  unsigned char *dup =
92  YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
93  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
94  // destination v-plane
95  unsigned char *dvp =
96  YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
97  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
98 
99  // line starts
100  unsigned char *lbyp = byp; // y-plane
101  unsigned char *lbup = fup; // u-plane
102  unsigned char *lbvp = fvp; // v-plane
103  unsigned char *lfyp = fyp; // y-plane
104  unsigned char *lfup = fup; // u-plane
105  unsigned char *lfvp = fvp; // v-plane
106  unsigned char *ldyp = dyp; // destination y-plane
107  unsigned char *ldup = dup; // destination u-plane
108  unsigned char *ldvp = dvp; // destination v-plane
109 
110  unsigned char u1, u2, v1, v2;
111 
112  for (h = 0; (h < src_roi[1]->height) && (h < dst_roi->height); ++h) {
113  for (w = 0; (w < src_roi[1]->width) && (w < dst_roi->width); w += 2) {
114  if (*byp < *fyp) {
115  *dyp++ = *byp;
116  u1 = *bup;
117  v1 = *bvp;
118  } else {
119  *dyp++ = *fyp;
120  u1 = *fup;
121  v1 = *fvp;
122  }
123  ++byp;
124  ++fyp;
125 
126  if (*byp < *fyp) {
127  *dyp++ = *byp;
128  u2 = *bup;
129  v2 = *bvp;
130  } else {
131  *dyp++ = *fyp;
132  u2 = *fup;
133  v2 = *fvp;
134  }
135  ++byp;
136  ++fyp;
137 
138  *dup++ = (u1 + u2) / 2;
139  *dvp++ = (v1 + v2) / 2;
140 
141  ++bup;
142  ++bvp;
143  ++fup;
144  ++fvp;
145  }
146 
147  lbyp += src_roi[0]->line_step;
148  lbup += src_roi[0]->line_step / 2;
149  lbvp += src_roi[0]->line_step / 2;
150  lfyp += src_roi[1]->line_step;
151  lfup += src_roi[1]->line_step / 2;
152  lfvp += src_roi[1]->line_step / 2;
153  ldyp += dst_roi->line_step;
154  ldup += dst_roi->line_step / 2;
155  ldvp += dst_roi->line_step / 2;
156  byp = lbyp;
157  bup = lbup;
158  bvp = lbvp;
159  fyp = lfyp;
160  fup = lfup;
161  fvp = lfvp;
162  dyp = ldyp;
163  dup = ldup;
164  dvp = ldvp;
165  }
166 }
167 
168 } // end namespace firevision
firevision::ROI::width
unsigned int width
ROI width.
Definition: roi.h:123
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:73
firevision::ROI::image_width
unsigned int image_width
width of image that contains this ROI
Definition: roi.h:127
firevision::ROI::image_height
unsigned int image_height
height of image that contains this ROI
Definition: roi.h:129
firevision::ROI::height
unsigned int height
ROI height.
Definition: roi.h:125
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:78
fawkes
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition: types.h:37
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition: roi.h:133
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition: filter.h:80
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition: roi.h:121
fawkes::NullPointerException
Definition: software.h:37
firevision::ROI::line_step
unsigned int line_step
line step
Definition: roi.h:131
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition: types.h:36
firevision::Filter
Definition: filter.h:38
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:75
firevision::FilterMin::apply
virtual void apply()
Definition: min.cpp:45