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 degree to radian
67 #define DEG_TO_RAD( x ) ( (x) * 2.0 * PI / 360.0 )
71 #define RAD_TO_DEG( x ) ( (x) * 360.0 / ( 2.0 * PI ) )
73 // Convert double x to unsigned char/short c
77 #define DBL_TO_UC( c, x ) if(x>255.0) c=255U; \
79 else c=(unsigned char)floor(x+0.5);
81 #define DBL_TO_US( c, x ) if(x>65535.0) c=65535U; \
83 else c=(unsigned short)floor(x+0.5);
107 typedef struct PTPoint PTPoint;
109 #define CopyPTPoint( to, from ) memcpy( &to, &from, sizeof( PTPoint ))
110 #define SamePTPoint( p, s ) ((p).x == (s).x && (p).y == (s).y)
117 typedef struct PTLine PTLine;
125 typedef struct PTTriangle PTTriangle;
130 // Maximum number of controlpoints in a pair of images, which can be read
135 // Randomization of feather in stitching tools
137 #define BLEND_RANDOMIZE 0.1
142 //----------------------- Structures -------------------------------------------
144 struct remap_Prefs{ // Preferences Structure for remap
145 long magic; // File validity check, must be 30
146 int from; // Image format source image
147 int to; // Image format destination image
148 double hfov; // horizontal field of view /in degrees
149 double vfov; // vertical field of view (usually ignored)
152 typedef struct remap_Prefs rPrefs;
154 struct perspective_Prefs{ // Preferences structure for tool perspective
155 long magic; // File validity check, must be 40
156 int format; // rectilinear or fisheye?
157 double hfov; // Horizontal field of view (in degree)
158 double x_alpha; // New viewing direction (x coordinate or angle)
159 double y_beta; // New viewing direction (y coordinate or angle)
160 double gamma; // Angle of rotation
161 int unit_is_cart; // true, if viewing direction is specified in coordinates
162 int width; // new width
163 int height; // new height
166 typedef struct perspective_Prefs pPrefs;
169 struct optVars{ // Indicate to optimizer which variables to optimize
170 int hfov; // optimize hfov? 0-no 1-yes , etc
181 typedef struct optVars optVars;
184 enum{ // Enumerates for stBuf.seam
185 _middle, // seam is placed in the middle of the overlap
186 _dest // seam is places at the edge of the image to be inserted
189 enum{ // Enumerates for colcorrect
190 _colCorrectImage = 1,
191 _colCorrectBuffer = 2,
195 struct stitchBuffer{ // Used describe how images should be merged
196 char srcName[256]; // Buffer should be merged to image; 0 if not.
197 char destName[256]; // Converted image (ie pano) should be saved to buffer; 0 if not
198 int feather; // Width of feather
199 int colcorrect; // Should the images be color corrected?
200 int seam; // Where to put the seam (see above)
203 typedef struct stitchBuffer stBuf;
205 struct panControls{ // Structure for realtime Panoeditor
206 double panAngle; // The amount by which yaw/pitch are changed per click
207 double zoomFactor; // The percentage for zoom in/out
211 typedef struct panControls panControls;
215 enum{ // Enumerates for aPrefs.mode
220 _useScript = 8, // else use options
223 struct adjust_Prefs{ // Preferences structure for tool adjust
224 long magic; // File validity check, must be 50
225 long mode; // What to do: create Panorama etc?
226 Image im; // Image to be inserted/extracted
227 Image pano; // Panorama to be created/ used for extraction
230 fullPath scriptFile; // On Mac: Cast to FSSpec; else: full path to scriptFile
234 typedef struct adjust_Prefs aPrefs;
246 typedef union panoPrefs panoPrefs;
249 struct size_Prefs{ // Preferences structure for 'pref' dialog
250 long magic; // File validity check; must be 70
251 int displayPart; // Display cropped/framed image ?
252 int saveFile; // Save to tempfile? 0-no, 1-yes
253 fullPath sFile; // Full path to file (short name)
254 int launchApp; // Open sFile ?
255 fullPath lApp; // the Application to launch
256 int interpolator; // Which interpolator to use
257 double gamma; // Gamma correction value
258 int noAlpha; // If new file is created: Don't save mask (Photoshop LE)
259 int optCreatePano; // Optimizer creates panos? 0 no/ 1 yes
262 typedef struct size_Prefs sPrefs;
267 struct controlPoint{ // Control Points to adjust images
268 int num[2]; // Indices of Images
269 int x[2]; // x - Coordinates
270 int y[2]; // y - Coordinates
271 int type; // What to optimize: 0-r, 1-x, 2-y
274 struct controlPoint{ // Control Points to adjust images
275 int num[2]; // Indices of Images
276 double x[2]; // x - Coordinates
277 double y[2]; // y - Coordinates
278 int type; // What to optimize: 0-r, 1-x, 2-y
281 typedef struct controlPoint controlPoint;
283 struct CoordInfo{ // Real World 3D coordinates
284 int num; // auxilliary index
289 typedef struct CoordInfo CoordInfo;
291 // Some useful macros for vectors
293 #define SCALAR_PRODUCT( v1, v2 ) ( (v1)->x[0]*(v2)->x[0] + (v1)->x[1]*(v2)->x[1] + (v1)->x[2]*(v2)->x[2] )
294 #define ABS_SQUARED( v ) SCALAR_PRODUCT( v, v )
295 #define ABS_VECTOR( v ) sqrt( ABS_SQUARED( v ) )
296 #define CROSS_PRODUCT( v1, v2, r ) { (r)->x[0] = (v1)->x[1] * (v2)->x[2] - (v1)->x[2]*(v2)->x[1]; \
297 (r)->x[1] = (v1)->x[2] * (v2)->x[0] - (v1)->x[0]*(v2)->x[2]; \
298 (r)->x[2] = (v1)->x[0] * (v2)->x[1] - (v1)->x[1]*(v2)->x[0]; }
299 #define DIFF_VECTOR( v1, v2, r ) { (r)->x[0] = (v1)->x[0] - (v2)->x[0]; \
300 (r)->x[1] = (v1)->x[1] - (v2)->x[1]; \
301 (r)->x[2] = (v1)->x[2] - (v2)->x[2]; }
302 #define DIST_VECTOR( v1, v2 ) sqrt( ((v1)->x[0] - (v2)->x[0]) * ((v1)->x[0] - (v2)->x[0]) + \
303 ((v1)->x[1] - (v2)->x[1]) * ((v1)->x[1] - (v2)->x[1]) + \
304 ((v1)->x[2] - (v2)->x[2]) * ((v1)->x[2] - (v2)->x[2]) )
306 struct transformCoord{ //
307 int nump; // Number of p-coordinates
308 CoordInfo *p; // Coordinates "as is"
309 int numr; // Number of r-coordinates
310 CoordInfo *r; // Requested values for coordinates
313 typedef struct transformCoord transformCoord;
323 typedef struct tMatrix tMatrix;
331 struct MakeParams{ // Actual parameters used by Xform functions for pano-creation
332 double scale[2]; // scaling factors for resize;
333 double shear[2]; // shear values
334 double rot[2]; // horizontal rotation params
335 void *perspect[2]; // Parameters for perspective control functions
336 double rad[6]; // coefficients for polynomial correction (0,...3) and source width/2 (4) and correction radius (5)
337 double mt[3][3]; // Matrix
343 struct LMStruct{ // Parameters used by the Levenberg Marquardt-Solver
369 // function to minimize in Levenberg-Marquardt solver
371 typedef int (*lmfunc)();
375 int vert[3]; // Three vertices from list
376 int nIm; // number of image for texture mapping
379 typedef struct triangle triangle;
384 struct AlignInfo{ // Global data structure used by alignment optimization
385 Image *im; // Array of Pointers to Image Structs
386 optVars *opt; // Mark variables to optimize
387 int numIm; // Number of images
388 controlPoint *cpt; // List of Control points
389 triangle *t; // List of triangular faces
390 int nt; // Number of triangular faces
391 int numPts; // Number of Control Points
392 int numParam; // Number of parameters to optimize
393 Image pano; // Panoramic Image decription
394 stBuf st; // Info on how to stitch the panorama
398 CoordInfo *cim; // Real World coordinates
401 typedef struct AlignInfo AlignInfo;
404 int numVars; // Number of variables to fit
405 int numData; // Number of data to fit to
406 int (*SetVarsToX)(double *x); // Translate variables to x-values
407 int (*SetXToVars)(double *x); // and reverse
408 lmfunc fcn; // Levenberg Marquardt function measuring quality
409 char message[256]; // info returned by LM-optimizer
412 typedef struct OptInfo OptInfo;
428 typedef struct VRPanoOptions VRPanoOptions;
431 struct MultiLayerImage
439 typedef struct MultiLayerImage MultiLayerImage;
446 // Transformation function type (we have only one...)
448 typedef void (*trfn)( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
451 // Function descriptor to be executed by exec_function
453 trfn func; // The function to be called
454 void *param; // The parameters to be used
457 typedef struct fDesc fDesc;
459 #define SetDesc(fD,f,p) fD.func = f; fD.param = p
461 // Panorama tool type
463 typedef void (*fnPtr)(TrformStr *TrPtr);
466 // Filter function type
468 typedef unsigned char (*flfn)( unsigned char srcPixel, int xc, int yc, void *params );
471 // Interpolating functions for resampler
473 typedef void (*intFunc)( unsigned char *dst, unsigned char **rgb,
476 int color, int SamplesPerPixel);
486 unsigned short *Gamma;
492 typedef struct PTGamma PTGamma;
497 // Some macros to find out more about images
499 #define GetBitsPerChannel( im, x ) switch( (im)->bitsPerPixel ) \
501 case 24: x = 8; break; \
502 case 32: x = 8; break; \
503 case 48: x = 16; break; \
504 case 64: x = 16; break; \
505 default: x = 8; break; \
508 #define GetChannels( im, x ) switch( (im)->bitsPerPixel ) \
510 case 24: x = 3; break; \
511 case 32: x = 4; break; \
512 case 48: x = 3; break; \
513 case 64: x = 4; break; \
514 default: x = 3; break; \
519 //---------------------------------- Functions identical in all platforms ------------------------
522 void dispatch (TrformStr *TrPtr, sPrefs *s); // Entry into platform independent code
523 void DoTransForm (TrformStr *TrPtr, panoPrefs *p );
525 void setLibToResFile ( void ); // MacOS: Get resources from shared lib
526 void unsetLibToResFile( void ); // MacOS: Don't get resources from shared lib
528 enum{ // Enumerates used by Progress and infoDlg
529 _initProgress, // display message "argument"
530 _setProgress, // display progress (argument is percentage converted to string)
531 _disposeProgress, // dispose progress indicator
532 _idleProgress // do nothing; on Mac: call waitnextevent;
535 int Progress( int command, char* argument ); // Progress Reporting
536 int infoDlg ( int command, char* argument ); // Display info: same argumenmts as progress
537 void PrintError( char* fmt, ...); // Error Reporting
539 int ccommand( char ***argvPtr); // Shell for standalone programs
542 // Panorama Tool functions
545 void perspective (TrformStr *TrPtr, pPrefs *p);
546 void correct (TrformStr *TrPtr, cPrefs *c);
547 void remap (TrformStr *TrPtr, rPrefs *r);
548 void adjust (TrformStr *TrPtr, aPrefs *a);
549 void pan (TrformStr *TrPtr, panControls *pc);
554 // Set Struct defaults
556 void SetPrefDefaults (panoPrefs *prPtr, int selector);
557 void SetCorrectDefaults ( cPrefs *p );
558 void SetAdjustDefaults ( aPrefs *p );
559 void SetRemapDefaults ( rPrefs *p );
560 void SetPerspectiveDefaults ( pPrefs *p );
561 void SetImageDefaults ( Image *im);
562 void SetOptDefaults ( optVars *opt );
563 void SetPanDefaults ( panControls *pc);
564 void SetSizeDefaults ( sPrefs *pref);
565 void SetStitchDefaults ( stBuf *sbuf);
566 void SetVRPanoOptionsDefaults( VRPanoOptions *v);
567 void SettMatrixDefaults ( tMatrix *t );
568 void SetCoordDefaults ( CoordInfo *c, int num);
570 int SetAlignParams ( double *x );
571 int SetLMParams ( double *x );
572 void SetGlobalPtr ( AlignInfo *p );
577 int SetPrefs ( panoPrefs *p );
578 int SetPanPrefs ( panControls *p );
579 int SetCorrectPrefs ( cPrefs *p );
580 int SetRadialOptions ( cPrefs *p );
581 int SetHorizontalOptions( cPrefs *p );
582 int SetVerticalOptions ( cPrefs *p );
583 int SetShearOptions ( cPrefs *p );
584 int SetScaleOptions ( cPrefs *p );
585 int SetLumOptions ( cPrefs *p );
586 int setSizePrefs ( sPrefs *p, int can_resize );
587 int SetRemapPrefs ( rPrefs *p );
588 int SetPerspectivePrefs ( pPrefs *p );
589 int SetAdjustPrefs ( aPrefs *p );
590 int SetInterpolator ( sPrefs *p );
591 int SetCreateOptions ( aPrefs *p );
592 int SetCutOptions ( cPrefs *p );
593 int SetFourierOptions ( cPrefs *p );
599 int readPrefs (char* p, int selector ); // Preferences, same selector as dispatch
600 void writePrefs (char* p, int selector ); // Preferences, same selector as dispatch
602 int LoadBufImage ( Image *image, char *fname, int mode);
603 int SaveBufImage ( Image *image, char *fname );
604 int writeTIFF ( Image *im, fullPath* fname); // On Mac: fname is FSSpec*
605 void SaveOptions ( struct correct_Prefs * thePrefs );
606 int LoadOptions ( struct correct_Prefs * thePrefs );
607 void FindScript ( struct adjust_Prefs *thePrefs );
608 char* LoadScript ( fullPath* scriptFile );
609 int WriteScript ( char* res, fullPath* scriptFile, int launch );
610 int writePSD ( Image *im, fullPath* fname); // On Mac: fname is FSSpec*
611 int readPSD ( Image *im, fullPath* fname, int mode);
612 int FindFile ( fullPath *fname );
613 int SaveFileAs ( fullPath *fname, char *prompt, char *name );
614 void ConvFileName ( fullPath *fname,char *string);
615 int writePSDwithLayer ( Image *im, fullPath *fname);
616 int addLayerToFile ( Image *im, fullPath* sfile, fullPath* dfile, stBuf *sB);
617 void showScript ( fullPath* scriptFile );
618 void MakeTempName ( fullPath *fspec, char *fname );
619 void makePathForResult ( fullPath *path );
620 int makePathToHost ( fullPath *path );
621 void open_selection ( fullPath *path );
622 int readPSDMultiLayerImage( MultiLayerImage *mim, fullPath* sfile);
623 int GetFullPath (fullPath *path, char *filename); // Somewhat confusing, for compatibility easons
624 int StringtoFullPath (fullPath *path, char *filename);
625 int IsTextFile ( char* fname );
626 int readPositions ( char* script, transformCoord *tP );
627 int readImage ( Image *im, fullPath *sfile );
628 int writeImage ( Image *im, fullPath *sfile );
629 int writeJPEG ( Image *im, fullPath *sfile, int quality, int progressive );
630 int makeTempPath ( fullPath *path );
631 int writePNG ( Image *im, fullPath *sfile );
632 int readPNG ( Image *im, fullPath *sfile );
634 #define FullPathtoString( path, string ) GetFullPath( path, string)
639 // Image manipulation
641 void addAlpha ( Image *im );
642 void transForm ( TrformStr *TrPtr, fDesc *fD, int color);
643 void filter ( TrformStr *TrPtr, flfn func, void* params, int color);
644 void CopyImageData ( Image *dest, Image *src );
645 void laplace ( Image *im );
646 void blurr ( Image *im );
647 void MakePano ( TrformStr *TrPtr, aPrefs *aP, int nt, PTTriangle *ts, PTTriangle *td);
648 void ExtractStill ( TrformStr *TrPtr , aPrefs *p );
649 int HaveEqualSize ( Image *im1, Image *im2 );
650 int merge ( Image *dst, Image *src, int feather, int showprogress, int seam );
651 void mergeAlpha ( Image *im, unsigned char *alpha, int feather, PTRect *theRect );
652 void SetEquColor ( cPrefs *p );
653 void CopyPosition ( Image *to, Image *from );
654 int isColorSpecific ( cPrefs *p );
655 void ThreeToFourBPP ( Image *im );
656 void FourToThreeBPP ( Image *im );
657 int SetUpGamma ( double pgamma, int psize);
658 int cutTheFrame ( Image *dest, Image *src, int width, int height, int showprogress );
659 int PositionCmp ( Image *im1, Image *im2 );
660 int MorphImage ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
661 int MorphImageFile ( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
662 int blendImages ( fullPath *f0, fullPath *f1, fullPath *result, double s );
663 int InterpolateImage ( Image *src, Image *dst, PTTriangle *ts, PTTriangle *td, int nt );
664 int InterpolateTrianglesPerspective( AlignInfo *g, int nIm, double s, PTTriangle** t );
665 int InterpolateImageFile( fullPath *sfile, fullPath *dfile, AlignInfo *g,int nIm );
666 void OneToTwoByte ( Image *im );
667 void TwoToOneByte ( Image *im );
668 void SetMakeParams ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
669 void SetInvMakeParams ( struct fDesc *stack, struct MakeParams *mp, Image *im , Image *pn, int color );
670 void GetControlPointCoordinates(int i, double *x, double *y, AlignInfo *gl );
673 // Script Reading/Parsing/Writing
675 int ParseScript ( char* script, AlignInfo *gl );
676 void WriteResults ( char* script, fullPath *sfile, AlignInfo *g, double ds( int i) , int launch);
677 int readAdjust ( aPrefs *p, fullPath* sfile , int insert);
678 void readControlPoints (char* script, controlPoint *c );
679 int getVRPanoOptions ( VRPanoOptions *v, char *line );
680 void nextWord ( register char* word, char** ch );
681 void nextLine ( register char* line, char** ch );
682 int numLines ( char* script, char first );
686 void DisposeAlignInfo ( AlignInfo *g );
687 void** mymalloc ( long numBytes ); // Memory allocation, use Handles
688 void myfree ( void** Hdl ); // free Memory, use Handles
689 int SetDestImage ( TrformStr *TrPtr, int width, int height) ;
690 void DisposeMultiLayerImage( MultiLayerImage *mim );
695 void RunLMOptimizer ( OptInfo *g);
696 void RunBROptimizer ( OptInfo *g, double minStepWidth);
697 void RunOverlapOptimizer ( AlignInfo *g);
699 void SetMatrix ( double a, double b, double c , double m[3][3], int cl );
700 void matrix_mult ( double m[3][3], double vector[3] );
701 void matrix_inv_mult ( double m[3][3], double vector[3] );
702 double smallestRoot ( double *p );
703 void SetCorrectionRadius ( cPrefs *cP );
705 void fourier ( TrformStr *TrPtr, cPrefs *cP );
706 unsigned short gamma_correct( double pix );
707 int EqualCPrefs( cPrefs *c1, cPrefs *c2 );
708 double OverlapRMS ( MultiLayerImage *mim );
709 double distSquared ( int num );
711 void doCoordinateTransform( CoordInfo *c, tMatrix *t );
712 void findOptimumtMatrix( transformCoord *tP, tMatrix *tM, lmfunc f);
713 int SolveLinearEquation2( double a[2][2], double b[2], double x[2] );
714 void SortControlPoints( AlignInfo *g , int nIm);
715 void noisefilter ( Image *dest, Image *src );
716 void fwiener ( TrformStr *TrPtr, Image *nf, Image *psf, double gamma, double frame );
720 int PointInTriangle( double x, double y, PTTriangle *T, double c[2] );
721 int SetSourceTriangles( AlignInfo *g, int nIm, PTTriangle** t );
722 int SetDestTriangles( AlignInfo *g, int nIm, PTTriangle** t );
723 int InterpolateTriangles( AlignInfo *g, int nIm, double s, PTTriangle** t );
724 int DelaunayIteration( AlignInfo *g, int nIm );
725 int PointInCircumcircle( double x, double y, PTTriangle *tC );
726 int TriangulatePoints( AlignInfo *g, int nIm );
727 int AddTriangle( triangle *t, AlignInfo *g );
728 int RemoveTriangle( int nt, AlignInfo *g );
729 void OrderVerticesInTriangle( int nt, AlignInfo *g );
730 void SetTriangleCoordinates( triangle *t, PTTriangle *tC, AlignInfo *g );
731 int TrianglesOverlap( PTTriangle *t0, PTTriangle *t1 );
732 int LinesIntersect( PTLine *s0, PTLine *s1) ;
733 double PTDistance( PTPoint *s0, PTPoint *s1 );
734 int PTPointInRectangle( PTPoint *p, PTLine *r );
735 int PTElementOf( double x, double a, double b );
736 int PTNormal( double *a, double *b, double *c, PTLine *s );
737 int PTGetLineCrossing( PTLine *s0, PTLine *s1, PTPoint *ps );
738 int ReduceTriangles( AlignInfo *g, int nIm );
739 double PTAreaOfTriangle( PTTriangle *t );
740 int normalToTriangle( CoordInfo *n, CoordInfo *v, triangle *t );
745 double GetBlendfactor( int d, int s, int feather );
751 void execute_stack ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
753 void resize ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
754 void shear ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
755 void horiz ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
756 void vert ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
757 void radial ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
760 void persp_sphere ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
761 void persp_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
764 void rect_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
765 void pano_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
766 void pano_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
767 void erect_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
768 void sphere_cp_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
769 void sphere_tp_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
770 void erect_sphere_cp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
771 void rect_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
772 void sphere_tp_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
773 void sphere_cp_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
774 void rect_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
775 void erect_rect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
776 void erect_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
777 void mirror_erect ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
778 void mirror_sphere_cp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
779 void mirror_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
780 void sphere_cp_mirror ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
781 void sphere_tp_pano ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
783 void pano_sphere_tp ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
785 void rotate_erect ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
786 void inv_radial ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
788 void vertical ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
789 void inv_vertical ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
790 void deregister ( double x_dest, double y_dest, double* x_src, double* y_src, void* params );
791 void tmorph ( double x_dest,double y_dest, double* x_src, double* y_src, void* params );
795 unsigned char radlum ( unsigned char srcPixel, int xc, int yc, void *params );
798 extern TrformStr *gTrPtr;
799 extern sPrefs *gsPrPtr;
804 // Endian stuff: Read and write numbers from and to memory (ptr)
807 #define LONGNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[0]; \
808 *ptr++ = ((char*)(&number))[1]; \
809 *ptr++ = ((char*)(&number))[2]; \
810 *ptr++ = ((char*)(&number))[3];
812 #define NUMBERLONG( number, ptr ) ((char*)(&number))[0] = *ptr++; \
813 ((char*)(&number))[1] = *ptr++; \
814 ((char*)(&number))[2] = *ptr++; \
815 ((char*)(&number))[3] = *ptr++;
817 #define SHORTNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[0]; \
818 *ptr++ = ((char*)(&number))[1]; \
820 #define NUMBERSHORT( number, ptr ) ((char*)(&number))[0] = *ptr++; \
821 ((char*)(&number))[1] = *ptr++; \
824 #define LONGNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[3]; \
825 *ptr++ = ((char*)(&number))[2]; \
826 *ptr++ = ((char*)(&number))[1]; \
827 *ptr++ = ((char*)(&number))[0];
829 #define NUMBERLONG( number, ptr ) ((char*)(&number))[3] = *ptr++; \
830 ((char*)(&number))[2] = *ptr++; \
831 ((char*)(&number))[1] = *ptr++; \
832 ((char*)(&number))[0] = *ptr++;
834 #define SHORTNUMBER( number, ptr ) *ptr++ = ((char*)(&number))[1]; \
835 *ptr++ = ((char*)(&number))[0]; \
837 #define NUMBERSHORT( number, ptr ) ((char*)(&number))[1] = *ptr++; \
838 ((char*)(&number))[0] = *ptr++; \
844 // Cross platform file functions
851 #define file_spec short
852 #define myopen( path, perm, fspec ) ( FSpOpenDF( path, perm, &fspec ) != noErr )
853 #define mywrite( fspec, count, data ) FSWrite (fspec, &count, data)
854 #define myread( fspec, count, data ) FSRead (fspec, &count, data)
855 #define myclose( fspec ) FSClose (fspec )
856 #define mycreate( path, creator, type ) FSpCreate( path, creator, type,0)
857 #define mydelete( path ) FSpDelete( path )
858 #define myrename( path, newpath ) FSpRename (path, (newpath)->name)
859 #define write_text fsWrPerm
860 #define write_bin fsWrPerm
861 #define read_text fsRdPerm
862 #define read_bin fsRdPerm
863 #define read_write_text fsRdWrPerm
865 #else // __Mac__, use ANSI-filefunctions
866 #define file_spec FILE*
867 #define myopen( path, perm, fspec ) ( (fspec = fopen( (path)->name, perm )) == NULL)
868 #define mywrite( fspec, count, data ) count = fwrite( data, 1, count, fspec)
869 #define myread( fspec, count, data ) count = fread( data, 1, count, fspec )
870 #define myclose( fspec ) fclose (fspec )
871 #define mycreate( path, creator, type )
872 #define mydelete( path ) remove((path)->name )
873 #define myrename( path, newpath ) rename ((path)->name, (newpath)->name)
874 #define write_text "w"
875 #define write_bin "wb"
876 #define read_text "r"
877 #define read_bin "rb"
878 #define read_write_text "rw"