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

Diff of /src/filter.h [000000] .. [24dce1] Maximize Restore

  Switch to unified view

a b/src/filter.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
#ifndef FILTER_H
21
#define FILTER_H
22
23
24
#include <math.h>
25
#include <stdio.h>
26
#include <stdarg.h>
27
#include <string.h>
28
#include <stdlib.h>
29
#include <ctype.h>
30
#include <limits.h>
31
32
#include "panorama.h"
33
//#include "tiffio.h"
34
35
#ifndef TRUE
36
  #define TRUE 1
37
#endif
38
39
#ifndef FALSE
40
  #define FALSE 0
41
#endif
42
43
44
//---------------------- Types ---------------------------------------------
45
46
#define UCHAR unsigned char
47
#define USHORT  unsigned short
48
#define ULONG   unsigned long
49
50
enum{
51
  _UCHAR,
52
  _USHORT,
53
  _ULONG
54
  };
55
56
//---------------------- Some useful math defines --------------------------
57
58
#ifndef PI
59
  #define PI 3.14159265358979323846
60
#endif
61
62
// Normalize an angle to +/-180degrees
63
64
#define NORM_ANGLE( x )  while( x >180.0 ) x -= 360.0; while( x < -180.0 ) x += 360.0;
65
66
// Convert degree to radian
67
68
#define DEG_TO_RAD( x )       ( (x) * 2.0 * PI / 360.0 )
69
70
// and reverse
71
72
#define RAD_TO_DEG( x )       ( (x) * 360.0 / ( 2.0 * PI ) )
73
74
// Convert double x to unsigned char/short c
75
76
77
78
#define   DBL_TO_UC( c, x )   if(x>255.0) c=255U;                             \
79
                              else if(x<0.0) c=0;                         \
80
                              else c=(unsigned char)floor(x+0.5);
81
82
#define   DBL_TO_US( c, x )   if(x>65535.0) c=65535U;                         \
83
                              else if(x<0.0) c=0;                         \
84
                              else c=(unsigned short)floor(x+0.5);
85
86
87
88
#define MAX_FISHEYE_FOV       160.0
89
90
extern int JavaUI; // Flag to indicate use of java dialogs
91
void JPrintError( char* text );
92
93
94
extern int fastTransformStep;     // defined in resample.c
95
#define FAST_TRANSFORM_STEP_NORMAL    40
96
#define FAST_TRANSFORM_STEP_MORPH 6
97
// FS-
98
99
struct PTPoint
100
{
101
  double x;
102
  double y;
103
};
104
105
typedef struct PTPoint PTPoint;
106
107
#define CopyPTPoint( to, from )       memcpy( &to, &from, sizeof( PTPoint ))
108
#define SamePTPoint( p, s )             ((p).x == (s).x && (p).y == (s).y)
109
110
struct PTLine
111
{
112
  PTPoint v[2];
113
};
114
115
typedef struct PTLine PTLine;
116
117
118
struct PTTriangle
119
{
120
  PTPoint v[3];
121
};
122
123
typedef struct PTTriangle PTTriangle;
124
125
126
127
128
// Maximum number of controlpoints in a pair of images, which can be read
129
// via Barcodes
130
#define NUMPTS 21
131
132
// Randomization of feather in stitching tools
133
#define   BLEND_RANDOMIZE     0.1
134
135
// Randomization of luminance adjustment in correct filter
136
#define LUMINANCE_RANDOMIZE   0.007
137
138
139
//----------------------- Structures -------------------------------------------
140
141
struct remap_Prefs{                               // Preferences Structure for remap
142
      long            magic;                  //  File validity check, must be 30
143
      int             from;                   // Image format source image
144
      int             to;                     // Image format destination image
145
      double          hfov;                   // horizontal field of view /in degrees
146
      double          vfov;                   // vertical field of view (usually ignored)
147
      } ;
148
149
typedef struct remap_Prefs rPrefs;
150
151
struct perspective_Prefs{                     //  Preferences structure for tool perspective
152
      long            magic;                  //  File validity check, must be 40
153
      int             format;                 //  rectilinear or fisheye?
154
      double          hfov;                   //  Horizontal field of view (in degree)
155
      double          x_alpha;                //  New viewing direction (x coordinate or angle)
156
      double          y_beta;                 //  New viewing direction (y coordinate or angle)
157
      double          gamma;                  //  Angle of rotation
158
      int             unit_is_cart;           //  true, if viewing direction is specified in coordinates
159
      int             width;                  //  new width
160
      int             height;                 //  new height
161
      } ;
162
      
163
typedef struct perspective_Prefs pPrefs;
164
165
166
struct optVars{                                   //  Indicate to optimizer which variables to optimize
167
      int hfov;                               //  optimize hfov? 0-no 1-yes , etc
168
      int yaw;                
169
      int pitch;              
170
      int roll;               
171
      int a;
172
      int b;
173
      int c;                  
174
      int d;
175
      int e;
176
      int shear_x;
177
      int shear_y;
178
      };
179
      
180
typedef struct optVars optVars;
181
182
183
enum{                                     // Enumerates for stBuf.seam
184
  _middle,                                // seam is placed in the middle of the overlap
185
  _dest                                   // seam is places at the edge of the image to be inserted
186
  };
187
188
enum{                                     // Enumerates for colcorrect
189
  _colCorrectImage    = 1,
190
  _colCorrectBuffer   = 2,
191
  _colCorrectBoth     = 3,
192
  };
193
194
struct stitchBuffer{                      // Used describe how images should be merged
195
  char                srcName[256];       // Buffer should be merged to image; 0 if not.
196
  char                destName[256];      // Converted image (ie pano) should be saved to buffer; 0 if not
197
  int             feather;        // Width of feather
198
  int             colcorrect;     // Should the images be color corrected?
199
  int             seam;           // Where to put the seam (see above)
200
  };
201
202
typedef struct stitchBuffer stBuf;
203
204
struct panControls{                           // Structure for realtime Panoeditor
205
      double panAngle;                    // The amount by which yaw/pitch are changed per click
206
      double zoomFactor;                  // The percentage for zoom in/out
207
      };
208
      
209
      
210
typedef struct panControls panControls;
211
212
213
214
enum{                                     // Enumerates for aPrefs.mode
215
      _readControlPoints,
216
      _runOptimizer,
217
      _insert,
218
      _extract,
219
      _useScript = 8,                     // else use options
220
  };
221
222
struct adjust_Prefs{      //  Preferences structure for tool adjust
223
      long    magic;  //  File validity check, must be 50
224
      long    mode;   //  What to do: create Panorama etc?
225
      Image   im; //  Image to be inserted/extracted
226
      Image   pano;   //  Panorama to be created/ used for extraction
227
      
228
      stBuf   sBuf;
229
      fullPath scriptFile;    // On Mac: Cast to FSSpec; else: full path to scriptFile
230
      int     nt; // morphing triangles
231
      PTTriangle  *ts; // Source triangles
232
      PTTriangle  *td; // Destination triangles
233
234
      int interpolator;
235
      int fastStep;
236
      double gamma;       
237
};
238
      
239
      
240
typedef struct adjust_Prefs aPrefs;
241
      
242
243
244
union panoPrefs{
245
      cPrefs  cP;
246
      pPrefs  pP;
247
      rPrefs  rP;
248
      aPrefs  aP;
249
      panControls pc;
250
      };
251
      
252
typedef union panoPrefs panoPrefs;
253
254
255
struct size_Prefs{                                // Preferences structure for 'pref' dialog
256
      long            magic;                  //  File validity check; must be 70
257
      int             displayPart;            // Display cropped/framed image ?
258
      int             saveFile;               // Save to tempfile? 0-no, 1-yes
259
      fullPath        sFile;                  // Full path to file (short name)
260
      int             launchApp;              // Open sFile ?
261
      fullPath        lApp;                   // the Application to launch
262
      int             interpolator;           // Which interpolator to use 
263
      int fastStep;
264
      double          gamma;                  // Gamma correction value
265
      int             noAlpha;                // If new file is created: Don't save mask (Photoshop LE)
266
      int             optCreatePano;          // Optimizer creates panos? 0  no/ 1 yes
267
      } ;
268
269
typedef struct size_Prefs sPrefs;
270
      
271
      
272
273
#if 0
274
struct controlPoint{                          // Control Points to adjust images
275
      int  num[2];                            // Indices of Images 
276
      int  x[2];                              // x - Coordinates 
277
      int  y[2];                              // y - Coordinates 
278
      int  type;                              // What to optimize: 0-r, 1-x, 2-y
279
      } ;
280
#endif
281
struct controlPoint{                          // Control Points to adjust images
282
      int  num[2];                            // Indices of Images 
283
      double x[2];                                // x - Coordinates 
284
      double y[2];                                // y - Coordinates 
285
      int  type;                              // What to optimize: 0-r, 1-x, 2-y
286
      } ;
287
288
typedef struct controlPoint controlPoint;
289
290
struct CoordInfo{                             // Real World 3D coordinates
291
      int  num;                               // auxilliary index
292
      double x[3];
293
      int  set[3];
294
      };
295
      
296
typedef struct CoordInfo CoordInfo;
297
298
// Some useful macros for vectors
299
300
#define SCALAR_PRODUCT( v1, v2 )  ( (v1)->x[0]*(v2)->x[0] + (v1)->x[1]*(v2)->x[1] + (v1)->x[2]*(v2)->x[2] ) 
301
#define ABS_SQUARED( v )          SCALAR_PRODUCT( v, v )
302
#define ABS_VECTOR( v )               sqrt( ABS_SQUARED( v ) )
303
#define CROSS_PRODUCT( v1, v2, r )  { (r)->x[0] = (v1)->x[1] * (v2)->x[2] - (v1)->x[2]*(v2)->x[1];  \
304
                                    (r)->x[1] = (v1)->x[2] * (v2)->x[0] - (v1)->x[0]*(v2)->x[2];  \
305
                                    (r)->x[2] = (v1)->x[0] * (v2)->x[1] - (v1)->x[1]*(v2)->x[0]; }
306
#define DIFF_VECTOR( v1, v2, r )      {   (r)->x[0] = (v1)->x[0] - (v2)->x[0];  \
307
                                      (r)->x[1] = (v1)->x[1] - (v2)->x[1];  \
308
                                      (r)->x[2] = (v1)->x[2] - (v2)->x[2]; }
309
#define DIST_VECTOR( v1, v2 )     sqrt( ((v1)->x[0] - (v2)->x[0]) * ((v1)->x[0] - (v2)->x[0]) + \
310
                                        ((v1)->x[1] - (v2)->x[1]) * ((v1)->x[1] - (v2)->x[1]) + \
311
                                        ((v1)->x[2] - (v2)->x[2]) * ((v1)->x[2] - (v2)->x[2]) )
312
313
struct transformCoord{                            // 
314
      int nump;                               // Number of p-coordinates
315
      CoordInfo  *p;                          // Coordinates "as is"
316
      int numr;                               // Number of r-coordinates
317
      CoordInfo  *r;                          // Requested values for coordinates
318
      } ;
319
  
320
typedef struct transformCoord transformCoord;
321
322
struct  tMatrix{
323
      double alpha;
324
      double beta;
325
      double gamma;
326
      double x_shift[3];
327
      double scale;
328
      };
329
      
330
typedef struct tMatrix tMatrix;
331
332
      
333
      
334
  
335
  
336
337
338
struct MakeParams{                                // Actual parameters used by Xform functions for pano-creation
339
  double  scale[2];                           // scaling factors for resize;
340
  double  shear[2];                           // shear values
341
  double  rot[2];                             // horizontal rotation params
342
  void    *perspect[2];                       // Parameters for perspective control functions
343
  double  rad[6];                             // coefficients for polynomial correction (0,...3) and source width/2 (4) and correction radius (5) 
344
  double  mt[3][3];                           // Matrix
345
  double  distance;
346
  double  horizontal;
347
  double  vertical;
348
  };
349
350
struct LMStruct{                              // Parameters used by the Levenberg Marquardt-Solver
351
  int         m;                              
352
  int         n;
353
  double      *x;
354
  double      *fvec;
355
  double      ftol;
356
  double      xtol;
357
  double      gtol;
358
  int         maxfev; 
359
  double      epsfcn;
360
  double      *diag;
361
  int         mode;   
362
  double      factor;
363
  int         nprint;
364
  int         info;
365
  int         nfev;
366
  double      *fjac;
367
  int         ldfjac;
368
  int         *ipvt;
369
  double      *qtf;
370
  double      *wa1;
371
  double      *wa2;
372
  double      *wa3;
373
  double      *wa4;
374
  };
375
376
// function to minimize in Levenberg-Marquardt solver
377
378
typedef       int (*lmfunc)();    
379
380
struct triangle
381
{
382
  int vert[3];    // Three vertices from list
383
  int nIm;        // number of image for texture mapping
384
};
385
386
typedef struct triangle triangle;
387
388
389
390
391
struct AlignInfo{                         // Global data structure used by alignment optimization
392
  Image               *im;                // Array of Pointers to Image Structs
393
  optVars             *opt;               // Mark variables to optimize
394
  int             numIm;              // Number of images 
395
  controlPoint            *cpt;               // List of Control points
396
  triangle            *t;             // List of triangular faces
397
  int             nt;             // Number of triangular faces
398
  int                 numPts;             // Number of Control Points
399
  int             numParam;           // Number of parameters to optimize
400
  Image               pano;               // Panoramic Image decription
401
  stBuf               st;             // Info on how to stitch the panorama
402
  void                *data;
403
  lmfunc              fcn;
404
  sPrefs              sP; 
405
  CoordInfo           *cim;               // Real World coordinates
406
  };  
407
408
typedef struct AlignInfo AlignInfo;
409
410
struct OptInfo{
411
  int numVars;                // Number of variables to fit
412
  int numData;                // Number of data to fit to
413
  int (*SetVarsToX)(double *x);       // Translate variables to x-values
414
  int (*SetXToVars)(double *x);       // and reverse
415
  lmfunc fcn;             // Levenberg Marquardt function measuring quality
416
  char message[256];          // info returned by LM-optimizer
417
};
418
  
419
typedef struct OptInfo OptInfo;
420
421
422
423
struct VRPanoOptions{
424
  int     width;
425
  int     height;
426
  double      pan;
427
  double      tilt;
428
  double      fov;
429
  int         codec;
430
  int         cquality;
431
  int         progressive;
432
};
433
434
typedef struct VRPanoOptions VRPanoOptions;
435
436
437
struct MultiLayerImage{
438
  int numLayers;
439
  Image   *Layer;
440
  PTRect  selection;
441
};
442
443
typedef struct MultiLayerImage MultiLayerImage;
444
445
446
  
447
  
448
449
450
// Transformation function type (we have only one...)
451
452
typedef       void (*trfn)( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );
453
454
455
// Function descriptor to be executed by exec_function
456
struct fDesc {
457
  trfn    func;           // The function to be called
458
  void    *param;         // The parameters to be used
459
  };      
460
461
typedef struct fDesc fDesc;
462
463
#define SetDesc(fD,f,p)       fD.func = f; fD.param = p
464
465
// Panorama tool type
466
467
typedef       void (*fnPtr)(TrformStr *TrPtr);
468
469
470
// Filter function type
471
472
typedef unsigned char (*flfn)( unsigned char srcPixel, int xc, int yc, void *params );
473
typedef unsigned short (*flfn16)( unsigned short srcPixel, int xc, int yc, void *params );
474
475
476
// Interpolating functions for resampler
477
478
typedef       void (*intFunc)( unsigned char *dst,    unsigned char **rgb,
479
                          register double Dx, 
480
                          register double Dy,
481
                          int color, int SamplesPerPixel);
482
483
484
485
486
487
// Gamma Correction
488
489
struct PTGamma{
490
  double *DeGamma;
491
  unsigned short *Gamma;
492
  int     ChannelSize;
493
  int     ChannelStretch;
494
  int     GammaSize;
495
  };
496
497
typedef struct PTGamma PTGamma;
498
499
extern PTGamma glu;
500
501
502
// Some macros to find out more about images
503
504
#define GetBitsPerChannel( im, x )        switch( (im)->bitsPerPixel )    \
505
                                  {                                   \
506
                                      case 24:    x =  8; break;      \
507
                                      case 32:    x =  8; break;      \
508
                                      case 48:    x = 16; break;      \
509
                                      case 64:    x = 16; break;      \
510
                                      default:    x =  8; break;      \
511
                                  }                                               
512
513
#define GetChannels( im, x )      switch( (im)->bitsPerPixel )        \
514
                                  {                                   \
515
                                      case 24:    x =  3; break;      \
516
                                      case 32:    x =  4; break;      \
517
                                      case 48:    x =  3; break;      \
518
                                      case 64:    x =  4; break;      \
519
                                      default:    x =  3; break;      \
520
                                  }                                               
521
522
                                  
523
524
//---------------------------------- Functions identical in all platforms ------------------------
525
526
527
void  dispatch    (TrformStr *TrPtr, sPrefs *s);     // Entry into platform independent code
528
void  DoTransForm (TrformStr *TrPtr, panoPrefs *p );
529
530
void setLibToResFile  ( void );           // MacOS: Get resources from shared lib
531
void unsetLibToResFile( void );           // MacOS: Don't get resources from shared lib
532
533
enum{                 // Enumerates used by Progress and infoDlg
534
  _initProgress,      // display message "argument"
535
  _setProgress,       // display progress (argument is percentage converted to string)
536
  _disposeProgress,   // dispose progress indicator
537
  _idleProgress       // do nothing; on Mac: call waitnextevent;
538
  };
539
540
int   Progress( int command, char* argument );    // Progress Reporting 
541
int   infoDlg ( int command, char* argument );    // Display info: same argumenmts as progress
542
void      PrintError( char* fmt, ...);                // Error Reporting
543
544
int   ccommand( char ***argvPtr);                 // Shell for standalone programs
545
546
547
//  Panorama Tool functions
548
549
550
void  perspective (TrformStr *TrPtr, pPrefs *p);  
551
void  correct     (TrformStr *TrPtr, cPrefs *c);  
552
void  remap       (TrformStr *TrPtr, rPrefs *r); 
553
void  adjust      (TrformStr *TrPtr, aPrefs *a); 
554
void  pan         (TrformStr *TrPtr, panControls *pc);
555
556
557
558
559
// Set Struct defaults
560
561
void    SetPrefDefaults           (panoPrefs *prPtr,  int selector);
562
void  SetCorrectDefaults      ( cPrefs *p );
563
void  SetAdjustDefaults       ( aPrefs *p );
564
void  SetRemapDefaults        ( rPrefs *p );
565
void  SetPerspectiveDefaults  ( pPrefs *p );
566
void  SetImageDefaults        ( Image *im);
567
void  SetOptDefaults          ( optVars *opt );
568
void  SetPanDefaults          ( panControls *pc);
569
void  SetSizeDefaults         ( sPrefs *pref);
570
void  SetStitchDefaults       ( stBuf *sbuf);
571
void  SetVRPanoOptionsDefaults( VRPanoOptions *v);
572
void  SettMatrixDefaults      ( tMatrix *t );
573
void  SetCoordDefaults        ( CoordInfo *c, int num);
574
575
int       SetAlignParams          ( double *x );
576
int   SetLMParams             ( double *x );
577
void  SetGlobalPtr            ( AlignInfo *p );
578
579
580
581
// Dialogs
582
int   SetPrefs        ( panoPrefs *p );
583
int   SetPanPrefs     ( panControls *p );
584
int   SetCorrectPrefs     ( cPrefs *p );
585
int   SetRadialOptions    ( cPrefs *p );
586
int   SetHorizontalOptions    ( cPrefs *p );
587
int   SetVerticalOptions  ( cPrefs *p );
588
int   SetShearOptions     ( cPrefs *p );
589
int   SetScaleOptions     ( cPrefs *p );
590
int   SetLumOptions       ( cPrefs *p );
591
int   setSizePrefs        ( sPrefs *p, int can_resize );
592
int   SetRemapPrefs       ( rPrefs *p );
593
int   SetPerspectivePrefs ( pPrefs *p );
594
int   SetAdjustPrefs      ( aPrefs *p );
595
int   SetInterpolator     ( sPrefs *p );
596
int   SetCreateOptions    ( aPrefs *p );
597
int   SetCutOptions       ( cPrefs *p );
598
int   SetFourierOptions   ( cPrefs *p );
599
600
601
602
// File I/O
603
604
int   readPrefs           (char* p, int selector );               // Preferences, same selector as dispatch
605
void  writePrefs          (char* p, int selector );               // Preferences, same selector as dispatch
606
607
int   LoadBufImage        ( Image *image, char *fname, int mode);
608
int   SaveBufImage        ( Image *image, char *fname );
609
int   writeTIFF           ( Image *im, fullPath* fname);          // On Mac: fname is FSSpec*             
610
void  SaveOptions         ( struct correct_Prefs * thePrefs );
611
int   LoadOptions         ( struct correct_Prefs * thePrefs );
612
void      FindScript          ( struct adjust_Prefs *thePrefs );
613
char*     LoadScript          ( fullPath* scriptFile  );
614
int   WriteScript         ( char* res, fullPath* scriptFile, int launch );
615
int   writePSD            ( Image *im, fullPath* fname);          // On Mac: fname is FSSpec* 
616
int   readPSD             ( Image *im, fullPath* fname, int mode);
617
int   FindFile            ( fullPath *fname );
618
int   SaveFileAs          ( fullPath *fname, char *prompt, char *name );
619
void  ConvFileName        ( fullPath *fname,char *string);
620
int   writePSDwithLayer   ( Image *im, fullPath *fname);
621
int   addLayerToFile      ( Image *im, fullPath* sfile, fullPath* dfile, stBuf *sB);
622
void  showScript          ( fullPath* scriptFile );
623
void  MakeTempName        ( fullPath *fspec, char *fname );
624
void  makePathForResult   ( fullPath *path );
625
int   makePathToHost      ( fullPath *path );
626
void    open_selection        ( fullPath *path );
627
int   readPSDMultiLayerImage( MultiLayerImage *mim, fullPath* sfile);
628
int   GetFullPath         (fullPath *path, char *filename); // Somewhat confusing, for compatibility easons
629
int   StringtoFullPath    (fullPath *path, char *filename);
630
int   IsTextFile          ( char* fname );
631
int   readPositions       ( char* script, transformCoord *tP );
632
int   readImage           ( Image *im, fullPath *sfile );
633
int   readJPEG            ( Image *im, fullPath *sfile );
634
int   readTIFF            ( Image *im, fullPath *sfile );
635
int   writeImage          ( Image *im, fullPath *sfile );
636
int   writeJPEG           ( Image *im, fullPath *sfile,   int quality, int progressive );
637
int   makeTempPath        ( fullPath *path );
638
int   writePNG            ( Image *im, fullPath *sfile );
639
int   readPNG             ( Image *im, fullPath *sfile );
640
int   LaunchAndSendScript(char* application, char* script);
641
aPrefs* readAdjustLine( fullPath *theScript );
642
//int readtif(Image *im, TIFF* tif);
643
644
#define FullPathtoString( path, string )      GetFullPath( path, string)
645
646
647
int       ReadMorphPoints( char *script, AlignInfo *gl, int nIm );
648
649
// Image manipulation
650
651
void  addAlpha            ( Image *im ); 
652
void  transForm           ( TrformStr *TrPtr, fDesc *fD, int color);
653
void    filter                ( TrformStr *TrPtr, flfn func, flfn16 func16, void* params, int color);     
654
void  CopyImageData       ( Image *dest, Image *src );
655
void  laplace             ( Image *im );
656
void  blurr               ( Image *im );
657
void  MakePano            ( TrformStr *TrPtr, aPrefs *aP);
658
void  ExtractStill        ( TrformStr *TrPtr , aPrefs *p );
659
int   HaveEqualSize       ( Image *im1, Image *im2 );
660
int   merge               ( Image *dst, Image *src, int feather, int showprogress, int seam );
661
void  mergeAlpha          ( Image *im, unsigned char *alpha, int feather, PTRect *theRect );
662
void  SetEquColor         ( cPrefs *p );
663
void  CopyPosition        ( Image *to, Image *from );
664
int   isColorSpecific     ( cPrefs *p );
665
void  ThreeToFourBPP      ( Image *im );
666
void  FourToThreeBPP      ( Image *im );
667
int   SetUpGamma          ( double pgamma, int psize);
668
int   cutTheFrame         ( Image *dest, Image *src, int width, int height, int showprogress );
669
int   PositionCmp         ( Image *im1, Image *im2 );
670
int   MorphImage          ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
671
int   MorphImageFile      ( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
672
int   blendImages         ( fullPath *f0,  fullPath *f1, fullPath *result, double s );
673
int   InterpolateImage    ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
674
int   InterpolateTrianglesPerspective( AlignInfo *g, int nIm, double s, PTTriangle** t  );
675
int   InterpolateImageFile( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
676
void  OneToTwoByte        ( Image *im );
677
void  TwoToOneByte        ( Image *im );
678
void  SetMakeParams       ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
679
void  SetInvMakeParams    ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
680
void  GetControlPointCoordinates(int i, double *x, double *y, AlignInfo *gl );
681
void  ARGBtoRGBA(UCHAR* buf, int width, int bitsPerPixel);
682
void  RGBAtoARGB(UCHAR* buf, int width, int bitsPerPixel);
683
int   CropImage(Image *im, PTRect *r);
684
void  DoColorCorrection( Image *im1, Image *im2, int mode );
685
686
// Script Reading/Parsing/Writing
687
688
int   ParseScript         ( char* script, AlignInfo *gl );
689
void  WriteResults        ( char* script, fullPath *sfile, AlignInfo *g, double ds( int i) , int launch);
690
int   readAdjust      ( aPrefs *p,  fullPath* sfile, int insert, sPrefs *sP );
691
void  readControlPoints   (char* script, controlPoint *c );
692
int   getVRPanoOptions    ( VRPanoOptions *v, char *line );
693
void  nextWord            ( register char* word, char** ch );
694
void  nextLine            ( register char* line, char** ch );
695
int   numLines            ( char* script, char first );
696
697
// Memory
698
699
void  DisposeAlignInfo    ( AlignInfo *g );
700
void**  mymalloc          ( long numBytes );                  // Memory allocation, use Handles
701
void  myfree              ( void** Hdl );                     // free Memory, use Handles
702
int   SetDestImage        ( TrformStr *TrPtr, int width, int height) ;
703
void  DisposeMultiLayerImage( MultiLayerImage *mim );
704
705
706
// Math
707
708
void  RunLMOptimizer      ( OptInfo   *g);
709
void  RunBROptimizer      ( OptInfo   *g, double minStepWidth);
710
void  RunOverlapOptimizer ( AlignInfo *g);
711
712
void  SetMatrix           ( double a, double b, double c , double m[3][3], int cl );
713
void  matrix_mult         ( double m[3][3], double vector[3] );
714
void  matrix_inv_mult     ( double m[3][3], double vector[3] );
715
double    smallestRoot        ( double *p );
716
void  SetCorrectionRadius ( cPrefs *cP );
717
int       lmdif               ();
718
void  fourier             ( TrformStr *TrPtr, cPrefs *cP );
719
unsigned short    gamma_correct( double pix );
720
int   EqualCPrefs( cPrefs *c1, cPrefs *c2 );
721
double    OverlapRMS          ( MultiLayerImage *mim );
722
double    distSquared         ( int num ); 
723
int       fcnPano();
724
int       EvaluateControlPointError ( int num, double *errptr, double errComponent[2]);
725
void  doCoordinateTransform( CoordInfo *c, tMatrix *t );
726
void  findOptimumtMatrix( transformCoord *tP, tMatrix *tM, lmfunc f);
727
int   SolveLinearEquation2( double a[2][2], double b[2], double x[2] );
728
void  SortControlPoints( AlignInfo *g , int nIm);
729
void  noisefilter         ( Image *dest, Image *src );    
730
void  fwiener             ( TrformStr *TrPtr, Image *nf, Image *psf, double gamma, double frame );
731
732
733
// Triangulation
734
int   PointInTriangle( double x, double y, PTTriangle *T, double c[2] );
735
int   SetSourceTriangles( AlignInfo *g, int nIm, PTTriangle** t  );
736
int   SetDestTriangles( AlignInfo *g, int nIm, PTTriangle** t  );
737
int   InterpolateTriangles( AlignInfo *g, int nIm, double s, PTTriangle** t  );
738
int   DelaunayIteration( AlignInfo *g, int nIm );
739
int   PointInCircumcircle( double x, double y, PTTriangle *tC );
740
int   TriangulatePoints( AlignInfo *g, int nIm );
741
int   AddTriangle( triangle *t, AlignInfo *g );
742
int   RemoveTriangle( int nt, AlignInfo *g );
743
void  OrderVerticesInTriangle( int nt, AlignInfo *g );
744
void  SetTriangleCoordinates( triangle *t, PTTriangle *tC, AlignInfo *g );
745
int   TrianglesOverlap( PTTriangle *t0, PTTriangle *t1 );
746
int   LinesIntersect( PTLine *s0, PTLine *s1) ; 
747
double    PTDistance( PTPoint *s0, PTPoint *s1 );
748
int   PTPointInRectangle(  PTPoint *p, PTLine *r );
749
int   PTElementOf(  double x, double a, double b );
750
int   PTNormal( double *a, double *b, double *c, PTLine *s );
751
int   PTGetLineCrossing( PTLine *s0, PTLine *s1, PTPoint *ps );
752
int   ReduceTriangles( AlignInfo *g, int nIm );
753
double    PTAreaOfTriangle( PTTriangle *t );
754
int   normalToTriangle( CoordInfo *n, CoordInfo *v, triangle *t );
755
756
757
758
759
double GetBlendfactor( int d, int s, int feather );
760
761
762
763
764
765
void execute_stack        ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
766
767
void resize               ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );       
768
void shear                ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
769
void horiz                ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
770
void vert             ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
771
void radial               ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
772
773
774
void persp_sphere     ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
775
void persp_rect           ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
776
777
778
void rect_pano            ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
779
void pano_rect            ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
780
void pano_erect           ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
781
void erect_pano           ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
782
void sphere_cp_erect  ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
783
void sphere_tp_erect  ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
784
void erect_sphere_cp  ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
785
void rect_sphere_tp       ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
786
void sphere_tp_rect       ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
787
void sphere_cp_pano       ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
788
void rect_erect           ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
789
void erect_rect           ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
790
void erect_sphere_tp  ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
791
void mirror_erect     ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );    
792
void mirror_sphere_cp ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
793
void mirror_pano      ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
794
void sphere_cp_mirror ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );   
795
void sphere_tp_pano       ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );
796
797
void pano_sphere_tp       ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );
798
799
void rotate_erect     ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
800
void inv_radial           ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
801
802
void vertical         ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
803
void inv_vertical     ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
804
void deregister           ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
805
void tmorph               ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );
806
807
void shift_scale_rotate ( double x_dest,double  y_dest, double* x_src, double* y_src, void* params );
808
809
810
811
unsigned char radlum            ( unsigned char srcPixel, int xc, int yc, void *params );
812
//Kekus 16 bit 2003/Nov/18
813
unsigned short radlum16         ( unsigned short srcPixel, int xc, int yc, void *params );// , long bitsPerComponent);
814
//Kekus.
815
816
extern TrformStr      *gTrPtr;
817
extern sPrefs         *gsPrPtr;
818
819
820
821
822
// Endian stuff: Read and write numbers from and to memory (ptr)
823
824
#ifdef PT_BIGENDIAN
825
  #define LONGNUMBER( number, ptr )                   *ptr++ = ((char*)(&number))[0]; \
826
                                                      *ptr++ = ((char*)(&number))[1]; \
827
                                                      *ptr++ = ((char*)(&number))[2]; \
828
                                                      *ptr++ = ((char*)(&number))[3]; 
829
830
  #define NUMBERLONG( number, ptr )                   ((char*)(&number))[0] = *ptr++; \
831
                                                      ((char*)(&number))[1] = *ptr++; \
832
                                                      ((char*)(&number))[2] = *ptr++; \
833
                                                      ((char*)(&number))[3] = *ptr++; 
834
835
  #define SHORTNUMBER( number, ptr )                  *ptr++ = ((char*)(&number))[0]; \
836
                                                      *ptr++ = ((char*)(&number))[1]; \
837
838
  #define NUMBERSHORT( number, ptr )                  ((char*)(&number))[0] = *ptr++; \
839
                                                      ((char*)(&number))[1] = *ptr++; \
840
841
#else
842
  #define LONGNUMBER( number, ptr )                   *ptr++ = ((char*)(&number))[3]; \
843
                                                      *ptr++ = ((char*)(&number))[2]; \
844
                                                      *ptr++ = ((char*)(&number))[1]; \
845
                                                      *ptr++ = ((char*)(&number))[0]; 
846
847
  #define NUMBERLONG( number, ptr )                   ((char*)(&number))[3] = *ptr++; \
848
                                                      ((char*)(&number))[2] = *ptr++; \
849
                                                      ((char*)(&number))[1] = *ptr++; \
850
                                                      ((char*)(&number))[0] = *ptr++; 
851
852
  #define SHORTNUMBER( number, ptr )                  *ptr++ = ((char*)(&number))[1]; \
853
                                                      *ptr++ = ((char*)(&number))[0]; \
854
855
  #define NUMBERSHORT( number, ptr )                  ((char*)(&number))[1] = *ptr++; \
856
                                                      ((char*)(&number))[0] = *ptr++; \
857
858
859
860
#endif // PT_BIGENDIAN
861
862
// Cross platform file functions
863
864
#ifdef __Mac__
865
866
  #include <Carbon/Carbon.h> // Kekus Digital<Files.h>
867
  #include "sys_mac.h"
868
  
869
  #define         file_spec                           short
870
  #define         myopen( path, perm, fspec )         ( FSpOpenDF( path, perm, &fspec ) != noErr )
871
  #define         mywrite( fspec, count, data )       FSWrite (fspec, &count, data) 
872
  #define         myread(  fspec, count, data )       FSRead  (fspec, &count, data) 
873
  #define         myclose( fspec )                    FSClose (fspec )
874
  #define         mycreate( path, creator, type )     FSpCreate( path, creator, type,0)
875
  #define         mydelete( path )                    FSpDelete( path )
876
  #define         myrename( path, newpath )           FSpRename (path, (newpath)->name)
877
  #define         write_text                          fsWrPerm
878
  #define         write_bin                           fsWrPerm
879
  #define         read_text                           fsRdPerm
880
  #define         read_bin                            fsRdPerm
881
  #define         read_write_text                     fsRdWrPerm
882
          
883
#else // __Mac__, use ANSI-filefunctions
884
  #define     file_spec           FILE*
885
  #define     myopen( path, perm, fspec ) ( (fspec = fopen( (path)->name, perm )) == NULL)
886
  #define     mywrite( fspec, count, data )   count = (long)fwrite( data, 1, (size_t)count, fspec)
887
  #define     myread( fspec, count, data )    count = (long)fread( data, 1, (size_t)count, fspec ) 
888
  #define         myclose( fspec )        fclose (fspec )
889
  #define     mycreate( path, creator, type )     
890
  #define     mydelete( path )        remove((path)->name )
891
  #define     myrename( path, newpath )   rename ((path)->name, (newpath)->name)
892
  #define     write_text          "w"
893
  #define     write_bin           "wb"
894
  #define     read_text           "r"
895
  #define     read_bin            "rb"
896
  #define     read_write_text         "rw"
897
  #define     append_bin          "ab"
898
  #define     p2cstr( x ) 
899
  #define     c2pstr( x )
900
                                                          
901
902
#endif
903
904
905
906
907
#endif
908
909