Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[7339b1]: remap.c Maximize Restore History

Download this file

remap.c    370 lines (339 with data), 12.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* Panorama_Tools - Generate, Edit and Convert Panoramic Images
Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software; see the file COPYING. If not, a copy
can be downloaded from http://www.gnu.org/licenses/gpl.html, or
obtained by writing to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*------------------------------------------------------------*/
#include "filter.h"
void remap(TrformStr *TrPtr, rPrefs *r_prefs)
{
fDesc fD; // remapping function
double vars[3]; // variables required for calculation
// vars[0] = distance d
// vars[1]
// vars[2]
double a,b; // horizontal/vertical field of view in 'rad'
int destwidth=0, destheight=0;
fD.param = (void*) vars;
fD.func = (trfn)NULL;
// Check for inconsistent values (should be extended!)
if( r_prefs->hfov <= 0.0 )
{
TrPtr->success = 0;
PrintError("Parameter Error");
return;
}
// Set destination image parameters and parameters for remapping
a = DEG_TO_RAD( r_prefs->hfov );
switch(r_prefs->from)
{
case _rectilinear:
if( a >= PI )
{
TrPtr->success = 0;
PrintError("Wrong FOV: Must be smaller than 180 degrees");
return;
}
vars[0] = TrPtr->src->width / ( 2.0 * tan( a/2.0 ) );
switch(r_prefs->to)
{
case _rectilinear: TrPtr->success = 0;
PrintError("Same Mapping!");
return;
break;
case _panorama :
destheight = TrPtr->src->height;
destwidth = (int)(a * vars[0] + 0.5);
fD.func = rect_pano;
break;
case _equirectangular:
destheight = (int)(2.0 * vars[0] * atan( TrPtr->src->height/(2*vars[0]) ) + 0.5);
destwidth = (int)(a * vars[0] + 0.5);
fD.func = rect_erect;
break;
case _spherical_cp:TrPtr->success = 0;
PrintError("Use Fisheye Horizontal and Perspective");
return;
break;
case _spherical_tp:
destheight = (int)(2.0 * vars[0] * atan( TrPtr->src->height/(2*vars[0]) ) + 0.5);
destwidth = (int)(a * vars[0] + 0.5);
fD.func = rect_sphere_tp;
break;
case _mirror:TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
default: break;
}
break;
case _panorama:
vars[0] = TrPtr->src->width / a;
switch(r_prefs->to)
{
case _rectilinear:
if( a >= PI )
{
TrPtr->success = 0;
PrintError("Wrong FOV: Must be smaller than 180 degrees");
return;
}
destheight = TrPtr->src->height;
destwidth = (int)(2.0 * tan( a/2.0 ) * vars[0] + 0.5);
fD.func = pano_rect;
break;
case _panorama : TrPtr->success = 0;
PrintError("Same Mapping!");
return;
break;
case _equirectangular:
destheight = (int)(2 * vars[0] * atan( TrPtr->src->height/ (2*vars[0]) ));
destwidth = TrPtr->src->width;
fD.func = pano_erect;
break;
case _spherical_cp:
TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
case _spherical_tp:
destheight = TrPtr->src->width ;//2 * vars[0] * atan( TrPtr->src->height/ (2*vars[0]) );
destwidth = TrPtr->src->width;
fD.func = pano_sphere_tp;
break;
case _mirror:TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
default: break;
}
break;
case _equirectangular:
vars[0] = TrPtr->src->width / a;
b = TrPtr->src->height/ vars[0];
switch(r_prefs->to)
{
case _rectilinear:
if( a >= PI || b >= PI )
{
TrPtr->success = 0;
PrintError("Wrong FOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(2 * vars[0] * tan( TrPtr->src->height/(2*vars[0]) ));
destwidth = (int)(2 * vars[0] * tan( TrPtr->src->width/(2*vars[0]) ));
fD.func = erect_rect;
break;
case _panorama :
if( b >= PI )
{
TrPtr->success = 0;
PrintError("Wrong VFOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(2 * vars[0] * tan( TrPtr->src->height/(2*vars[0]) ));
destwidth = TrPtr->src->width;
fD.func = erect_pano;
break;
case _equirectangular:TrPtr->success = 0;
PrintError("Same Mapping!");
return;
break;
case _spherical_cp:
destwidth = 2 * TrPtr->src->height;
destheight = 2 * TrPtr->src->height;
vars[1] = TrPtr->src->height/2; // vars[1] is midpoint
fD.func = erect_sphere_cp;
break;
case _spherical_tp:
destwidth = TrPtr->src->width;
destheight = TrPtr->src->width;
fD.func = erect_sphere_tp;
break;
case _mirror:TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
default: break;
}
break;
case _spherical_cp:
if( r_prefs->hfov > MAX_FISHEYE_FOV && r_prefs->vfov > MAX_FISHEYE_FOV ){
TrPtr->success = 0;
PrintError("Fisheye lens processing limited to fov <= %lg", MAX_FISHEYE_FOV);
return;
}
vars[0] = TrPtr->src->width / a;
switch(r_prefs->to)
{
case _rectilinear:TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
case _panorama :
if(r_prefs->vfov >= 180.0 )
{
TrPtr->success = 0;
PrintError("Wrong VFOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(PI * vars[0] * tan(r_prefs->vfov * PI / 360.0));
destwidth = (int)(PI * vars[0] * PI);
fD.func = sphere_cp_pano;
break;
case _equirectangular:
destheight = (int)((TrPtr->src->width > TrPtr->src->height ?
TrPtr->src->width/2: TrPtr->src->height/2) * PI / 2.0);
destwidth = (int)(vars[0] * PI * PI);
vars[1] = destheight / 2;
fD.func = sphere_cp_erect;
break;
case _spherical_cp:TrPtr->success = 0;
PrintError("Same Mapping!");
return;
break;
case _spherical_tp:TrPtr->success = 0;
PrintError("Use tool perspective.");
return;
break;
case _mirror:
vars[1] = TrPtr->src->width / (2 * sin(a/4.0)) ; // Radius of mirror
destwidth = TrPtr->src->width ;
destheight = TrPtr->src->height ;
fD.func = sphere_cp_mirror;
break;
default: break;
}
break;
case _spherical_tp:
if( r_prefs->hfov > MAX_FISHEYE_FOV && r_prefs->vfov > MAX_FISHEYE_FOV ){
TrPtr->success = 0;
PrintError("Fisheye lens processing limited to fov <= %lg", MAX_FISHEYE_FOV);
return;
}
vars[0] = TrPtr->src->width / a;
b = TrPtr->src->height / vars[0];
switch(r_prefs->to)
{
case _rectilinear:
if( a >= PI || b >= PI )
{
TrPtr->success = 0;
PrintError("Wrong FOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(2.0 * vars[0] * tan( TrPtr->src->height / (2.0*vars[0]) ) + 0.5);
destwidth = (int)(2.0 * tan( a/2.0 ) * vars[0] + 0.5);
fD.func = sphere_tp_rect;
break;
case _panorama :
if( b >= PI )
{
TrPtr->success = 0;
PrintError("Wrong VFOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(2.0 * vars[0] * tan( TrPtr->src->height / (2.0*vars[0]) ) + 0.5);
destwidth = TrPtr->src->width;
fD.func = sphere_tp_pano;
break;
case _equirectangular:
destheight = TrPtr->src->height ;
destwidth = TrPtr->src->width;
vars[1] = destheight / 2;
fD.func = sphere_tp_erect;
break;
case _spherical_cp:TrPtr->success = 0;
PrintError("Use tool perspective.");
return;
break;
case _spherical_tp:TrPtr->success = 0;
PrintError( "Same Mapping!");
return;
break;
case _mirror:TrPtr->success = 0;
PrintError( "Sorry, not yet available");
return;
break;
default: break;
}
break;
case _mirror:
vars[1] = TrPtr->src->width / (2 * sin(a/4.0)) ; // Radius of mirror
vars[0] = TrPtr->src->width / a;
switch(r_prefs->to)
{
case _rectilinear:TrPtr->success = 0;
PrintError("Sorry, not yet available");
return;
break;
case _panorama :
if(r_prefs->vfov >= 180.0 )
{
TrPtr->success = 0;
PrintError("Wrong VFOV: Must be smaller than 180 degrees");
return;
}
destheight = (int)(PI * vars[0] * tan(r_prefs->vfov * PI / 360.0));
destwidth = (int)(PI * vars[0] * PI);
fD.func = mirror_pano;
break;
case _equirectangular:
destwidth = (int)(vars[0] * PI * PI);
destheight = (int)(PI * vars[0] * a / 4.0);
vars[2] = destheight / 2.0;
fD.func = mirror_erect;
break;
case _spherical_cp:
destwidth = TrPtr->src->width ;
destheight = TrPtr->src->height ;
fD.func = mirror_sphere_cp;
break;
case _spherical_tp:TrPtr->success = 0;
PrintError( "Sorry, not yet available");
return;
break;
case _mirror:TrPtr->success = 0;
PrintError( "Same Mapping!");
return;
break;
default: break;
}
break;
default: break;
}
if( SetDestImage(TrPtr, destwidth, destheight) != 0 )
{
TrPtr->success = 0;
PrintError( "Not enough Memory.");
return;
}
// Do transformation
if( fD.func != NULL)
{
transFormEx( TrPtr, &fD, &fD, 0, 1 );
//transForm( TrPtr, &fD, 0 );
}
else
TrPtr->success = 0;
if( TrPtr->success == 0 && ! (TrPtr->mode & _destSupplied)) // Moved here
myfree( (void**)TrPtr->dest->data );
}
void SetRemapDefaults( rPrefs *rP )
{
rP->magic = 30; // Magic number for file validity check
rP->from = _rectilinear;
rP->to = _panorama;
rP->hfov = 60.0;
rP->vfov = 60.0;
}