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