1 /* Panorama_Tools - Generate, Edit and Convert Panoramic Images
2 Copyright (C) 1998,1999 - Helmut Dersch der@fh-furtwangen.de
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)
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.
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. */
18 /*------------------------------------------------------------*/
43 //---------------------- Types ---------------------------------------------
45 #define UCHAR unsigned char
46 #define USHORT unsigned short
47 #define ULONG unsigned long
55 //---------------------- Some useful math defines --------------------------
58 #define PI 3.14159265358979323846
61 // Normalize an angle to +/-180degrees
63 #define NORM_ANGLE( x ) while( x >180.0 ) x -= 360.0; while( x < -180.0 ) x += 360.0;
65 // Convert double x to unsigned char/short c
69 #define DBL_TO_UC( c, x ) if(x>255.0) c=255U; \
71 else c=(unsigned char)floor(x+0.5);
73 #define DBL_TO_US( c, x ) if(x>65535.0) c=65535U; \
75 else c=(unsigned short)floor(x+0.5);
99 typedef struct PTPoint PTPoint;
101 #define CopyPTPoint( to, from ) memcpy( &to, &from, sizeof( PTPoint ))
102 #define SamePTPoint( p, s ) ((p).x == (s).x && (p).y == (s).y)
109 typedef struct PTLine PTLine;
117 typedef struct PTTriangle PTTriangle;
122 // Maximum number of controlpoints in a pair of images, which can be read
127 // Randomization of feather in stitching tools
129 #define BLEND_RANDOMIZE 0.1
134 //----------------------- Structures -------------------------------------------
136 struct remap_Prefs{ // Preferences Structure for remap
137 long magic; // File validity check, must be 30
138 int from; // Image format source image
139 int to; // Image format destination image
140 double hfov; // horizontal field of view /in degrees
141 double vfov; // vertical field of view (usually ignored)
144 typedef struct remap_Prefs rPrefs;
146 struct perspective_Prefs{ // Preferences structure for tool perspective
147 long magic; // File validity check, must be 40
148 int format; // rectilinear or fisheye?
149 double hfov; // Horizontal field of view (in degree)
150 double x_alpha; // New viewing direction (x coordinate or angle)
151 double y_beta; // New viewing direction (y coordinate or angle)
152 double gamma; // Angle of rotation
153 int unit_is_cart; // true, if viewing direction is specified in coordinates
154 int width; // new width
155 int height; // new height
158 typedef struct perspective_Prefs pPrefs;
161 struct optVars{ // Indicate to optimizer which variables to optimize
162 int hfov; // optimize hfov? 0-no 1-yes , etc
173 typedef struct optVars optVars;
176 enum{ // Enumerates for stBuf.seam
177 _middle, // seam is placed in the middle of the overlap
178 _dest // seam is places at the edge of the image to be inserted
181 enum{ // Enumerates for colcorrect
182 _colCorrectImage = 1,
183 _colCorrectBuffer = 2,
187 struct stitchBuffer{ // Used describe how images should be merged
188 char srcName[256]; // Buffer should be merged to image; 0 if not.
189 char destName[256]; // Converted image (ie pano) should be saved to buffer; 0 if not
190 int feather; // Width of feather
191 int colcorrect; // Should the images be color corrected?
192 int seam; // Where to put the seam (see above)
195 typedef struct stitchBuffer stBuf;
197 struct panControls{ // Structure for realtime Panoeditor
198 double panAngle; // The amount by which yaw/pitch are changed per click
199 double zoomFactor; // The percentage for zoom in/out
203 typedef struct panControls panControls;
207 enum{ // Enumerates for aPrefs.mode
212 _useScript = 8, // else use options
215 struct adjust_Prefs{ // Preferences structure for tool adjust
216 long magic; // File validity check, must be 50
217 long mode; // What to do: create Panorama etc?
218 Image im; // Image to be inserted/extracted
219 Image pano; // Panorama to be created/ used for extraction
222 fullPath scriptFile; // On Mac: Cast to FSSpec; else: full path to scriptFile
226 typedef struct adjust_Prefs aPrefs;
238 typedef union panoPrefs panoPrefs;
241 struct size_Prefs{ // Preferences structure for 'pref' dialog
242 long magic; // File validity check; must be 70
243 int displayPart; // Display cropped/framed image ?
244 int saveFile; // Save to tempfile? 0-no, 1-yes
245 fullPath sFile; // Full path to file (short name)
246 int launchApp; // Open sFile ?
247 fullPath lApp; // the Application to launch
248 int interpolator; // Which interpolator to use
249 double gamma; // Gamma correction value
250 int noAlpha; // If new file is created: Don't save mask (Photoshop LE)
251 int optCreatePano; // Optimizer creates panos? 0 no/ 1 yes
254 typedef struct size_Prefs sPrefs;
259 struct controlPoint{ // Control Points to adjust images
260 int num[2]; // Indices of Images
261 int x[2]; // x - Coordinates
262 int y[2]; // y - Coordinates
263 int type; // What to optimize: 0-r, 1-x, 2-y
266 struct controlPoint{ // Control Points to adjust images
267 int num[2]; // Indices of Images
268 double x[2]; // x - Coordinates
269 double y[2]; // y - Coordinates
270 int type; // What to optimize: 0-r, 1-x, 2-y
273 typedef struct controlPoint controlPoint;
275 struct CoordInfo{ // Real World 3D coordinates
276 int num; // auxilliary index
281 typedef struct CoordInfo CoordInfo;
283 // Some useful macros for vectors
285 #define SCALAR_PRODUCT( v1, v2 ) ( (v1)->x[0]*(v2)->x[0] + (v1)->x[1]*(v2)->x[1] + (v1)->x[2]*(v2)->x[2] )
286 #define ABS_SQUARED( v ) SCALAR_PRODUCT( v, v )
287 #define ABS_VECTOR( v ) sqrt( ABS_SQUARED( v ) )
288 #define CROSS_PRODUCT( v1, v2, r ) { (r)->x[0] = (v1)->x[1] * (v2)->x[2] - (v1)->x[2]*(v2)->x[1]; \
289 (r)->x[1] = (v1)->x[2] * (v2)->x[0] - (v1)->x[0]*(v2)->x[2]; \
290 (r)->x[2] = (v1)->x[0] * (v2)->x[1] - (v1)->x[1]*(v2)->x[0]; }
291 #define DIFF_VECTOR( v1, v2, r ) { (r)->x[0] = (v1)->x[0] - (v2)->x[0]; \
292 (r)->x[1] = (v1)->x[1] - (v2)->x[1]; \
293 (r)->x[2] = (v1)->x[2] - (v2)->x[2]; }
294 #define DIST_VECTOR( v1, v2 ) sqrt( ((v1)->x[0] - (v2)->x[0]) * ((v1)->x[0] - (v2)->x[0]) + \
295 ((v1)->x[1] - (v2)->x[1]) * ((v1)->x[1] - (v2)->x[1]) + \
296 ((v1)->x[2] - (v2)->x[2]) * ((v1)->x[2] - (v2)->x[2]) )
298 struct transformCoord{ //
299 int nump; // Number of p-coordinates
300 CoordInfo *p; // Coordinates "as is"
301 int numr; // Number of r-coordinates
302 CoordInfo *r; // Requested values for coordinates
305 typedef struct transformCoord transformCoord;
315 typedef struct tMatrix tMatrix;
323 struct MakeParams{ // Actual parameters used by Xform functions for pano-creation
324 double scale[2]; // scaling factors for resize;
325 double shear[2]; // shear values
326 double rot[2]; // horizontal rotation params
327 void *perspect[2]; // Parameters for perspective control functions
328 double rad[6]; // coefficients for polynomial correction (0,...3) and source width/2 (4) and correction radius (5)
329 double mt[3][3]; // Matrix
335 struct LMStruct{ // Parameters used by the Levenberg Marquardt-Solver
361 // function to minimize in Levenberg-Marquardt solver
363 typedef int (*lmfunc)();
367 int vert[3]; // Three vertices from list
368 int nIm; // number of image for texture mapping
371 typedef struct triangle triangle;
376 struct AlignInfo{ // Global data structure used by alignment optimization
377 Image *im; // Array of Pointers to Image Structs
378 optVars *opt; // Mark variables to optimize
379 int numIm; // Number of images
380 controlPoint *cpt; // List of Control points
381 triangle *t; // List of triangular faces
382 int nt; // Number of triangular faces
383 int numPts; // Number of Control Points
384 int numParam; // Number of parameters to optimize
385 Image pano; // Panoramic Image decription
386 stBuf st; // Info on how to stitch the panorama
390 CoordInfo *cim; // Real World coordinates
393 typedef struct AlignInfo AlignInfo;
396 int numVars; // Number of variables to fit
397 int numData; // Number of data to fit to
398 int (*SetVarsToX)(double *x); // Translate variables to x-values
399 int (*SetXToVars)(double *x); // and reverse
400 lmfunc fcn; // Levenberg Marquardt function measuring quality
401 char message[256]; // info returned by LM-optimizer
404 typedef struct OptInfo OptInfo;
420 typedef struct VRPanoOptions VRPanoOptions;
423 struct MultiLayerImage
431 typedef struct MultiLayerImage MultiLayerImage;
438 // Transformation function type (we have only one...)
440 typedef void (*trfn)( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
443 // Function descriptor to be executed by exec_function
445 trfn func; // The function to be called
446 void *param; // The parameters to be used
449 typedef struct fDesc fDesc;
451 #define SetDesc(fD,f,p) fD.func = f; fD.param = p
453 // Panorama tool type
455 typedef void (*fnPtr)(TrformStr *TrPtr);
458 // Filter function type
460 typedef unsigned char (*flfn)( unsigned char srcPixel, int xc, int yc, void *params );
463 // Interpolating functions for resampler
465 typedef void (*intFunc)( unsigned char *dst, unsigned char **rgb,
468 int color, int SamplesPerPixel);
478 unsigned short *Gamma;
484 typedef struct PTGamma PTGamma;
489 // Some macros to find out more about images
491 #define GetBitsPerChannel( im, x ) switch( (im)->bitsPerPixel ) \
493 case 24: x = 8; break; \
494 case 32: x = 8; break; \
495 case 48: x = 16; break; \
496 case 64: x = 16; break; \
497 default: x = 8; break; \
500 #define GetChannels( im, x ) switch( (im)->bitsPerPixel ) \
502 case 24: x = 3; break; \
503 case 32: x = 4; break; \
504 case 48: x = 3; break; \
505 case 64: x = 4; break; \
506 default: x = 3; break; \
511 //---------------------------------- Functions identical in all platforms ------------------------
514 void dispatch (TrformStr *TrPtr, sPrefs *s); // Entry into platform independent code
515 void DoTransForm (TrformStr *TrPtr, panoPrefs *p );
517 void setLibToResFile ( void ); // MacOS: Get resources from shared lib
518 void unsetLibToResFile( void ); // MacOS: Don't get resources from shared lib
520 enum{ // Enumerates used by Progress and infoDlg
521 _initProgress, // display message "argument"
522 _setProgress, // display progress (argument is percentage converted to string)
523 _disposeProgress, // dispose progress indicator
524 _idleProgress // do nothing; on Mac: call waitnextevent;
527 int Progress( int command, char* argument ); // Progress Reporting
528 int infoDlg ( int command, char* argument ); // Display info: same argumenmts as progress
529 void PrintError( char* fmt, ...); // Error Reporting
531 int ccommand( char ***argvPtr); // Shell for standalone programs
534 // Panorama Tool functions
537 void perspective (TrformStr *TrPtr, pPrefs *p);
538 void correct (TrformStr *TrPtr, cPrefs *c);
539 void remap (TrformStr *TrPtr, rPrefs *r);
540 void adjust (TrformStr *TrPtr, aPrefs *a);
541 void pan (TrformStr *TrPtr, panControls *pc);
546 // Set Struct defaults
548 void SetPrefDefaults (panoPrefs *prPtr, int selector);
549 void SetCorrectDefaults ( cPrefs *p );
550 void SetAdjustDefaults ( aPrefs *p );
551 void SetRemapDefaults ( rPrefs *p );
552 void SetPerspectiveDefaults ( pPrefs *p );
553 void SetImageDefaults ( Image *im);
554 void SetOptDefaults ( optVars *opt );
555 void SetPanDefaults ( panControls *pc);
556 void SetSizeDefaults ( sPrefs *pref);
557 void SetStitchDefaults ( stBuf *sbuf);
558 void SetVRPanoOptionsDefaults( VRPanoOptions *v);
559 void SettMatrixDefaults ( tMatrix *t );
560 void SetCoordDefaults ( CoordInfo *c, int num);
562 int SetAlignParams ( double *x );
563 int SetLMParams ( double *x );
564 void SetGlobalPtr ( AlignInfo *p );
569 int SetPrefs ( panoPrefs *p );
570 int SetPanPrefs ( panControls *p );
571 int SetCorrectPrefs ( cPrefs *p );
572 int SetRadialOptions ( cPrefs *p );
573 int SetHorizontalOptions( cPrefs *p );
574 int SetVerticalOptions ( cPrefs *p );
575 int SetShearOptions ( cPrefs *p );
576 int SetScaleOptions ( cPrefs *p );
577 int SetLumOptions ( cPrefs *p );
578 int setSizePrefs ( sPrefs *p, int can_resize );
579 int SetRemapPrefs ( rPrefs *p );
580 int SetPerspectivePrefs ( pPrefs *p );
581 int SetAdjustPrefs ( aPrefs *p );
582 int SetInterpolator ( sPrefs *p );
583 int SetCreateOptions ( aPrefs *p );
584 int SetCutOptions ( cPrefs *p );
585 int SetFourierOptions ( cPrefs *p );
591 int readPrefs (char* p, int selector ); // Preferences, same selector as dispatch
592 void writePrefs (char* p, int selector ); // Preferences, same selector as dispatch
594 int LoadBufImage ( Image *image, char *fname, int mode);
595 int SaveBufImage ( Image *image, char *fname );
596 int writeTIFF ( Image *im, fullPath* fname); // On Mac: fname is FSSpec*
597 void SaveOptions ( struct correct_Prefs * thePrefs );
598 int LoadOptions ( struct correct_Prefs * thePrefs );
599 void FindScript ( struct adjust_Prefs *thePrefs );
600 char* LoadScript ( fullPath* scriptFile );
601 int WriteScript ( char* res, fullPath* scriptFile, int launch );
602 int writePSD ( Image *im, fullPath* fname); // On Mac: fname is FSSpec*
603 int readPSD ( Image *im, fullPath* fname, int mode);
604 int FindFile ( fullPath *fname );
605 int SaveFileAs ( fullPath *fname, char *prompt, char *name );
606 void ConvFileName ( fullPath *fname,char *string);
607 int writePSDwithLayer ( Image *im, fullPath *fname);
608 int addLayerToFile ( Image *im, fullPath* sfile, fullPath* dfile, stBuf *sB);
609 void showScript ( fullPath* scriptFile );
610 void MakeTempName ( fullPath *fspec, char *fname );
611 void makePathForResult ( fullPath *path );
612 int makePathToHost ( fullPath *path );
613 void open_selection ( fullPath *path );
614 int readPSDMultiLayerImage( MultiLayerImage *mim, fullPath* sfile);
615 int GetFullPath (fullPath *path, char *filename); // Somewhat confusing, for compatibility easons
616 int StringtoFullPath (fullPath *path, char *filename);
617 int IsTextFile ( char* fname );
618 int readPositions ( char* script, transformCoord *tP );
619 int readImage ( Image *im, fullPath *sfile );
620 int writeImage ( Image *im, fullPath *sfile );
621 int writeJPEG ( Image *im, fullPath *sfile, int quality, int progressive );
622 int makeTempPath ( fullPath *path );
623 int writePNG ( Image *im, fullPath *sfile );
624 int readPNG ( Image *im, fullPath *sfile );
626 #define FullPathtoString( path, string ) GetFullPath( path, string)
631 // Image manipulation
633 void addAlpha ( Image *im );
634 void transForm ( TrformStr *TrPtr, fDesc *fD, int color);
635 void filter ( TrformStr *TrPtr, flfn func, void* params, int color);
636 void CopyImageData ( Image *dest, Image *src );
637 void laplace ( Image *im );
638 void blurr ( Image *im );
639 void MakePano ( TrformStr *TrPtr, aPrefs *aP, int nt, PTTriangle *ts, PTTriangle *td);
640 void ExtractStill ( TrformStr *TrPtr , aPrefs *p );
641 int HaveEqualSize ( Image *im1, Image *im2 );
642 int merge ( Image *dst, Image *src, int feather, int showprogress, int seam );
643 void mergeAlpha ( Image *im, unsigned char *alpha, int feather, PTRect *theRect );
644 void SetEquColor ( cPrefs *p );
645 void CopyPosition ( Image *to, Image *from );
646 int isColorSpecific ( cPrefs *p );
647 void ThreeToFourBPP ( Image *im );
648 void FourToThreeBPP ( Image *im );
649 int SetUpGamma ( double pgamma, int psize);
650 int cutTheFrame ( Image *dest, Image *src, int width, int height, int showprogress );
651 int PositionCmp ( Image *im1, Image *im2 );
652 int MorphImage ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
653 int MorphImageFile ( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
654 int blendImages ( fullPath *f0, fullPath *f1, fullPath *result, double s );
655 int InterpolateImage ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
656 int InterpolateTrianglesPerspective( AlignInfo *g, int nIm, double s, PTTriangle** t );
657 int InterpolateImageFile( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
658 void OneToTwoByte ( Image *im );
659 void TwoToOneByte ( Image *im );
660 void SetMakeParams ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
661 void SetInvMakeParams ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
662 void GetControlPointCoordinates(int i, double *x, double *y, AlignInfo *gl );
665 // Script Reading/Parsing/Writing
667 int ParseScript ( char* script, AlignInfo *gl );
668 void WriteResults ( char* script, fullPath *sfile, AlignInfo *g, double ds( int i) , int launch);
669 int readAdjust ( aPrefs *p, fullPath* sfile , int insert);
670 void readControlPoints (char* script, controlPoint *c );
671 int getVRPanoOptions ( VRPanoOptions *v, char *line );
672 void nextWord ( register char* word, char** ch );
673 void nextLine ( register char* line, char** ch );
674 int numLines ( char* script, char first );
678 void DisposeAlignInfo ( AlignInfo *g );
679 void** mymalloc ( long numBytes ); // Memory allocation, use Handles
680 void myfree ( void** Hdl ); // free Memory, use Handles
681 int SetDestImage ( TrformStr *TrPtr, int width, int height) ;
682 void DisposeMultiLayerImage( MultiLayerImage *mim );
687 void RunLMOptimizer ( OptInfo *g);
688 void RunBROptimizer ( OptInfo *g, double minStepWidth);
689 void RunOverlapOptimizer ( AlignInfo *g);
691 void SetMatrix ( double a, double b, double c , double m[3][3], int cl );
692 void matrix_mult ( double m[3][3], double vector[3] );
693 void matrix_inv_mult ( double m[3][3], double vector[3] );
694 double smallestRoot ( double *p );
695 void SetCorrectionRadius ( cPrefs *cP );
697 void fourier ( TrformStr *TrPtr, cPrefs *cP );
698 unsigned short gamma_correct( double pix );
699 int EqualCPrefs( cPrefs *c1, cPrefs *c2 );
700 double OverlapRMS ( MultiLayerImage *mim );
701 double distSquared ( int num );
703 void doCoordinateTransform( CoordInfo *c, tMatrix *t );
704 void findOptimumtMatrix( transformCoord *tP, tMatrix *tM, lmfunc f);
705 int SolveLinearEquation2( double a[2][2], double b[2], double x[2] );
706 void SortControlPoints( AlignInfo *g , int nIm);
707 void noisefilter ( Image *dest, Image *src );
708 void fwiener ( TrformStr *TrPtr, Image *nf, Image *psf, double gamma, double frame );
712 int PointInTriangle( double x, double y, PTTriangle *T, double c[2] );
713 int SetSourceTriangles( AlignInfo *g, int nIm, PTTriangle** t );
714 int SetDestTriangles( AlignInfo *g, int nIm, PTTriangle** t );
715 int InterpolateTriangles( AlignInfo *g, int nIm, double s, PTTriangle** t );
716 int DelaunayIteration( AlignInfo *g, int nIm );
717 int PointInCircumcircle( double x, double y, PTTriangle *tC );
718 int TriangulatePoints( AlignInfo *g, int nIm );
719 int AddTriangle( triangle *t, AlignInfo *g );
720 int RemoveTriangle( int nt, AlignInfo *g );
721 void OrderVerticesInTriangle( int nt, AlignInfo *g );
722 void SetTriangleCoordinates( triangle *t, PTTriangle *tC, AlignInfo *g );
723 int TrianglesOverlap( PTTriangle *t0, PTTriangle *t1 );
724 int LinesIntersect( PTLine *s0, PTLine *s1) ;
725 double PTDistance( PTPoint *s0, PTPoint *s1 );
726 int PTPointInRectangle( PTPoint *p, PTLine *r );
727 int PTElementOf( double x, double a, double b );
728 int PTNormal( double *a, double *b, double *c, PTLine *s );
729 int PTGetLineCrossing( PTLine *s0, PTLine *s1, PTPoint *ps );
730 int ReduceTriangles( AlignInfo *g, int nIm );
731 double PTAreaOfTriangle( PTTriangle *t );
732 int normalToTriangle( CoordInfo *n, CoordInfo *v, triangle *t );
737 double GetBlendfactor( int d, int s, int feather );
743 void execute_stack ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
745 void resize ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
746 void shear ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
747 void horiz ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
748 void vert ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
749 void radial ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
752 void persp_sphere ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
753 void persp_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
756 void rect_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
757 void pano_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
758 void pano_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
759 void erect_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
760 void sphere_cp_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
761 void sphere_tp_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
762 void erect_sphere_cp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
763 void rect_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
764 void sphere_tp_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
765 void sphere_cp_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
766 void rect_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
767 void erect_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
768 void erect_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
769 void mirror_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
770 void mirror_sphere_cp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
771 void mirror_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
772 void sphere_cp_mirror ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
773 void sphere_tp_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
775 void pano_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
777 void rotate_erect ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
778 void inv_radial ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
780 void vertical ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
781 void inv_vertical ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
782 void deregister ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
783 void tmorph ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
787 unsigned char radlum ( unsigned char srcPixel, int xc, int yc, void *params );
790 extern TrformStr *gTrPtr;
791 extern sPrefs *gsPrPtr;
796 // Endian stuff: Read and write numbers from and to memory (ptr)
799 #define LONGNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[0]; \
800 *ptr++ = ((char*)(&number))[1]; \
801 *ptr++ = ((char*)(&number))[2]; \
802 *ptr++ = ((char*)(&number))[3];
804 #define NUMBERLONG( number, ptr ) ((char*)(&number))[0] = *ptr++; \
805 ((char*)(&number))[1] = *ptr++; \
806 ((char*)(&number))[2] = *ptr++; \
807 ((char*)(&number))[3] = *ptr++;
809 #define SHORTNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[0]; \
810 *ptr++ = ((char*)(&number))[1]; \
812 #define NUMBERSHORT( number, ptr ) ((char*)(&number))[0] = *ptr++; \
813 ((char*)(&number))[1] = *ptr++; \
816 #define LONGNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[3]; \
817 *ptr++ = ((char*)(&number))[2]; \
818 *ptr++ = ((char*)(&number))[1]; \
819 *ptr++ = ((char*)(&number))[0];
821 #define NUMBERLONG( number, ptr ) ((char*)(&number))[3] = *ptr++; \
822 ((char*)(&number))[2] = *ptr++; \
823 ((char*)(&number))[1] = *ptr++; \
824 ((char*)(&number))[0] = *ptr++;
826 #define SHORTNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[1]; \
827 *ptr++ = ((char*)(&number))[0]; \
829 #define NUMBERSHORT( number, ptr ) ((char*)(&number))[1] = *ptr++; \
830 ((char*)(&number))[0] = *ptr++; \
836 // Cross platform file functions
843 #define file_spec short
844 #define myopen( path, perm, fspec ) ( FSpOpenDF( path, perm, &fspec ) != noErr )
845 #define mywrite( fspec, count, data ) FSWrite (fspec, &count, data)
846 #define myread( fspec, count, data ) FSRead (fspec, &count, data)
847 #define myclose( fspec ) FSClose (fspec )
848 #define mycreate( path, creator, type ) FSpCreate( path, creator, type,0)
849 #define mydelete( path ) FSpDelete( path )
850 #define myrename( path, newpath ) FSpRename (path, (newpath)->name)
851 #define write_text fsWrPerm
852 #define write_bin fsWrPerm
853 #define read_text fsRdPerm
854 #define read_bin fsRdPerm
855 #define read_write_text fsRdWrPerm
857 #else // __Mac__, use ANSI-filefunctions
858 #define file_spec FILE*
859 #define myopen( path, perm, fspec ) ( (fspec = fopen( (path)->name, perm )) == NULL)
860 #define mywrite( fspec, count, data ) count = fwrite( data, 1, count, fspec)
861 #define myread( fspec, count, data ) count = fread( data, 1, count, fspec )
862 #define myclose( fspec ) fclose (fspec )
863 #define mycreate( path, creator, type )
864 #define mydelete( path ) remove((path)->name )
865 #define myrename( path, newpath ) rename ((path)->name, (newpath)->name)
866 #define write_text "w"
867 #define write_bin "wb"
868 #define read_text "r"
869 #define read_bin "rb"
870 #define read_write_text "rw"