Imported PTViewer 0.4 as received from <http://www.all-in-one.ee/~dersch/>.
[libopano.git] / src / panorama.h
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 program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17
18 /*------------------------------------------------------------*/
19
20
21
22 #ifndef PANORAMA_H
23 #define PANORAMA_H
24
25
26 #include "version.h"
27
28
29 // Determine which machine we are using. Macs are set to BIGENDIAN, all others not
30
31 // If you need BIGENDIAN, and don't use MacOS, define it here:
32 // #define BIGENDIAN                    1
33
34
35 // Create a definition if we're on a Windows machine:
36 #ifndef __Win__
37         #if (defined(MSDOS) || defined(WIN32) || defined(__INTEL__))
38                 #define __Win__                 1
39         #endif
40 #endif
41
42
43 // Create a definition if we're on a Macintosh:
44 #ifndef __Mac__
45         #if (defined(macintosh) || defined(__MC68K__) || defined(__POWERPC__) || defined(__powerc))
46                 #define __Mac__                 1
47                 #define BIGENDIAN               1
48         #endif
49 #endif
50
51
52
53 // Use FSSpec on Macs as Path-specifyers, else strings
54 #define PATH_SEP                                                        '/'
55
56 #ifdef __Mac__
57
58         #include <Files.h>
59         #define                 fullPath                                                        FSSpec
60         #undef  PATH_SEP
61         #define PATH_SEP                                                                        ':'
62
63 #else // __Mac__, use ANSI-filefunctions
64
65         #ifdef __Win__
66                 // #include <windows.h>; including this causes problems with libjpeg
67                 #define MAX_PATH_LENGTH         260
68                 // was MAX_PATH
69                 #undef  PATH_SEP
70                 #define PATH_SEP                                                        '\\'
71         #else
72                 #define MAX_PATH_LENGTH         512
73         #endif
74
75         typedef struct{char name[MAX_PATH_LENGTH];} fullPath;
76
77 #endif
78
79
80
81
82
83 // Enumerates for TrFormStr.tool
84
85 enum{                                                   // Panorama Tools
86                 _perspective,                                   
87                 _correct,
88                 _remap,
89                 _adjust,
90                 _interpolate,
91                 _sizep,                                 // dummy for size-preferences
92                 _version,                               // dummy for version
93                 _panright,                              // Pan Controls
94                 _panleft,
95                 _panup,
96                 _pandown,
97                 _zoomin,
98                 _zoomout,
99                 _apply,
100                 _getPano,
101                 _increment
102         };
103
104 // Enumerates for TrFormStr.mode
105
106 enum{                                                   // Modes
107                 _interactive,                   // display dialogs and do Xform
108                 _useprefs,                              // load saved prefs and do Xform/ no dialogs
109                 _setprefs,                              // display dialogs and set preferences, no Xform        
110                 _usedata,                               // use supplied data in TrFormStr.data, do Xform
111                 _honor_valid    = 8,    // Use only pixels with alpha channel set
112                 _show_progress  = 16,   // Interpolator displays progress bar
113                 _hostCanResize  = 32,   // o-no; 1-yes (Photoshop: no; GraphicConverter: yes)
114                 _destSupplied   = 64,   // Destination image allocated by plug-in host
115                 _wrapX                  =128    // Wrap image horizontally (if HFOV==360 degrees)
116         };
117                 
118
119 // Enumerates for Image.dataformat
120
121 enum{                                                   
122                 _RGB,                                   
123                 _Lab,
124                 _Grey
125         };
126
127 // Enumerates for TrFormStr.interpolator
128
129 enum{                                                   // Interpolators
130                 _poly3          = 0,            // Third order polynomial fitting 16 nearest pixels
131                 _spline16       = 1,            // Cubic Spline fitting 16 nearest pixels
132                 _spline36       = 2,            // Cubic Spline fitting 36 nearest pixels
133                 _sinc256        = 3,            // Sinc windowed to 8 pixels
134                 _spline64,                              // Cubic Spline fitting 64 nearest pixels
135                 _bilinear,                              // Bilinear interpolation
136                 _nn     ,                                       // Nearest neighbor
137                 _sinc1024
138         };
139
140 // Corrections
141
142 struct  correct_Prefs{                                                  //  Preferences structure for tool correct
143                 unsigned long   magic;                                  //  File validity check, must be 20
144                 int                     radial;                                 //  Radial correction requested?
145                 double                  radial_params[3][5];    //  3 colors x (4 coeffic. for 3rd order polys + correction radius)
146                 int                     vertical;                               //  Vertical shift requested ?
147                 double                  vertical_params[3];             //  3 colors x vertical shift value
148                 int                             horizontal;                             //  horizontal tilt ( in screenpoints)
149                 double                  horizontal_params[3];   //  3 colours x horizontal shift value
150                 int                             shear;                                  //  shear correction requested?
151                 double                  shear_x;                                //  horizontal shear values
152                 double                  shear_y;                                //  vertical shear values
153                 int                     resize;                                 //  scaling requested ?
154                 long                    width;                                  //  new width
155                 long                    height;                                 //  new height
156                 int                             luminance;                              //  correct luminance variation?
157                 double                  lum_params[3];                  //  parameters for luminance corrections
158                 int                             correction_mode;                //  0 - radial correction;1 - vertical correction;2 - deregistration
159                 int                             cutFrame;                               //  remove frame? 0 - no; 1 - yes
160                 int                         fwidth;
161                 int                     fheight;
162                 int                             frame;
163                 int                             fourier;                                //  Fourier filtering requested?
164                 int                             fourier_mode;                   //  _faddBlurr vs _fremoveBlurr
165                 fullPath                psf;                                    //  Point Spread Function, full path/fsspec to psd-file
166                 int                             fourier_nf;                             //  Noise filtering: _nf_internal vs _nf_custom
167                 fullPath                nff;                                    //  noise filtered file: full path/fsspec to psd-file
168                 double                  filterfactor;                   //  Hunt factor
169                 double                  fourier_frame;                  //  To correct edge errors
170                 } ;
171
172 typedef struct correct_Prefs cPrefs;
173
174 enum{
175         correction_mode_radial          = 0,
176         correction_mode_vertical        = 1,
177         correction_mode_deregister      = 2,
178         correction_mode_morph           = 4
179         };
180         
181
182 enum{
183         _faddBlurr,
184         _fremoveBlurr,
185         _nf_internal,
186         _nf_custom,
187         _fresize
188         };
189         
190
191 enum{                           // Enumerates for Image.format
192         _rectilinear    = 0,
193         _panorama               = 1,
194         _fisheye_circ   = 2,
195         _fisheye_ff             = 3,
196         _equirectangular= 4,
197         _spherical_cp   = 5,
198         _spherical_tp   = 6,
199         _mirror                 = 7,
200         _orthographic   = 8
201         };
202
203
204
205 struct Image
206         {
207                 // Pixel data
208                 long                    width;
209                 long                    height;
210                 long                    bytesPerLine;
211                 long                    bitsPerPixel;   // Must be 24 or 32
212                 long                    dataSize; 
213                 unsigned char** data;
214                 long                    dataformat;             // rgb, Lab etc
215                 long                    format;                 // Projection: rectilinear etc
216                 double                  hfov;
217                 double                  yaw;
218                 double                  pitch;
219                 double                  roll;
220                 cPrefs                  cP;                             // How to correct the image
221                 char                    name[256];
222         };
223                 
224 typedef struct Image Image;
225
226
227 struct TrformStr                                // This structure holds all image information
228         {
229                 Image *src;                             // Source image, must be supplied on entry
230                 Image *dest;                    // Destination image data, valid if success = 1 
231                 long success;                   // 0 - no, 1 - yes 
232
233
234                 long tool;                              // Panorama Tool requested
235                 long mode;                              // how to run transformation
236                 void *data;                             // data for tool requested.
237                                                                 // Required only if mode = _usedata; then it
238                                                                 // must point to valid preferences structure
239                                                                 // for requested tool (see filter.h).
240
241                 long interpolator;              // Select interpolator
242                 double gamma;                   // Gamma value for internal gamma correction
243         };
244
245 typedef struct TrformStr TrformStr;     
246
247
248 // Useful for looping through images
249
250 #define LOOP_IMAGE( image, action )             {       int x,y,bpp=(image)->bitsPerPixel/8;                                            \
251                                                                                         unsigned char *idata;                                                                           \
252                                                                                         for(y=0; y<(image)->height; y++){                                                       \
253                                                                                                 idata = *((image)->data) + y * (image)->bytesPerLine;   \
254                                                                                                 for(x=0; x<(image)->width;x++, idata+=bpp){                             \
255                                                                                                         action;} } }                                                            
256                                                                                         
257                                                                                         
258                                                                                         
259                                                                                         
260                                                                                         
261
262 void filter_main();
263
264
265 #endif // PANORAMA_H