1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_crop.c,v $
37 * Date : $Date: 2004/08/04 15:07:47 $
38 * Version : $Revision: 1.1 $
39 * CVS Id : $Id: imgPrc_crop.c,v 1.1 2004/08/04 15:07:47 paul Exp $
40 *
41 * Author : S.Crossley, NAT
42 */
43
44 /**
45 * @file
46 * @brief imf_crop_and_pad: delux faster padding func replacing unknowns with
47 * nearest neighbours, crop ensures that the region boundaries are
48 * multiples of 8 and therefore easy to use in ctf stereo scaling.
49 *
50 */
51
52 #include "imgPrc_crop.h"
53
54 #if HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58
59 #include <math.h>
60 #include <tina/sys/sysDef.h>
61 #include <tina/sys/sysPro.h>
62 #include <tina/math/mathDef.h>
63 #include <tina/math/mathPro.h>
64 #include <tina/image/imgDef.h>
65 #include <tina/image/imgPro.h>
66
67 /*
68 #include "correlate.h"
69 */
70 #define PAD_DEPTH 8
71
72 static int nearest_row(Imregion *roi, int y)
73 {
74 if (y < roi->ly) return(roi->ly);
75 if (y >= roi->uy) return(roi->uy - 1);
76 return(y);
77 }
78
79 static int nearest_col(Imregion *roi, int x)
80 {
81 if (x < roi->lx) return(roi->lx);
82 if (x >= roi->ux) return(roi->ux - 1);
83 return(x);
84 }
85
86
87 Imrect *imf_crop_and_pad(Imrect *im)
88 {
89 Imrect *new_im = NULL;
90 Imregion im_roi, padded_roi;
91 int row, col;
92 float *row_ptr1, *row_ptr2;
93
94 im_roi = *(im->region);
95
96 if (im_roi.lx > 0)
97 im_roi.lx += (8 - im_roi.lx % 8);
98 else if (im_roi.lx < 0)
99 im_roi.lx -= im_roi.lx % 8;
100
101 if (im_roi.ly > 0)
102 im_roi.ly += (8 - im_roi.ly % 8);
103 else if (im_roi.ly < 0)
104 im_roi.ly -= im_roi.ly % 8;
105
106 if (im_roi.ux > 0)
107 im_roi.ux -= im_roi.ux % 8;
108 else if (im_roi.ux < 0)
109 im_roi.ux -= (8 + im_roi.ux % 8);
110
111 if (im_roi.uy > 0)
112 im_roi.uy -= im_roi.uy % 8;
113 else if (im_roi.uy < 0)
114 im_roi.uy -= (8 + im_roi.uy % 8);
115
116 padded_roi = im_roi;
117 padded_roi.lx -= PAD_DEPTH;
118 padded_roi.ly -= PAD_DEPTH;
119 padded_roi.ux += PAD_DEPTH;
120 padded_roi.uy += PAD_DEPTH;
121
122 new_im = im_alloc(im->height, im->width, &padded_roi, float_v);
123
124 for (row = padded_roi.ly; row < padded_roi.uy; row++)
125 {
126 row_ptr1 = ((float **)(im->data))[nearest_row(&im_roi, row)];
127 row_ptr2 = ((float **)(new_im->data))[row];
128 for (col = padded_roi.lx; col < padded_roi.ux; col++)
129 row_ptr2[col] = row_ptr1[nearest_col(&im_roi, col)];
130 }
131
132 return(new_im);
133 }
134
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.