Fawkes API  Fawkes Development Version
unwarp.cpp
1 
2 /***************************************************************************
3  * unwarp.cpp - Implementation of unwarp filter
4  *
5  * Created: Mon Jul 25 11:22:11 2005
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/unwarp.h>
25 #include <fvmodels/mirror/mirrormodel.h>
26 #include <fvutils/color/yuv.h>
27 
28 #include <cstddef>
29 
30 namespace firevision {
31 
32 /** @class FilterUnwarp <fvfilters/unwarp.h>
33  * Create unwarped image with given mirror model.
34  * @author Tim Niemueller
35  */
36 
37 /** Constructor.
38  * @param mm mirror model
39  */
40 FilterUnwarp::FilterUnwarp(MirrorModel *mm) : Filter("FilterUnwarp")
41 {
42  this->mm = mm;
43 }
44 
45 void
47 {
48  // destination y-plane
49  unsigned char *dyp =
51 
52  // destination u-plane
53  unsigned char *dup =
54  YUV422_PLANAR_U_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
55  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
56  // v-plane
57  unsigned char *dvp =
58  YUV422_PLANAR_V_PLANE(dst, dst_roi->image_width, dst_roi->image_height)
59  + ((dst_roi->start.y * dst_roi->line_step) / 2 + (dst_roi->start.x * dst_roi->pixel_step) / 2);
60 
61  // line starts
62  unsigned char *ldyp = dyp; // destination y-plane
63  unsigned char *ldup = dup; // u-plane
64  unsigned char *ldvp = dvp; // v-plane
65 
66  unsigned int warp1_x = 0, warp1_y = 0, warp2_x = 0, warp2_y = 0;
67 
68  unsigned char py1 = 0, py2 = 0, pu1 = 0, pu2 = 0, pv1 = 0, pv2 = 0;
69 
70  for (unsigned int h = 0; h < dst_roi->height; ++h) {
71  for (unsigned int w = 0; w < dst_roi->width; w += 2) {
72  mm->unwarp2warp(dst_roi->start.x + w, dst_roi->start.y + h, &warp1_x, &warp1_y);
73  mm->unwarp2warp(dst_roi->start.x + w + 1, dst_roi->start.y + h + 1, &warp2_x, &warp2_y);
74 
75  if ((warp1_x < src_roi[0]->image_width) && (warp1_y < src_roi[0]->image_height)) {
76  // Src pixel is in original image
77 
78  YUV422_PLANAR_YUV(src[0],
79  src_roi[0]->image_width,
80  src_roi[0]->image_height,
81  warp1_x,
82  warp1_y,
83  py1,
84  pu1,
85  pv1);
86 
87  *dyp++ = py1;
88  *dup = pu1;
89  *dvp = pv1;
90 
91  if ((warp2_x < src_roi[0]->image_width) && (warp2_y < src_roi[0]->image_height)) {
92  YUV422_PLANAR_YUV(src[0],
93  src_roi[0]->image_width,
94  src_roi[0]->image_height,
95  warp2_x,
96  warp2_y,
97  py2,
98  pu2,
99  pv2);
100 
101  *dyp++ = py2;
102  *dup = (*dup + pu2) / 2;
103  *dvp = (*dvp + pv2) / 2;
104  } else {
105  *dyp++ = 0;
106  }
107  dup++;
108  dvp++;
109  } else {
110  *dyp++ = 0;
111  *dup = 0;
112  *dvp = 0;
113 
114  if ((warp2_x < src_roi[0]->image_width) && (warp2_y < src_roi[0]->image_height)) {
115  YUV422_PLANAR_YUV(src[0],
116  src_roi[0]->image_width,
117  src_roi[0]->image_height,
118  warp2_x,
119  warp2_y,
120  py2,
121  pu2,
122  pv2);
123 
124  *dyp++ = py2;
125  *dup = pu2;
126  *dvp = pv2;
127  } else {
128  *dyp++ = 0;
129  }
130 
131  dup++;
132  dvp++;
133  }
134  }
135 
136  ldyp += dst_roi->line_step;
137  ldup += dst_roi->line_step;
138  ldup += dst_roi->line_step;
139  dyp = ldyp;
140  dup = ldup;
141  dvp = ldvp;
142  }
143 }
144 
145 } // end namespace firevision
firevision::MirrorModel::unwarp2warp
virtual void unwarp2warp(unsigned int unwarp_x, unsigned int unwarp_y, unsigned int *warp_x, unsigned int *warp_y)=0
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::FilterUnwarp::FilterUnwarp
FilterUnwarp(MirrorModel *mm)
Constructor.
Definition: unwarp.cpp:46
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:78
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
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::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:75
firevision::FilterUnwarp::apply
virtual void apply()
Definition: unwarp.cpp:52