home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / VideoToolbox.h < prev    next >
Encoding:
Text File  |  1993-12-29  |  33.2 KB  |  981 lines  |  [TEXT/KAHL]

  1. /*
  2. VideoToolbox.h
  3. This file contains the necessary prototypes for use of all the VideoToolbox
  4. files except Luminance.c, which has its own header file, Luminance.h, and
  5. GDInfo.c and GDTestClut.c, which use GDInfo.h.
  6.  
  7. Precompilation of this header, producing either VideoToolbox.pre or
  8. VideoToolboxMATLAB.pre, will reduce your compilation time tenfold. See
  9. VideoToolbox.c or VideoToolboxMATLAB.c for instructions.
  10.  
  11. Header files whose precompilation depends on the mc68881 or mc68020 THINK C
  12. compiler options (e.g. math.h and mc68881.h) were omitted from VideoToolbox.h so
  13. that the resulting precompiled header file can be used in projects regardless of
  14. those options. (You’ll want them enabled for speed in your lab, but you’ll
  15. usually want them disabled for portability on the road, e.g. the PowerBook 160
  16. has no floating point unit.) If you change other options that affect the
  17. pre-compilation of the headers (e.g. size of double or size of int) you should
  18. rebuild the precompiled header file, to reflect the new settings.
  19.  
  20. MAC_C:
  21.  
  22. The Apple Macintosh header files use some extensions to C that are not part of
  23. Standard C, e.g. "pascal", "short double", enums larger than ints, and function
  24. prototypes that specify absolute addresses. These keywords and constructions
  25. cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
  26. only on Macintosh C compilers that incorporate these extensions, and is false
  27. otherwise. The MAC_C symbol is used to prevent inclusion of all the
  28. Macintosh-dependent header files and prototypes when the compiler doesn't
  29. support them. However, lacking any general test for these extensions, a test
  30. must be added, below, for each compiler. At present we only test Symantec's THINK C
  31. compiler and Apple's MPW C compiler.
  32.  
  33. MATLAB:
  34.  
  35. The VideoToolbox sources can be linked to create a stand-alone C application, or
  36. a MATLAB external code resource (a "MEX" file), to be invoked by typing the
  37. function name from within MATLAB. In that case we call the THINK C project a
  38. "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
  39. every C file, must #include the VideoToolbox.h header at the beginning of every
  40. C file, and must #include MATLABMain.h in the main C file.
  41.  
  42. Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
  43. window instead. E.g. you could type
  44.     #define MATLAB 1
  45. into the Prefix window, or, more conveniently (because it speeds up your
  46. compilations enormously), type
  47.     #include "VideoToolboxMATLAB.pre"
  48. See VideoToolboxMATLAB.c for instructions.
  49.  
  50. The MATLABMain.h header allocates space for QuickDraw globals for use by THINK C
  51. MATLAB projects. It should be #included in the main C file of each THINK C
  52. MATLAB project, i.e. in the C file that contains "main" or "user_fcn". It must
  53. be included in exactly one source file of each project, as the THINK C Linker
  54. will otherwise complain.
  55.  
  56. dgp & dhb.
  57. Copyright 1989-1993 © Denis G. Pelli
  58.  
  59. HISTORY: (omitting changes documented in C files)
  60. 2/20/93 dhb    Added various commonly used headers.  
  61.             Restructured so that only VideoToolbox.h has to be included,
  62.             whether one is creating stand-alone THINK C or code resources
  63.             to be called by MATLAB. Everything that cares is properly conditioned
  64.             by the symbol MATLAB.
  65. 7/9/93    dgp    Changed our convention for the MATLAB symbol, defining it as
  66.             1 or 0 instead of defining or leaving undefined. The advantage of
  67.             this approach is that "MATLAB" can now be used as an argument in an
  68.             ordinary if statement, which is much more readable than #if.
  69. 8/21/93    dhb    Added undefs in #if MATLAB so that memory allocation goes through THINK C 
  70.             library, not as callback. Callbacks would be OK except that the Mathworks 
  71.             forgot to give us one for realloc. This leads to mixing memory managers
  72.              on the same pointers -- bad bad bad.
  73. 9/2/93    dhb    commented out #include <TranslateLinefeeds.h> since it's
  74.             not presently compatible with MATLAB.
  75. 9/2/93    dgp    Moved the NL and NEWLINE macros from Assign.c into this file.
  76. 9/8/93    dgp    Mention VideoToolbox.c.
  77. 9/11/93    dhb,dgp    Define STDIO_INT and STDIO_DOUBLE.
  78. 9/12/93    dhb    Change STDIO_... to PRINTF_... and SCANF_...
  79.             Insert conditional for MATLAB 3.5 vs. 4.x
  80. 9/14/93    dhb    Conditional for MATLAB changed to make symbol match major version number.
  81.             Removed traces of old trying to force 4 byte ints for MATLAB.
  82. 9/14/93    dgp    Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
  83.             requires it. Fixed typo, changing "#elseif" to "#elif".
  84. 9/15/93    dgp    Edited the comments above, referring to VideoToolbox.c and the new 
  85.             VideoToolboxMATLAB.c.
  86. 9/16/93    dgp    Added contents of former Assign.h.
  87.             Defined MAC_C so that the VideoToolbox.h header may be used with
  88.             Standard C.
  89. 9/16/93    dhb Removed prototype for obsolete GetDateTimeString.
  90. 10/2/93    dgp    Added #include <Errors.h>.
  91. 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
  92. 12/16/93 dhb Somewhere things got munged.  Conditional for MATLAB version appeared
  93.            before inclusion of cmex, which won't work.  I fixed the order.
  94. 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below.  This
  95.            generates a link error from MATLAB.
  96. 12/29/93 dgp added #include <Packages.h>
  97. */
  98. #pragma once            /*  suppress multiple inclusions of this file */
  99. #ifndef _VIDEOTOOLBOX_    /*  suppress multiple inclusions of this file */
  100. #define _VIDEOTOOLBOX_
  101. /*
  102. Header files that are required for successful compilation of the rest of this
  103. file are marked "required".
  104. */
  105. #if defined(THINK_C) && __option(thinkc)    /* THINK C with Mac extensions */    \
  106.     || defined(applec)                        /* MPW C, presumably with Mac extensions */
  107.     #define MAC_C 1        /* allow Macintosh C extensions: "pascal", "short double", etc. */
  108. #else
  109.     #define MAC_C 0
  110. #endif
  111. #ifndef SHORT_DOUBLE_OK
  112.     #define SHORT_DOUBLE_OK MAC_C    /* "short double" not allowed by Standard C */
  113. #endif
  114. #include <stdio.h>            /*  required */
  115. #include <stdlib.h>
  116. #if MAC_C
  117.     #include <QuickDraw.h>    /*  required */
  118. #endif
  119. #ifndef MATLAB
  120.     #define MATLAB 0
  121. #endif
  122. #if MATLAB
  123.     /*
  124.     This must come after stdlib.h, stdio.h, and QuickDraw.h and before everything
  125.     else. If MATLAB is true then we include the header file cmex.h.  Otherwise we
  126.     define the data types that are normally provided by that header, so that code
  127.     that uses these types may be compiled for use in applications.  It must come
  128.     before we test for version 3 or 4.  The version 3 cmex.h does not define the
  129.     symbol mex_h; version 4 does.  This is what we use to figure out which
  130.     version we are compiling for.  Sound complicated?  Sigh!
  131.     */
  132.     
  133.     #include <cmex.h>
  134.     // Test for MATLAB 4 or MATLAB 3, and set symbol appropriately.
  135.     #undef MATLAB
  136.     #ifdef mex_h
  137.         #define MATLAB 4
  138.     #else
  139.         #define MATLAB 3
  140.     #endif
  141.     #ifndef MAC_C
  142.         #error "MATLAB requires the Macintosh extensions to C."
  143.     #endif
  144.  
  145.     // Undefine the macros that override memory allocation.  MATLAB's implementation
  146.     // doesn't work if you use realloc.
  147.     #undef malloc
  148.     #undef calloc
  149.     #undef free
  150.     
  151.     // Define data types for printf, scanf.
  152.     #if (MATLAB == 4)                        /* Version 4 */
  153.         typedef int PRINTF_INT;                /* type of arguments to printf et al. */
  154.         typedef long double PRINTF_DOUBLE;
  155.         typedef int SCANF_INT;                /* type of arguments to scanf et al. */
  156.         typedef double SCANF_DOUBLE;
  157.     #elif (MATLAB == 3)                        /* Version 3.5 */
  158.         typedef long int PRINTF_INT;        /* type of arguments to printf et al. */
  159.         typedef double PRINTF_DOUBLE;
  160.         typedef short int SCANF_INT;        /* type of arguments to scanf et al. */
  161.         typedef long double SCANF_DOUBLE;    
  162.     #endif
  163.     #ifdef THINK_C    /* Declare our own QuickDraw globals, allocated by MATLABMain.h */
  164.         extern THINK_C_QD mex_qd;
  165.         #define qd mex_qd
  166.     #else
  167.         #define mex_qd qd
  168.     #endif
  169.     #if defined(MAIN)                        /* Some old programs #define MAIN. */
  170.         #include "MATLABMain.h"                /* New programs just #include directly. */
  171.     #endif
  172. #else
  173.     typedef long int INT;
  174.     #if SHORT_DOUBLE_OK
  175.         typedef short double DOUBLE;/* not allowed by Standard C */
  176.     #endif
  177.     typedef int PRINTF_INT;            /* type of arguments to printf et al. */
  178.     typedef double PRINTF_DOUBLE;
  179.     typedef int SCANF_INT;            /* type of arguments to scanf et al. */
  180.     typedef double SCANF_DOUBLE;
  181.     #if SHORT_DOUBLE_OK
  182.         typedef struct {
  183.             char *name;
  184.             INT type;
  185.             INT m;
  186.             INT n;
  187.             DOUBLE *pr;
  188.             DOUBLE *pi;
  189.         } Matrix;
  190.     #endif
  191. #endif
  192.  
  193. /*  Standard C headers */
  194. #include <ctype.h>
  195. #include <float.h>
  196. #include <limits.h>
  197. #include <string.h>
  198. #include <time.h>
  199.  
  200. /*  Macintosh headers */
  201. #if MAC_C
  202.     #if THINK_C
  203.         #include <console.h>
  204.     #endif
  205.     #include <Devices.h>
  206.     #include <Errors.h>
  207.     #include <Events.h>
  208.     #include <FixMath.h>    /*  Must come before mc68881.h */
  209.     #include <Fonts.h>
  210.     #include <GestaltEqu.h>
  211.     #include <Memory.h>
  212.     #include <OSEvents.h>
  213.     #include <OSUtils.h>    /*  required */
  214.     #include <Packages.h>
  215.     #include <Palettes.h>    /*  formerly Palette.h */
  216.     #if THINK_C
  217.         #include <pascal.h>    /*  c2pstr(),CtoPStr() */
  218.         #include <profile.h>/* only needed if you want timing info */
  219.     #endif
  220.     #include <QDOffscreen.h>/*  formerly QuickDraw32Bit.h */
  221.     #include <Resources.h>
  222.     #include <Retrace.h>    /*  required */
  223.     #include <Slots.h>
  224.     #include <Sound.h>
  225.     #ifndef THINK_C            /*  e.g. MPW C */
  226.         #include <Strings.h>/*  c2pstr(),CtoPStr() */
  227.     #endif
  228.     #include <Timer.h>        /*  required */
  229.     #include <ToolUtils.h>
  230.     #include <Video.h>
  231.     #include <Windows.h>    /*  required */
  232. #endif
  233.  
  234. /*
  235. MATLAB AND THE NEWLINE CHARACTER
  236. In most C environments the newline character is '\n' (ascii 10). In Apple's
  237. wisdom they chose to separate lines in Macintosh files with the ascii 13
  238. character, which is usually called the return character '\r'. Standard C
  239. specifies that the stdio library will use '\n' as the newline character. This
  240. potentially creates a compatibility problem between Mac C programs and C
  241. programs written for the rest of the world's computers, since one wants any text
  242. files they produce to be appropriate to the local environment. Both MPW and
  243. THINK C resolve the problem behind the scenes, but they do it in different ways.
  244. MPW redefines the association between symbolic names and character codes, making
  245. '\n' be 13 and '\r' be 10. THINK C instead modifies the stdio library so that
  246. reads and writes to a "text" (i.e. not binary) stream are translated, exchanging
  247. character codes 10 and 13. Both solutions work. However, when we use THINK C to
  248. create code resources for MATLAB we are forced to use the MPW stdio library that
  249. is built into MATLAB. Unfortunately this bypasses both compilers' fixes to the
  250. newline problem. The problem affects every single text i/o operation, e.g. every
  251. printf and scanf. Alas, there is no way to get the pre-processor to redefine /n
  252. and /r.
  253.  
  254. We have attempted two solutions: a quick fix, using macros NL and NEWLINE, and a
  255. complete clean fix, using TranslateLinefeeds.c. At present only the quick fix
  256. works.
  257.  
  258. Our quick fix is to create a macro called NL that is normally defined as the
  259. newline string "\n", but which is instead defined as "\015" (i.e. ascii 13) when
  260. MATLAB is true. Programs such as Assign.c that have replaced all instances of
  261. "\n" by NL will then work whether or not MATLAB is true. The obvious drawback is
  262. that this quick solution requires these modifications to the source files.
  263.  
  264. The clean relatively complete solution is to insert a filter,
  265. TranslateLinefeeds.c, that intercepts the calls to the stdio library and
  266. translates /r to /n and vice versa for i/o to text files. The header file
  267. TranslateLinefeeds.h redefines all the stdio calls as macros that call
  268. corresponding routines within TranslateLinefeeds.c. Note that scanf is not
  269. intercepted and that for printf (and fprintf, ...) only the format string
  270. is translated; linefeeds hiding in char or string arguments in the variable
  271. part of the argument list are not be translated.
  272. */
  273. #if MATLAB && THINK_C            /* Clean, relatively complete solution */
  274.     //#include <TranslateLinefeeds.h>
  275. #endif
  276. #if !defined(_TranslateLinefeeds_) && MATLAB && THINK_C    /* Quick fix */
  277.     #define NL "\r"
  278.     #define NEWLINE '\r'
  279. #else
  280.     #define NL "\n"        /* the standard new-line string */
  281.     #define NEWLINE '\n'
  282. #endif
  283.  
  284. /*
  285. TRUE and FALSE
  286. */
  287. #ifndef TRUE
  288.     #define FALSE    0
  289.     #define TRUE    1
  290. #endif
  291.  
  292. /*
  293. NAN & INF
  294. If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
  295. IsFinite() definitions & prototypes below. Note that the THINK C compiler is
  296. timid, worried about possible exception events, so the INF and NAN expressions
  297. below are evaluated at runtime. (Drat!) If you use these expressions in a tight
  298. loop, you'd be better off putting the value in a variable (preferably a
  299. register) and using that instead.
  300. */
  301. #if !defined(INF)
  302.     #define INF    (1.0/0.0)        /* Infinity */
  303. #endif
  304. #if !defined(NAN)
  305.     #define NAN    (0.0/0.0)        /* Not a Number */
  306. #endif
  307.  
  308. /*
  309. NUMERICAL CONSTANTS
  310. It's sad to say, but THINK C 5.02 loses two bits of precision converting between
  311. doubles and ascii text, in either direction. Thus you will obtain more accurate
  312. results by computing the numerical constants below at runtime rather than using
  313. these predefined constants. The ANSI Numerical C Extensions group is moving to
  314. require C compilers to preserve precision, so there is hope for the future. Of
  315. course most applications would never notice a loss of two bits precision out of
  316. the total double precision given by the 64 bits in the mantissa.
  317. */
  318. #if !defined(PI)
  319.     #define PI        3.1415926535897932385    /* computed in Mathematica */
  320. #endif
  321. #if !defined(LOGPI)
  322.     #define LOGPI    1.14472988584940017414    /* computed in Mathematica */
  323. #endif
  324. #if !defined(LOG2)
  325.     #define LOG2    0.69314718055994530942    /* computed in Mathematica */
  326. #endif
  327. #if !defined(LOG10)
  328.     #define LOG10    2.30258509299404568402    /* computed in Mathematica */
  329. #endif
  330.  
  331. #if MAC_C
  332.     /*
  333.     CLUTSIZE
  334.     Inline code that returns the same answer as GDClutSize(device).
  335.     */
  336.     #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
  337.     
  338.     /*  Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
  339.     /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
  340. #endif
  341.  
  342. /*
  343. FIXED POINT ARITHMETIC
  344. Apple defines a handy data type called Fixed that is stored in a long, but is
  345. assumed to have a decimal point in the middle. Many operations, e.g. adding two
  346. Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
  347. directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
  348. FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
  349. compilers define double in various ways, depending on whether a floating point
  350. unit is to be used. The Apple-provided routines for doing type conversion to and
  351. from Fixed are only appropriate if you are NOT using the floating point unit.
  352. The ones defined below are faster and work with or without the FPU.
  353. */
  354. #define LongToFix(x) ((long)(x)<<16)
  355. #define FixToLong(x) ((x)>>16)
  356. #define DoubleToFix(x) ((long)((x)*65536.+0.5))
  357. #define FixToDouble(x) ((double)(x)*(1./65536.))
  358.  
  359. #if MAC_C
  360.     /*
  361.     STACK
  362.     StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
  363.     Apple's StackSpace(), declared in Memory.h, that returns the number of bytes 
  364.     allocated for the stack.
  365.     */
  366.     #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
  367. #endif
  368.  
  369. /* Assign.c */
  370.  
  371. #define ASSIGN_DIMS 3        /* Feel free to increase or decrease ASSIGN_DIMS. */
  372. typedef struct {
  373.     short type;
  374.     unsigned sizedOnce:1;    /* dim[] is meaningful */
  375.     unsigned sized:1;        /* dim[] is final */
  376.     unsigned malloced:1;    /* allocated by malloc */
  377.     char *name;
  378.     void *ptr;                /* for array, address of element zero */
  379.     long dim[ASSIGN_DIMS];    /* zero indicates a scalar */
  380.     long firstElement;        /* for 1-d array, index of first array element. Usually 0 */
  381.     const char *comment;    /* text string, or NULL */
  382. } Description;
  383. enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
  384.     ,assignNoComment=8,assignNoPrintfExit=0x10
  385.     ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
  386. };
  387. enum {assignMemoryError=-1,assignTypeError=-2
  388.     ,assignVariableError=-3,assignUnknownVariableError=-4
  389.     ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
  390.     ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
  391.     ,assignSemicolonError=-10,assignFileError=-11
  392.     ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
  393.     ,assignInconsistentDimensionsError=-14
  394.     ,assignCouldntFindDescription=-15
  395. };
  396. enum{charType=1,unsignedCharType,shortType,unsignedShortType
  397.     ,longType,unsignedLongType
  398.     ,floatType
  399.     #if SHORT_DOUBLE_OK
  400.         ,shortDoubleType
  401.     #endif
  402.     ,doubleType
  403.     ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
  404.     ,longPtrType,unsignedLongPtrType
  405.     ,floatPtrType
  406.     #if SHORT_DOUBLE_OK
  407.         ,shortDoublePtrType
  408.     #endif
  409.     ,doublePtrType
  410.     ,stringType,unknownType
  411. };
  412. FILE *OpenCalFileRead(char *filename);
  413. FILE *OpenCalFileReadAndCheck(char *filename);
  414. FILE *OpenCalFileWrite(char *filename);
  415. void AppendDescriptions(Description **d,Description *s);
  416. void CopyDescriptions(Description *d,Description *s);
  417. Description *AllocateDescriptions(long n);
  418. void FreeDescriptions(Description *d);
  419. long NumberOfDescriptions(Description *d);
  420. Description NullDescription(void);
  421. int IsNullDescription(Description d);
  422. #define IsNullDescription(d) ((d).type==0)
  423. int AssignmentLineWasBlank(void);
  424. int UnequalDescribedVars(Description d1[],Description d2[],short flags);
  425. int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
  426. long InitializeADescribedVar(Description *d,short flags);
  427. long InitializeDescribedVars(Description d[],short flags);
  428. long FindDescribedDim(Description d[],void *ptr,int i,short flags);
  429. long FindDescription(Description d[],void *ptr,short flags);
  430. void FreeADescribedVar(Description *d,short flags);
  431. void FreeDescribedPtrVars(Description d[],short flags);
  432. void FreeDescribedVars(Description d[],short flags);
  433. void KeepDescribedVars(Description d[],short flags);
  434. void KeepADescribedVar(Description *d,short flags);
  435. long PrintAnAssignment(FILE *stream,Description *d,short flags);
  436. long PrintAssignments(FILE *stream,Description d[],short flags);
  437. long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
  438. long ReadAssignmentLine(FILE *stream,Description d[],short flags);
  439. long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
  440. long ReadAssignmentStream(FILE *stream,Description d[],short flags);
  441. long ReadAssignmentFile(const char *filename,Description d[],short flags);
  442. Description Describe(short type,void *ptr,char *name,const char *comment);
  443. Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
  444. Description DescribeFirstLast(short type,void *ptr,char *name
  445.     ,const char *comment,long firstElement,long lastElement);
  446.  
  447. /* Binomial.c */
  448.  
  449. long    BinomialSample(double p,long n);
  450. int        BinomialSampleQuickly(int n);
  451. double    BinomialLowerBound(double P,long k,long n);
  452. double    BinomialUpperBound(double P,long k,long n);
  453. double    BinomialPdf(double p,long k,long n);
  454. double    Binomial(double p,long k,long n);
  455. double    IncompleteBeta(double x,double a,double b);
  456. double    InverseBinomial(double P,long k,long n);
  457. double    InverseIncompleteBeta(double p,double a,double b);
  458.  
  459. /* BreakLines.c */
  460.  
  461. char *BreakLines(char *string,long lineLength);
  462. void PrintWrappedText(FILE *stream,const char *s);
  463. void PrintWrappedTextToFile(const char *filename,const char *s);
  464. void PrintWrappedComment(FILE *stream,const char *s);
  465. void PrintWrappedCommentToFile(const char *filename,const char *s);
  466.  
  467. #if MAC_C
  468.     /* CardSlot.c */
  469.     
  470.     OSErr    CardSlot(char *cardName);
  471.     
  472.     /* CenterRectInRect.c */
  473.     
  474.     void    CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
  475.     void    OffsetRectTile(Rect *r,int nx,int ny);
  476.     Boolean    RectInRect(Rect *r,Rect *R);
  477. #endif
  478.  
  479. /* ChiSquare.c */
  480.  
  481. double    PChiSquare (double chiSquare,int n);
  482.  
  483. #if MAC_C
  484.     /* ConvolveX.c */
  485.     
  486.     void    ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  487.                 Rect *srcRectPtr,Rect *dstRectPtr);
  488.  
  489.     /* ConvolveY.c */
  490.     
  491.     void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  492.                 Rect *srcRectPtr,Rect *dstRectPtr);
  493.     
  494.     /* CopyBitsQuickly.c */
  495.     
  496.     enum{mulOver=128};
  497.     int    CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits,
  498.                 Rect *srcRectPtr,Rect *dstRectPtr,int srcMode,RgnHandle maskRgn);
  499.     
  500.     /* CopyQuickDrawGlobals.c */
  501.     
  502.     void CopyQuickDrawGlobals(void);
  503.     #define CopyQuickdrawGlobals CopyQuickDrawGlobals    /*  old spelling */
  504.     
  505.     /* CreateTrialSnds.c */
  506.     
  507.     void CreateTrialSnds(void);
  508. #endif
  509.  
  510. /* DateString.c */
  511.  
  512. char    *DateString(unsigned long seconds);
  513.  
  514. #if MAC_C
  515.     /* DrawPrintf.c */
  516.     
  517.     void DrawPrintf(char *s, ...);
  518. #endif
  519.  
  520. /* Exponential.c */
  521.  
  522. double ExponentialPdf(double x);
  523.  
  524. /* ffprintf.c */
  525.  
  526. int ffprintf(FILE *stream[2],char *format,...);
  527.  
  528. #if MAC_C
  529.     /* FlushCacheRange.c */
  530.     
  531.     void FlushCacheRange (void *address, unsigned long count);
  532.     
  533.     /* GDOpenWindow.c */
  534.     
  535.     void AddExplicitPalette(WindowPtr window);
  536.     WindowPtr GDOpenWindow1(GDHandle device);
  537.     void GDDisposeWindow1(WindowPtr window);
  538.     CWindowPtr GDOpenWindow(GDHandle device);                    /*  Old. Use GD...1 instead. */
  539.     void GDDisposeWindow(GDHandle device,CWindowPtr myWindow);    /*  Old. Use GD...1 instead. */
  540.     
  541.     /* GDPrintf.c */
  542.     
  543.     void    GDPrintf(char *s, ...);
  544.     
  545.     /* GDTime.c */
  546.     
  547.     double GDFrameRate(GDHandle device);
  548.     double GDMovieRate(GDHandle device,int quickly);
  549.     double GDMovieSize(GDHandle device,int quickly);
  550.     double GDVBLRate(GDHandle device);
  551.     double TickRate(void);
  552.     typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
  553.         ,ColorSpec *aTable);
  554.     OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
  555.         ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
  556.     
  557.     /* GDVideo.c */
  558.     
  559.     #define MAX_SCREENS 8
  560.     char  *GDCardName(GDHandle device);
  561.     extern short gdClutSizeTable[33];
  562.     short GDClutSize(GDHandle device);
  563.     long GDColors(GDHandle device);
  564.     OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
  565.     short GDDacSize(GDHandle device);
  566.     OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  567.     OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
  568.     OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
  569.     OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  570.     OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
  571.     OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
  572.     OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
  573.     OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  574.     OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
  575.     OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
  576.     OSErr GDGrayPage(GDHandle device,short page);
  577.     Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
  578.     #define GDLinearGamma GDUncorrectedGamma /* old name, before 12/16/92 */
  579.     short GDModePixelSize(GDHandle device,short mode);
  580.     unsigned char *GDName(GDHandle device);
  581.     ColorSpec *GDNewLinearColorTable(GDHandle device);
  582.     short GDPixelSize(GDHandle device);
  583.     OSErr GDPrintGammaTable(FILE *o,GDHandle device);
  584.     OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  585.     OSErr GDRestoreDeviceClut(GDHandle device);
  586.     OSErr GDRestoreGamma(GDHandle device);
  587.     OSErr GDSaveGamma(GDHandle device);
  588.     OSErr GDSetDefaultMode(GDHandle device,short mode);
  589.     OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  590.     OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
  591.     OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
  592.         ,ColorSpec *table);
  593.     OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
  594.     OSErr GDSetGray(GDHandle device,Boolean flag);
  595.     OSErr GDSetInterrupt(GDHandle device,Boolean flag);
  596.     OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
  597.     OSErr GDSetPageDrawn(GDHandle device,short page);
  598.     OSErr GDSetPageShown(GDHandle device,short page);
  599.     OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
  600.     short GDType(GDHandle device);
  601.     OSErr GDUncorrectedGamma(GDHandle device);
  602.     int  GDVersion(GDHandle device);
  603.     #define ModeName GDModeName   /* old name, before 1/18/93 */
  604.     int  PatchMacIIciVideoDriver(void);
  605.     
  606.     /* GetClicks.c */
  607.     
  608.     short    GetClicks(void);
  609. #endif
  610.  
  611. /* GetTimeDateString.c */
  612.  
  613. char *GetTimeDateString(time_t t);
  614.  
  615. #if MAC_C
  616.     /* GetVersionString.c */
  617.  
  618.     char *GetVersionString(void);
  619.  
  620.     /* GetScreenDevice.c */
  621.     
  622.     GDHandle    GetScreenDevice(int n);
  623.     int GetScreenIndex(GDHandle device);
  624.     GDHandle    SlotToScreenDevice(int n);
  625.     short int    GetDeviceSlot(GDHandle device);
  626.     GDHandle    GetWindowDevice(WindowPtr theWindow);
  627.     void        LocalToGlobalRect(Rect *r);
  628.     void        GlobalToLocalRect(Rect *r);
  629.  
  630.     /* GetVoltage.c */
  631.     
  632.     double    VoltsDuringFrame(double frames);
  633.     double    GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
  634.                 ,double *sdPtr);
  635.     short    GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
  636.                 ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
  637.     short    InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
  638.                 ,double *voltDeltaPtr,double *voltZeroPtr);
  639.     short    RetrieveVoltages(long *nPtr,unsigned short readings[]);
  640.     int        ForeRunnerSlot(void);
  641.     enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
  642. #endif
  643.  
  644. /* HexToBinary.c */
  645.  
  646. int HexToBinary(char *string,void *ptr);
  647. char *BinaryToHex(size_t n,void *ptr,char *string);
  648.  
  649. #if MAC_C
  650.     /* HideMenuBar.c */
  651.     
  652.     void    HideMenuBar(void);
  653.     void    ShowMenuBar(void);
  654.     void SquareCorners(GDHandle device);
  655.     void RestoreCorners(GDHandle device);
  656.     void UnclipScreen(GDHandle device);
  657.     void RestoreScreenClipping(GDHandle device);
  658.     
  659.     /* Identify.c */
  660.     
  661.     char *IdentifyCompiler(void);
  662.     char *IdentifyMachine(void);
  663.     char *IdentifyModel(void);
  664.     char *IdentifyVideo(GDHandle device);
  665.     
  666.     /* IsCmdPeriod.c */
  667.     
  668.     Boolean IsCmdPeriod(EventRecord *theEvent);
  669. #endif
  670.  
  671. /* IsNan.c */
  672.  
  673. int IsNan(double x);
  674. int IsInf(double x);
  675. #ifndef IsFinite
  676.     #define IsFinite(x) ((*(short *)&(x) & 32767)!=32767)    /* neither NAN nor ±INF */
  677. #endif
  678.  
  679. #if MAC_C
  680.     /* kbhit.c */
  681.     
  682.     int    kbhit(void);
  683.     int    getcharUnbuffered(void);
  684. #endif
  685.  
  686. /* Log2L.c */
  687.  
  688. long Log2L(unsigned long j);
  689.  
  690. #if MAC_C
  691.     /* MakeNoise.c */
  692.     
  693.     Boolean MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *frame);
  694.     void    MakeNoise(double dx,double dy,PixMap frame[],short *maxFramesPtr);
  695.     
  696.     /* MaximizeConsoleHeight.c */
  697.     
  698.     void MaximizeConsoleHeight(void);
  699. #endif
  700.  
  701. /* Mean.c */
  702.  
  703. double    Mean(double x[],long n,double *sdPtr);
  704.  
  705. /* MultipleChoice.c */
  706.  
  707. #if !MAC_C
  708.     #define Boolean unsigned char
  709. #endif
  710. int MultipleChoice(short defaultChoice,short n,char *answer[]);
  711. Boolean YesOrNo(Boolean defaultAnswer);
  712. #if !MAC_C
  713.     #undef Boolean
  714. #endif
  715.  
  716. /* Normal.c */
  717.  
  718. double NormalPdf(double x);
  719. double Normal(double x);
  720. double InverseNormal(double p);
  721. double NormalSample(void);
  722. double Normal2DPdf(double r);
  723. double Normal2D(double r);
  724. double InverseNormal2D(double p);
  725. double Normal2DSample(void);
  726. double InverseNormal2DPdf(double p);
  727.  
  728. /* nrand.c */
  729.  
  730. int nrand(short n);
  731. unsigned short nrandU(unsigned short n);
  732. unsigned long nrandUL(unsigned long n);
  733.  
  734. /* OpenDataFiles.c */
  735.  
  736. unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
  737.                     ,char *inName,char *outName);
  738.  
  739. /* OpenPreferencesFolder.c */
  740.  
  741. #if !MAC_C
  742.     #define OSErr short
  743. #endif
  744. OSErr OpenPreferencesFolder(void);
  745. OSErr ClosePreferencesFolder(void);
  746. OSErr OpenPreferencesWD(short *wdRefNumPtr);
  747. #if !MAC_C
  748.     #undef OSErr
  749. #endif
  750.  
  751. #if MAC_C
  752.     /*    PixMapToPICT.c */
  753.  
  754.     void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  755.         ,int pixelSize,ColorTable **cTable);
  756.  
  757.     /*    PixMapToPostScript.c */
  758.     
  759.     void    PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
  760.                 ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  761.     void    AppendToFile(char *filename,char *string);
  762.     
  763.     /* PlotXY.c */
  764.     
  765.     typedef struct{
  766.         Boolean continuing;    /* zero to start a new curve */
  767.         long color;            /* e.g. blackColor, blueColor */
  768.         short lineWidth;    /* in pixels, zero for none */
  769.         short symbolWidth;    /* in pixels, zero for none */
  770.         short dashOffset;    /* in pixels */
  771.         short dash[5];        /* in pixels. The array is terminated by a zero element */
  772.         short h,v;            /* reserved for internal use */
  773.         Fixed pathLengthF;    /* reserved for internal use */
  774.     } PlotXYStyle;
  775.     void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
  776. #endif
  777.  
  778. /* PrintfExit.c */
  779.  
  780. int PrintfExit(const char *format,...);
  781.  
  782. #if MAC_C
  783.     /* QD32Exists.c */
  784.     
  785.     Boolean         QD8Exists(void);
  786.     Boolean            QD32Exists(void);
  787.     Boolean            NewPaletteManager(void);
  788. #endif
  789.  
  790. /* randU.c */
  791.  
  792. unsigned short    randU(void);
  793. unsigned long    randUL(void);
  794. void            srandU(unsigned n);
  795. void            RandFill(void *address,long bytes);
  796.  
  797. /* ReadMATLABFile.c */
  798.  
  799. int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
  800.     ,double **real,double **imag);
  801. int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
  802.     ,short **real,short **imag);
  803. int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
  804.     ,double **real,double **imag);
  805. int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
  806.     ,short **real,short **imag);
  807. int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
  808. int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
  809.  
  810. #if MAC_C
  811.     /* RectToAddress.c */
  812.     
  813.     unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr, 
  814.         short *pixelSizePtr,short *bitsOffsetPtr);
  815.     Ptr GetPixBaseAddr32(PixMap **pm);
  816. #endif
  817.     
  818. /*    Require.c    */
  819.  
  820. void Require(long quickDrawVersion);
  821. struct PrecompileSizeofInt{
  822.     int i;
  823. };
  824. struct PrecompileSizeofDouble{
  825.     double d;
  826. };
  827.  
  828. #if MAC_C
  829.     /* RestoreCluts.c */
  830.     
  831.     void RestoreCluts(void);
  832.     
  833.     /*    SetEntriesQuickly.c */
  834.     
  835.     OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
  836.     short macltset(GDHandle device,register short start
  837.         ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
  838.     short GetCardType(GDHandle device);
  839.     char *GetCardBase(GDHandle device);
  840.     OSErr WaitForNextBlanking(GDHandle device);
  841.     
  842.     /* SetFileInfo.c */
  843.     
  844.     void    SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
  845.     
  846.     /* SetMouse.c */
  847.     
  848.     void    SetMouse(Point where);
  849.     
  850.     /* SetOnePixel.c */
  851.     
  852.     void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
  853.     unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
  854.     unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
  855.     void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
  856.     unsigned long GetDevicePixel(GDHandle device,int x,int y);
  857.     void SetOnePixel(int x,int y,unsigned long value);
  858.     unsigned long GetOnePixel(int x,int y);
  859.     #define SetIPixel SetDevicePixel    /*  So that old programs won't break. */
  860.     #define GetIPixel GetDevicePixel    /*  So that old programs won't break. */
  861.     
  862.     /* SetPixelsQuickly.c */
  863.     
  864.     int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
  865.     int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
  866.     int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  867.     int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  868.     int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  869.     int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  870.     int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  871.     int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  872.     
  873.     /* SetPriority.c */
  874.     
  875.     void SwapPriority(char *priority);
  876.     void SetPriority(int i);
  877.     int GetPriority(void);
  878. #endif
  879.  
  880. /* Shuffle.c */
  881.  
  882. void    Shuffle(short array[],long size);
  883.  
  884. #if MAC_C
  885.     /* SndPlay1.c */
  886.     
  887.     OSErr SndPlay1(Handle snd);
  888.     void SndStop1(void);
  889.     short SndDone1(void);
  890.  
  891.     /* StringToDate.c */
  892.     
  893.     double StringToDate(char *string,DateTimeRec *date);
  894.  
  895.     /* Timer.c */
  896.     
  897.     struct Timer{
  898.         TMTask time;
  899.         long ourA5;
  900.         long interval,elapsed,elapsedIntervals;
  901.         long timeToStartTimer;            /*  minimum time in µs */
  902.         long stopDelay;                    /*  µs from call to stop, re from call to start */
  903.         long timeManagerVersion;
  904.         struct Timer *next,*previous;    /*  doubly linked list of Timers */
  905.     };
  906.     typedef struct Timer Timer;
  907.     
  908.     Timer *NewTimer(void);
  909.     void DisposeTimer(Timer *t);
  910.     void StartTimer(Timer *t);
  911.     long StopTimer(Timer *t);                    /*  µs */
  912.     double StopTimerSecs(Timer *t);                /*  s */
  913.     
  914.     /* TitleBarHeight.c */
  915.     
  916.     int TitleBarHeight(WindowPtr window);
  917.     
  918.     /* TrapAvailable.c */
  919.     
  920.     Boolean    TrapAvailable(short theTrap);
  921. #endif
  922.  
  923. /* Uniform.c */
  924.  
  925. double UniformSample(void);
  926.  
  927. #if MAC_C
  928.     /* VBLInstall.c */
  929.     
  930.     struct VBLTaskAndA5 {
  931.         volatile VBLTask vbl;
  932.         long ourA5;
  933.         void (*subroutine)(struct VBLTaskAndA5 *vblData);
  934.         GDHandle device;
  935.         long slot;
  936.         volatile long newFrame;                /*  Boolean */
  937.         volatile long framesLeft;            /*  count down to zero */
  938.         long framesDesired;
  939.         Timer *frameTimer;                    /*  time ms since last VBL interrupt, see Timer.c */
  940.         void *ptr;                            /*  use this for whatever you want */
  941.     };
  942.     typedef struct VBLTaskAndA5 VBLTaskAndA5;    
  943.     OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,int frames);
  944.     OSErr VBLRemove(VBLTaskAndA5 *vblData);
  945.     void VBLInterruptServiceRoutine(void);
  946.     void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
  947.     
  948.     /* VideoTFB.c */
  949.     
  950.     Boolean TFBInSlot(int slot);
  951.     void    SetUpTFB(int slot);
  952.     void    RampClutTFB(int slot);
  953.     void    GrayClutTFB(int slot);
  954.     void    LoadClutTFB(int slot,unsigned char rgb[256][3]);
  955.     void    NewBlankingTFB(int slot);
  956.     void    NewFieldTFB(int slot);
  957.     int        BlankingTFB(int slot);
  958.     void    SetDepthTFB(int slot,short int bits);
  959.     void    SynchSetDepthTFB(int masterSlot,int slot,short int bits);
  960.     void    SynchToMainDeviceTFB(GDHandle device);
  961.     void    HaltTFB(int slot);
  962.     void    RestartTFB(int slot,short int bits);
  963.     void    HaltDeviceTFB(GDHandle device);
  964.     void    RestartDeviceTFB(GDHandle device);
  965.     void    ScrollTFB(int slot,short int bits,long x,long y);
  966.     void    PanTFB(int slot,long int x);
  967. #endif
  968.  
  969. /* VLambda.c */
  970.  
  971. double VLambda(double nm);
  972. double VLambdaPrime(double nm);
  973.  
  974. #if MAC_C
  975.     /* Zoom.c */
  976.     
  977.     void Zoom(WindowPtr theWindow,int zoomDir);
  978. #endif
  979.  
  980. #endif /* _VIDEOTOOLBOX_ */
  981.