1 /* Panorama_Tools	-	Generate, Edit and Convert Panoramic Images
2    Copyright (C) 1998,1999 - Helmut Dersch  der@fh-furtwangen.de
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this software; see the file COPYING.  If not, a copy
16    can be downloaded from http://www.gnu.org/licenses/gpl.html, or
17    obtained by writing to the Free Software Foundation, Inc.,
18    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19 
20 /*------------------------------------------------------------*/
21 
22 
23 
24 #ifndef PANORAMA_H
25 #define PANORAMA_H
26 
27 #if defined _WIN32 && defined PANO13_DLL
28 #if defined pano13_EXPORTS
29 #define PANO13_IMPEX __declspec(dllexport)
30 #else
31 #define PANO13_IMPEX __declspec(dllimport)
32 #endif
33 #else
34 #define PANO13_IMPEX
35 #endif
36 
37 #include "pt_stdint.h"
38 #include "version.h"
39 #include "panotypes.h"
40 
41 // MRDL: Replaced BIGENDIAN with PT_BIGENDIAN to eliminate conflict with
42 // BIGENDIAN defined in winsock2.h distributed with MingW 2.0
43 
44 // Determine which machine we are using. Macs are set to PT_BIGENDIAN, all others not
45 
46 // If you need PT_BIGENDIAN, and don't use MacOS, define it here:
47 //#define PT_BIGENDIAN                  1
48 
49 typedef unsigned char Boolean;
50 
51 // Create a definition if we're on a Windows machine:
52 #ifndef __Ansi__
53   #if (defined(MSDOS) || defined(_CONSOLE) || defined(__DOS__) || defined(__MSDOS__))
54     #define __Ansi__      1
55   #endif
56 #endif
57 
58 #ifndef __Win__
59   #if (defined(_WINDOWS) || defined(WINDOWS))
60     #define __Win__     1
61   #endif
62 #endif
63 
64 #ifndef __Mac_OSX__
65     #if defined(__APPLE_CC__)
66         #define __Mac_OSX__			1
67         #if (defined(__ppc__) || defined(__ppc64__))
68             #define PT_BIGENDIAN		1
69         #elif defined(__i386__)
70             #undef PT_BIGENDIAN
71         #endif
72     #endif
73 #endif
74 
75 // Use FSSpec on Macs as Path-specifyers, else strings
76 #define PATH_SEP							'/'
77 
78 #ifdef _WIN32
79     #ifndef __NO_SYSTEM__
80         #include <windows.h>            // including this causes problems with libjpeg
81     #endif
82 
83     #define MAX_PATH_LENGTH		260
84                 // was MAX_PATH
85     #undef  PATH_SEP
86     #define PATH_SEP							'\\'
87 
88 #else
89     #define MAX_PATH_LENGTH		512
90 #endif
91 
92 // I really want to get rid of this one. it is legacy from OS 9
93 typedef struct
94 {
95     char name[MAX_PATH_LENGTH];
96 } fullPath;
97 
98 
99 // Some important defaults (perhaps to be moved somewhere else later
100 
101 // Enumerates for TrFormStr.tool
102 
103 enum
104 {                               // Panorama Tools
105     _perspective,
106     _correct,
107     _remap,
108     _adjust,
109     _interpolate,
110     _sizep,                     // dummy for size-preferences
111     _version,                   // dummy for version
112     _panright,                  // Pan Controls
113     _panleft,
114     _panup,
115     _pandown,
116     _zoomin,
117     _zoomout,
118     _apply,
119     _getPano,
120     _increment
121 };
122 
123 // Enumerates for TrFormStr.mode
124 
125 enum
126 {                               // Modes
127     _interactive,               // display dialogs and do Xform
128     _useprefs,                  // load saved prefs and do Xform/ no dialogs
129     _setprefs,                  // display dialogs and set preferences, no Xform
130     _usedata,                   // use supplied data in TrFormStr.data, do Xform
131     _honor_valid = 8,           // Use only pixels with alpha channel set
132     _show_progress = 16,        // Interpolator displays progress bar
133     _hostCanResize = 32,        // o-no; 1-yes (Photoshop: no; GraphicConverter: yes)
134     _destSupplied = 64,         // Destination image allocated by plug-in host
135     _wrapX = 128                // Wrap image horizontally (if HFOV==360 degrees)
136 };
137 
138 
139 // Enumerates for Image.dataformat
140 
141 enum
142 {
143     _RGB,
144     _Lab,
145     _Grey
146 };
147 
148 // Enumerates for TrFormStr.interpolator
149 
150 enum
151 {                               // Interpolators
152     _poly3 = 0,                 // Third order polynomial fitting 16 nearest pixels
153     _spline16 = 1,              // Cubic Spline fitting 16 nearest pixels
154     _spline36 = 2,              // Cubic Spline fitting 36 nearest pixels
155     _sinc256 = 3,               // Sinc windowed to 8 pixels
156     _spline64,                  // Cubic Spline fitting 64 nearest pixels
157     _bilinear,                  // Bilinear interpolation
158     _nn,                        // Nearest neighbor
159     _sinc1024,
160     // Thomas Rauscher: New antialiasing filter.
161     // Plots of the functions are available at http://www.pano2qtvr.com/dll_patch/
162     _aabox,                     // Antialiasing: Box
163     _aatriangle,                // Antialiasing: Bartlett/Triangle Filter
164     _aahermite,                 // Antialiasing: Hermite Filter
165     _aahanning,                 // Antialiasing: Hanning Filter
166     _aahamming,                 // Antialiasing: Hamming Filter
167     _aablackman,                // Antialiasing: Blackmann Filter
168     _aagaussian,                // Antialiasing: Gaussian 1/sqrt(2) Filter (blury)
169     _aagaussian2,               // Antialiasing: Gaussian 1/2 Filter (sharper)
170     _aaquadratic,               // Antialiasing: Quadardic Filter
171     _aacubic,                   // Antialiasing: Cubic Filter
172     _aacatrom,                  // Antialiasing: Catmull-Rom Filter
173     _aamitchell,                // Antialiasing: Mitchell Filter
174     _aalanczos2,                // Antialiasing: Lanczos2 Filter
175     _aalanczos3,                // Antialiasing: Lanczos3 Filter
176     _aablackmanbessel,          // Antialiasing: Blackman/Bessel Filter
177     _aablackmansinc             // Antialiasing: Blackman/sinc Filter
178 };
179 
180 // Corrections
181 
182 struct correct_Prefs
183 {                               //  Preferences structure for tool correct
184     uint32_t magic;            //  File validity check, must be 20
185     int radial;                 //  Radial correction requested?
186     double radial_params[3][5]; //  3 colors x (4 coeffic. for 3rd order polys + correction radius)
187     int vertical;               //  Vertical shift requested ?
188     double vertical_params[3];  //  3 colors x vertical shift value
189     int horizontal;             //  horizontal tilt ( in screenpoints)
190     double horizontal_params[3];        //  3 colours x horizontal shift value
191     int shear;                  //  shear correction requested?
192     double shear_x;             //  horizontal shear values
193     double shear_y;             //  vertical shear values
194 
195     int tilt;                  //  tilt correction requested?
196     double tilt_x;             //  tilt on x values
197     double tilt_y;             //  tilt on y values
198     double tilt_z;             //  tilt on z values
199     double tilt_scale;         //  scale for tilting
200 
201     int trans;                  //  translation of camera plane requested?
202     double trans_x;            //  x component of translation vector
203     double trans_y;            //  y component of translation vector
204     double trans_z;             //  z component of translation vector
205     double trans_yaw;          // yaw of remapping plane for translation
206     double trans_pitch;        // pitch of remapping plane for translation
207 
208     int test;                  //  these parameters are for testing new projections
209     double test_p0;            //  and make it easier for others to experiment
210     double test_p1;            //
211     double test_p2;            //
212     double test_p3;            //
213 
214 
215     int resize;                 //  scaling requested ?
216     uint32_t width;             //  new width
217     uint32_t height;            //  new height
218     int luminance;              //  correct luminance variation?
219     double lum_params[3];       //  parameters for luminance corrections
220     int correction_mode;        //  0 - radial correction;1 - vertical correction;2 - deregistration
221     int cutFrame;               //  remove frame? 0 - no; 1 - yes
222     int fwidth;
223     int fheight;
224     int frame;
225     int fourier;                //  Fourier filtering requested?
226     int fourier_mode;           //  _faddBlurr vs _fremoveBlurr
227     fullPath psf;               //  Point Spread Function, full path/fsspec to psd-file
228     int fourier_nf;             //  Noise filtering: _nf_internal vs _nf_custom
229     fullPath nff;               //  noise filtered file: full path/fsspec to psd-file
230     double filterfactor;        //  Hunt factor
231     double fourier_frame;       //  To correct edge errors
232 };
233 
234 typedef struct correct_Prefs cPrefs;
235 
236 enum
237 {
238     correction_mode_radial = 0,
239     correction_mode_vertical = 1,
240     correction_mode_deregister = 2,
241     correction_mode_morph = 4
242 };
243 
244 
245 enum
246 {
247     _faddBlurr,
248     _fremoveBlurr,
249     _nf_internal,
250     _nf_custom,
251     _fresize,
252     _flogtransform
253 };
254 
255 
256 enum
257 {                               // Enumerates for Image.format
258     _rectilinear = 0,           // (Standand) FOV (rectilinear) =  2 * arctan (frame size/(focal length * 2))
259     _panorama = 1,              // Cylindrical
260     _fisheye_circ = 2,          // fisheye-equidistance Circular
261     _fisheye_ff = 3,            // fisheye-equidistance Full Frame
262     _equirectangular = 4,
263     _spherical_cp = 5,          // Fisheye-Horizontal is an image shot with the camera held horizontally. The equator is now in the center of the image.
264     _spherical_tp = 6,          // Fisheye-vertical is an image shot with the camera held vertically up.  The panorama is extracted from the circumpherence of the image.
265     _mirror = 7,                // convex mirror. This is the reflection of a convex, spherical image. The horizontal field of view is calculated using the formula HFov = 2*arcsin(radius of mirror/radius of curvature of mirror)
266     _orthographic = 8,          // fisheye-orthographic FOV  (orthogonal fisheye) = 2 * arcsin (frame size/(focal length *2)
267     _cubic = 9,
268     _stereographic = 10,        // fisheye stereographic FOV (stereographic fisheye) = 4 * arctan (frame size/(focal length * 4))
269     _mercator = 11,
270     _trans_mercator = 12,
271     _trans_panorama = 13,
272     _sinusoidal = 14,
273     _lambert    = 15,
274     _lambertazimuthal  = 16,
275     _albersequalareaconic = 17,
276     _millercylindrical = 18,
277     _panini = 19,
278     _architectural = 20,
279     _equisolid   = 21,          // fisheye-equisolid  FOV (equisolid fisheye) = 4 * arcsin (frame size/(focal length * 4))
280     _equipanini = 22,
281     _biplane = 23,
282    _triplane = 24,
283     _panini_general = 25,
284     _thoby   = 26,             // generalizes the model found in modern fisheye lenses. It is
285                                // parametrizable but it defaults to the Nikkor 10.5 fisheye lens
286     _hammer = 27,
287 };
288 
289 enum
290 {                               // Enumerates external number of panorama f<index>
291     PANO_FORMAT_RECTILINEAR = 0,
292     PANO_FORMAT_PANORAMA = 1,
293     PANO_FORMAT_EQUIRECTANGULAR = 2,
294     PANO_FORMAT_FISHEYE_FF = 3,
295     PANO_FORMAT_STEREOGRAPHIC = 4,
296     PANO_FORMAT_MERCATOR = 5,
297     PANO_FORMAT_TRANS_MERCATOR = 6,
298     PANO_FORMAT_SINUSOIDAL = 7,
299     PANO_FORMAT_LAMBERT_EQUAL_AREA_CONIC = 8,
300     PANO_FORMAT_LAMBERT_AZIMUTHAL = 9,
301     PANO_FORMAT_ALBERS_EQUAL_AREA_CONIC = 10,
302     PANO_FORMAT_MILLER_CYLINDRICAL = 11,
303     PANO_FORMAT_PANINI = 12,
304     PANO_FORMAT_ARCHITECTURAL = 13,
305     PANO_FORMAT_ORTHOGRAPHIC = 14,
306     PANO_FORMAT_EQUISOLID = 15,
307     PANO_FORMAT_EQUI_PANINI = 16,
308     PANO_FORMAT_BIPLANE = 17,
309     PANO_FORMAT_TRIPLANE = 18,
310     PANO_FORMAT_PANINI_GENERAL = 19,
311     PANO_FORMAT_THOBY   = 20,
312     PANO_FORMAT_HAMMER  = 21,
313 };
314 
315 #define PANO_FORMAT_COUNT 22
316 
317 enum
318 {                               // Enumerates external number of image f<index>
319     IMAGE_FORMAT_RECTILINEAR = 0,
320     IMAGE_FORMAT_PANORAMA = 1,
321     IMAGE_FORMAT_FISHEYE_EQUIDISTANCECIRC = 2,
322     IMAGE_FORMAT_FISHEYE_EQUIDISTANCEFF = 3,
323     IMAGE_FORMAT_EQUIRECTANGULAR = 4,
324     IMAGE_FORMAT_MIRROR = 7,
325     IMAGE_FORMAT_FISHEYE_ORTHOGRAPHIC = 8,
326     IMAGE_FORMAT_FISHEYE_STEREOGRAPHIC = 10,
327     IMAGE_FORMAT_FISHEYE_EQUISOLID = 21,
328     IMAGE_FORMAT_FISHEYE_THOBY = PANO_FORMAT_THOBY,
329 };
330 #define IMAGE_FORMAT_COUNT 10
331 
332 // A large rectangle
333 
334 typedef struct
335 {
336     int32_t top;
337     int32_t bottom;
338     int32_t left;
339     int32_t right;
340 } PTRect;
341 
342 typedef struct
343 {
344     uint32_t full_width;
345     uint32_t full_height;
346     uint32_t cropped_width;
347     uint32_t cropped_height;
348     uint32_t x_offset;
349     uint32_t y_offset;
350 } CropInfo;
351 
352 typedef struct
353 {
354     uint32_t fullWidth;
355     uint32_t fullHeight;
356     uint32_t croppedWidth;
357     uint32_t croppedHeight;
358     uint32_t xOffset;
359     uint32_t yOffset;
360 } pano_CropInfo;
361 
362 typedef struct
363 {
364     uint16_t type;
365     uint16_t predictor;
366 } pano_TiffCompression;
367 
368 typedef struct
369 {
370     uint32_t size;
371     char *data;
372 } pano_ICCProfile;
373 
374 typedef struct
375 {
376     // Full size of image
377     uint32_t imageWidth;
378     uint32_t imageHeight;
379 
380     int isCropped;
381 
382     float xPixelsPerResolution;
383     float yPixelsPerResolution;
384     uint16_t resolutionUnits;
385 
386 
387     uint16_t samplesPerPixel;
388     uint16_t bitsPerSample;
389     int bytesPerLine;           // Equal to the scanlinesize
390 
391     uint32_t rowsPerStrip;
392 
393     pano_TiffCompression compression;
394 
395     pano_ICCProfile iccProfile;
396     pano_CropInfo cropInfo;
397 
398     // other metadata
399     char *copyright;
400     char *datetime;
401     char *imageDescription;
402     char *artist;
403     uint16_t imageNumber;        // saved in the page number TIFF field
404     uint16_t imageTotalNumber;   // total number of images
405 
406     // These fields are computed
407     int bytesPerPixel;          // This is a common value to use
408     int bitsPerPixel;           // This is a common value to use
409 } pano_ImageMetadata;
410 
411 // THe following constants define the number of parameters used by a projection
412 
413 // THe first is the number provided by the user. In most cases it is
414 // zero, sometimes 1 and sometimes 2.
415 // The second is the number of internally used parameters. THis is
416 // used for optimization purposes, as some projections require to compute
417 // the same value over and over again.
418 
419 
420 // This are the maximum number of parameters accepted by a given projection
421 #define PANO_PROJECTION_MAX_PARMS 6
422 // This are the maximum number of internal parameters used by a given projection
423 #define PANO_PROJECTION_PRECOMPUTED_VALUES 10
424 
425 
426 struct Image
427 {
428     // Pixel data
429     uint32_t width;
430     uint32_t height;
431     uint32_t bytesPerLine;
432     uint32_t bitsPerPixel;      // Must be 24 or 32
433     size_t dataSize;
434     unsigned char **data;
435     int32_t dataformat;        // rgb, Lab etc
436     int32_t format;            // Projection: rectilinear etc
437     int formatParamCount;       // Number of format parameters.
438     double formatParam[PANO_PROJECTION_MAX_PARMS];  // Parameters for format.
439     int precomputedCount;   // number of values precomputed for a given pano
440     double precomputedValue[PANO_PROJECTION_PRECOMPUTED_VALUES]; // to speed up pano creation
441     double hfov;
442     double yaw;
443     double pitch;
444     double roll;
445     cPrefs cP;                  // How to correct the image
446     char name[MAX_PATH_LENGTH];
447     PTRect selection;
448     CropInfo cropInformation; // TO BE DEPRECATED
449 
450     pano_ImageMetadata metadata;
451 };
452 
453 typedef struct Image Image;
454 
455 
456 
457 struct TrformStr                // This structure holds all image information
458 {
459     Image          *src;        // Source image, must be supplied on entry
460     Image          *dest;       // Destination image data, valid if success = 1
461     int32_t        success;    // 0 - no, 1 - yes
462 
463 
464     int32_t        tool;       // Panorama Tool requested
465     int32_t        mode;       // how to run transformation
466     void           *data;       // data for tool requested.
467     // Required only if mode = _usedata; then it
468     // must point to valid preferences structure
469     // for requested tool (see filter.h).
470 
471     int32_t        interpolator;// Select interpolator
472     double          gamma;      // Gamma value for internal gamma correction
473     int             fastStep;   // 0 no fast Transformation (default), FAST_TRANSFORM_STEP_MORPH, FAST_TRANSFORM_STEP_NORMAL
474 };
475 
476 typedef struct TrformStr TrformStr;
477 
478 
479 // Useful for looping through images
480 
481 #define LOOP_IMAGE( image, action ) { 	int x,y,bpp=(image)->bitsPerPixel/8; \
482 					unsigned char *idata;										\
483 					for(y=0; y<(image)->height; y++){							\
484 						idata = *((image)->data) + y * (image)->bytesPerLine;	\
485 						for(x=0; x<(image)->width;x++, idata+=bpp){				\
486 							action;} } }
487 
488 
489 // These structs are to be used to query the features of the different projection formats
490 
491 typedef struct
492 {
493     double minValue;  // used only if float
494     double maxValue;
495 	double defValue;	// default
496     char *name; // name of the parameter (for the purpose of legibility)
497 } pano_projection_parameter;
498 
499 
500 
501 typedef struct
502 {
503     int projection;
504     int internalFormat; // internal id for Image.format
505     double maxVFOV; // units in degrees
506     double maxHFOV;
507     char *name;
508     int numberOfParameters;
509     //  so far we dont have more than 3 parameters
510     pano_projection_parameter parm[PANO_PROJECTION_MAX_PARMS];
511 } pano_projection_features;
512 
513 PANO13_IMPEX int panoProjectionFeaturesQuery(int projection, pano_projection_features *features);
514 PANO13_IMPEX int panoProjectionFormatCount(void);
515 /** APIs to read dynamic features that depend on projection parameters
516     projection argument is an index, same as for queryFeatures()
517 **/
518 PANO13_IMPEX int queryFOVLimits( int projection,
519 				    double * params, /* length depends on projection */
520 					double * lims	/* [0] = maxhfov, [1] = maxvfov */
521 				  );
522 
523 //void filter_main();
524 
525 #include "PTcommon.h"
526 
527 #endif // PANORAMA_H
528