home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / VideoToolbox / VideoToolboxSources / VideoToolbox.h < prev    next >
Encoding:
Text File  |  1995-10-27  |  46.7 KB  |  1,354 lines  |  [TEXT/CWIE]

  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.pch, or VideoToolbox.c, or VideoToolboxMATLAB.c for instructions.
  10.  
  11. My convention is to assign different names to the precompiled header depending
  12. on the compile-time options: use of ppc/68k, 68881, and size of int.
  13.  
  14. The precompilation depends on the sizeof(double) and sizeof(int)
  15. because most functions use or return such values and the external interface must
  16. allow the appropriate amount of space. THINK C supports a 12-byte "universal"
  17. format double that works well both with the 68881 fpu (which uses the top two
  18. bytes and the bottom 8 bytes) and with SANE (which uses the bottom 10 bytes).
  19. Thus in THINK C it is easy to mix modules compiled with (e.g. your code) and
  20. without (e.g. the ANSI library) the 68881 option. Unfortunately that excellent
  21. feature is unique to THINK C. In MPW and CodeWarrior C you must use 10-byte
  22. doubles when you use SANE (i.e. don't use the 68881 fpu), so when you use these
  23. compilers you'll need separate pre-compiled headers, with and without the 68881
  24. option, if you want to compile for each environment: to use the 68881 fpu, or
  25. run on machines that lack it.
  26.  
  27. Metrowerks CodeWarrior project names end in "µ", and indicate which cpu they
  28. support by "68k" or "ppc". THINK C projects support only the 68k and have names
  29. ending in "π".
  30.  
  31. My naming convention for pre-compiled headers indicates the size of int, "2i" or
  32. "4i", and, if the 68881 is required, "881". Metrowerks pre-compiled headers
  33. indicate which cpu they support by "68k" or "ppc"; THINK C supports only the
  34. 68k. The THINK C pre-compiled header that I use is "VideoToolbox.pre", which
  35. uses 2-byte ints and "universal" 12-byte doubles that work with or without the
  36. 68881. (The THINK C ANSI library requires 2-byte ints.) The Metrowerks
  37. CodeWarrior C pre-compiled headers that I use are called,
  38. "VideoToolbox.68k.4i.pre", "VideoToolbox.68k.4i.881.pre", and
  39. "VideoToolbox.ppc.pre".
  40.  
  41. As of June 14, 1995, the VideoToolbox #includes <assert.h>, or, if MATLAB
  42. is true, defines a MATLAB-compatible version of assert(). If your source file
  43. #includes <assert.h> then it will be included again, which will obviate the work
  44. done here, including the MATLAB compatibility. For that reason you should NOT
  45. #include <assert.h> in your source files.
  46.  
  47. MAC_C:
  48.  
  49. Defining the symbol MAC_C as 0 before this file is compiled will leave only the 
  50. stuff that is written in pure Standard C, which will work on any computer.
  51.  
  52. The Apple Macintosh header files use some extensions to C that are not part of
  53. Standard C, e.g. "pascal", "short double", enums larger than ints, and function
  54. prototypes that specify absolute addresses. These keywords and constructions
  55. cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
  56. only on Macintosh C compilers that incorporate these extensions, and is false
  57. otherwise. The MAC_C symbol is used to prevent inclusion of all the
  58. Macintosh-dependent header files and prototypes when the compiler doesn't
  59. support them. However, lacking any general test for these extensions, a test
  60. must be added, below, for each new compiler. At present we test for Symantec C
  61. THINK C, Apple MPW C, and Metrowerks CodeWarrior C.
  62.  
  63. MATLAB:
  64.  
  65. The VideoToolbox sources can be linked to create a stand-alone C application, or
  66. a MATLAB external code resource (a "MEX" file), to be invoked by typing the
  67. function name from within MATLAB. In that case we call the THINK C project a
  68. "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
  69. every C file, must #include the VideoToolbox.h header at the beginning of every
  70. C file, and must #include MATLABMain.h in the main C file.
  71.  
  72. You must have the file "cmex.h" in order to compile this file when "MATLAB" is true.
  73. "cmex.h" is distributed by MathWorks as part of MATLAB.
  74.  
  75. Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
  76. window instead. E.g. you could type
  77.     #define MATLAB 1
  78. into the Prefix window, or, more conveniently (because it speeds up your
  79. compilations enormously), type
  80.     #include "VideoToolboxMATLAB.pre"
  81. See VideoToolboxMATLAB.c for instructions.
  82.  
  83. The MATLABMain.h header allocates space for QuickDraw globals for use by THINK C
  84. MATLAB projects. It should be #included in the main C file of each THINK C
  85. MATLAB project, i.e. in the C file that contains "main" or "user_fcn". It must
  86. be included in exactly one source file of each project, as the THINK C Linker
  87. will otherwise complain.
  88.  
  89. dgp & dhb.
  90. Copyright 1989-1994 © Denis G. Pelli
  91.  
  92. HISTORY: (omitting changes documented in C files)
  93. 2/20/93 dhb    Added various commonly used headers.  
  94.             Restructured so that only VideoToolbox.h has to be included,
  95.             whether one is creating stand-alone THINK C or code resources
  96.             to be called by MATLAB. Everything that cares is properly conditioned
  97.             by the symbol MATLAB.
  98. 7/9/93    dgp    Changed our convention for the MATLAB symbol, defining it as
  99.             1 or 0 instead of defining or leaving undefined. The advantage of
  100.             this approach is that "MATLAB" can now be used as an argument in an
  101.             ordinary if statement, which is much more readable than #if.
  102. 8/21/93    dhb    Added undefs in #if MATLAB so that memory allocation goes through THINK C 
  103.             library, not as callback. Callbacks would be OK except that the Mathworks 
  104.             forgot to give us one for realloc. This leads to mixing memory managers
  105.              on the same pointers -- bad bad bad.
  106. 9/2/93    dhb    commented out #include <TranslateLinefeeds.h> since it's
  107.             not presently compatible with MATLAB.
  108. 9/2/93    dgp    Moved the NL and NEWLINE macros from Assign.c into this file.
  109. 9/8/93    dgp    Mention VideoToolbox.c.
  110. 9/11/93    dhb,dgp    Define STDIO_INT and STDIO_DOUBLE.
  111. 9/12/93    dhb    Change STDIO_... to PRINTF_... and SCANF_...
  112.             Insert conditional for MATLAB 3.5 vs. 4.x
  113. 9/14/93    dhb    Conditional for MATLAB changed to make symbol match major version number.
  114.             Removed traces of old trying to force 4 byte ints for MATLAB.
  115. 9/14/93    dgp    Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
  116.             requires it. Fixed typo, changing "#elseif" to "#elif".
  117. 9/15/93    dgp    Edited the comments above, referring to VideoToolbox.c and the new 
  118.             VideoToolboxMATLAB.c.
  119. 9/16/93    dgp    Added contents of former Assign.h.
  120.             Defined MAC_C so that the VideoToolbox.h header may be used with
  121.             Standard C.
  122. 9/16/93    dhb Removed prototype for obsolete GetDateTimeString.
  123. 10/2/93    dgp    Added #include <Errors.h>.
  124. 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
  125. 12/16/93 dhb Somewhere things got munged.  Conditional for MATLAB version appeared
  126.            before inclusion of cmex, which won't work.  I fixed the order.
  127. 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below.  This
  128.            generates a link error from MATLAB.
  129. 12/29/93 dgp added #include <Packages.h>
  130. 6/12/94  dgp added definition of Apple's new BlockMoveData, for compatibility with
  131.             Apple's old pre-Universal header files.
  132. 6/12/94    dgp #include Strings.h if Universal header files are used.
  133. 7/28/94 dgp Added test for Metrowerks CodeWarrior C.
  134. 9/2/94    dgp #include MacMemory.h
  135. 9/5/94    dgp changed "int" to "short int" in definitions of PRINTF_INT and SCANF_INT for
  136.             MATLAB 4. This is based on common sense, not testing or detailed knowledge.
  137. 3/31/95    dgp    As a gesture of support for Symantec THINK C 8, now define THINK_C.
  138. 5/26/95 dgp Formerly header files whose precompilation depends on the mc68881 or 
  139.         mc68020 THINK C compiler options (i.e. math.h and mc68881.h) were omitted 
  140.         from VideoToolbox.h so that the resulting precompiled header file could be 
  141.         used in projects regardless of those options. However, for Metrowerks CodeWarrior
  142.         there's no advantage to omitting those headers, and a significant increase in
  143.         compile time, as fp.h is recompiled for each file. Since I've switch to
  144.         CodeWarrior, and expect most other users to switch as well, VideoToolbox.h now
  145.         includes math.h or fp.h.
  146. 5/27/95 dgp removed fp.c prototypes because Apple's fp.h now supports both 68k and ppc.
  147. 6/6/95 dgp discarded all references to TranslateLinefeeds.c and TranslateLinefeeds.h, since
  148.         I never got them to work properly, and I don't think they're needed with Metrowerks
  149.         CodeWarrior.
  150. 6/8/95 dgp Made sure that the MATLAB struct "Matrix" is always native aligned.
  151. 6/13/95 dgp define GENERATING68K, GENERATINGPOWERPC, and GENERATING68881 if not already
  152.         defined (as in Apple's latest universal headers). Define GENERATING68020.
  153. 6/14/95    dhb & dgp redefine the assert() macro, redirecting it to PrintfExit, which
  154.         in turn uses mex_error() to report the error. This is needed to get MEX files
  155.         to link properly.
  156. 6/16/95    dhb Fixed MATLAB's SCANF_INT etc. for __MWERKS__.
  157. 6/16/95 dgp moved the definitions of GENERATING68K to the top of this file, so that
  158.         the MATLAB conditionals can use them.
  159. 6/16/95    dhb    & dgp now #include <assert.h>, unless MATLAB is defined, in which case
  160.         we define a MATLAB-compatible version of the assert macro. Just in case,
  161.         leave NDEBUG defined to disable the standard assert macro which may be
  162.         brought in if the user's source files #include <assert.h>.
  163. 6/16/95    dhb    Fixed longstanding bug (in SCANF_INT??).
  164. 6/23/95    dhb    Include prototypes for AfterDark.c and IsFileSharingOn.c.
  165. 7/19/95 dgp Added changes suggested by Stefan Treue, streue@bcm.tmc.edu, for compatibility
  166.         with Symantec C. Eliminated use of //-style comments. Now include math.h
  167.         when compiling for Standard C, i.e. MAC_C is false.
  168. 8/10/95 dgp Include MacMemory.h ONLY for THINK C, not for Symantec C, since I don't
  169.         have any reason to think that Symantec C memory management is bad.
  170. 8/13/95 dgp Removed definition of THINK_C for SYMANTEC_C. It seems better to leave
  171.         the compiler's macros alone. Changed conditionals throughout the VideoToolbox
  172.         to deal with all the special cases: THINK_C, THINK_CPLUS, and SYMANTEC_C.
  173. */
  174. #pragma once            /*  suppress multiple inclusions of this file */
  175. #ifndef _VIDEOTOOLBOX_    /*  suppress multiple inclusions of this file */
  176. #define _VIDEOTOOLBOX_
  177. /*
  178. Header files that are required for successful compilation of the rest of this
  179. file are marked "required".
  180. */
  181. #if !defined(MAC_C)
  182.     #if THINK_C    || THINK_CPLUS || SYMANTEC_C                            \
  183.         || applec            /* MPW C, presumably with Mac extensions */    \
  184.         || __MWERKS__        /* Metrowerks CodeWarrior C, " */
  185.         /* Set MAC_C to true only if the "pascal" keyword is allowed. */
  186.         #if THINK_C && !SYMANTEC_C
  187.             #if !__option(thinkc)
  188.                 #define MAC_C 0    /* Standard C */
  189.             #endif
  190.         #endif
  191.         #if SYMANTEC_C
  192.             #if __option(ansi_strict)
  193.                 #define MAC_C 0    /* Standard C */
  194.             #endif
  195.         #endif
  196.         #if __MWERKS__
  197.             #if __option(ANSI_strict) || __option(only_std_keywords)
  198.                 #define MAC_C 0    /* Standard C */
  199.             #endif
  200.         #endif
  201.         #if !defined(MAC_C)
  202.             #define MAC_C 1    /* allow Mac C extensions: "pascal", etc. */
  203.         #endif
  204.     #else
  205.         #define MAC_C 0        /* Standard C */
  206.     #endif
  207. #endif
  208. #ifndef SHORT_DOUBLE_OK
  209.     #if SYMANTEC_C
  210.         #define SHORT_DOUBLE_OK 0        /* "short double" not supported by Symantec C */
  211.     #else
  212.         #define SHORT_DOUBLE_OK MAC_C    /* "short double" not allowed by Standard C */
  213.     #endif
  214. #endif
  215. #include <stdio.h>            /*  required */
  216. #include <stdlib.h>
  217. #if MAC_C
  218.     #include <Quickdraw.h>    /*  required */
  219. #endif
  220. /*
  221. The inclusion, above, of Quickdraw.h will result in the inclusion of MixedMode.h
  222. only if the Universal Headers are used, since the Universal Headers and the Mixed
  223. Mode Manager are both new, providing universal support for 68k and ppc Macs.
  224. */
  225. #if defined(__MIXEDMODE__)
  226.     #if defined(GENERATINGPOWERPC) || defined(GENERATING68K)
  227.         #define UNIVERSAL_HEADERS 2    /* version 2 */
  228.     #else
  229.         #define UNIVERSAL_HEADERS 1    /* version 1 */
  230.     #endif
  231. #else
  232.     #define UNIVERSAL_HEADERS 0
  233. #endif
  234.  
  235. /*
  236. Based on Apple's ConditionalMacros.h, so that the VideoToolbox and your sources 
  237. can use these new macros without worrying about whether you've actually got the 
  238. new headers (June '95) in which they are first introduced. This section has no effect if
  239. GENERATINGPOWERPC etc. are already defined. These macros support early versions of
  240. THINK C, which Apple's new headers don't support.
  241. */
  242. #ifndef GENERATINGPOWERPC
  243.     #if defined(powerc) || defined(__powerc)
  244.         #define GENERATINGPOWERPC 1
  245.     #else
  246.         #define GENERATINGPOWERPC 0
  247.     #endif
  248. #endif
  249. #ifndef GENERATING68K
  250.     #if GENERATINGPOWERPC
  251.         #define GENERATING68K 0
  252.     #else
  253.         #define GENERATING68K 1
  254.     #endif
  255. #endif
  256. #if GENERATING68K && !defined(GENERATING68881)
  257.     #if defined(applec) || defined(__SC__)
  258.         #ifdef mc68881
  259.             #define GENERATING68881 1
  260.         #endif
  261.     #else
  262.         #if THINK_C && THINK_C==1        /* THINK C 4 */
  263.             #define GENERATING68881 _MC68881_
  264.         #endif
  265.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* THINK C 5,6,7,8, C++, SYMANTEC C,C++ */
  266.             #if __option(mc68881)
  267.                 #define GENERATING68881 1
  268.             #endif
  269.         #endif
  270.         #ifdef __MWERKS__
  271.             #if __MC68881__
  272.                 #define GENERATING68881 1
  273.             #endif
  274.         #endif
  275.     #endif
  276. #endif
  277. #ifndef GENERATING68881
  278.     #define GENERATING68881 0
  279. #endif
  280.  
  281. /* Apple's headers don't define GENERATING68020, but Identify.c and Require.c need it. */
  282. #if GENERATING68K && !defined(GENERATING68020)
  283.     #if defined(applec) || defined(__SC__)
  284.         #ifdef mc68020
  285.             #define GENERATING68020 1
  286.         #endif
  287.     #else
  288.         #if THINK_C && THINK_C==1            /* THINK C 4 */
  289.             #define GENERATING68020 _MC68020_
  290.         #endif
  291.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* Symantec C, THINK C 5,6,7,8 */
  292.             #if __option(mc68020)
  293.                 #define GENERATING68020 1
  294.             #endif
  295.         #endif
  296.         #if __MWERKS__
  297.             #if __MC68020__
  298.                 #define GENERATING68020 1
  299.             #endif
  300.         #endif
  301.     #endif
  302. #endif
  303. #if !defined(GENERATING68020)
  304.     #define GENERATING68020 0
  305. #endif
  306.  
  307. #if !defined(MATLAB)
  308.     #define MATLAB 0
  309. #endif
  310. #if MATLAB
  311.     /*
  312.     This must come after stdlib.h, stdio.h, and QuickDraw.h and before everything
  313.     else. If MATLAB is true then we include the header file cmex.h.  Otherwise we
  314.     define the data types that are normally provided by that header, so that code
  315.     that uses these types may be compiled for use in applications.  It must come
  316.     before we test for version 3 or 4.  The version 3 cmex.h does not define the
  317.     symbol mex_h; version 4 does.  This is what we use to figure out which
  318.     version we are compiling for.  Sound complicated?  Sigh! dhb
  319.     */
  320.     
  321.     #include <cmex.h>
  322.     /* Test for MATLAB 4 or MATLAB 3, and set symbol appropriately. */
  323.     #undef MATLAB
  324.     #ifdef mex_h
  325.         #define MATLAB 4
  326.     #else
  327.         #define MATLAB 3
  328.     #endif
  329.     #if !MAC_C
  330.         #error "MATLAB requires the Macintosh extensions to C."
  331.     #endif
  332.  
  333.     /*
  334.     Undefine the macros that override memory allocation.  MATLAB's implementation
  335.     doesn't work if you use realloc.
  336.     */
  337.     #undef malloc
  338.     #undef calloc
  339.     #undef free
  340.     
  341.     /* Define data types for printf, scanf. */
  342.     #if MATLAB==4                    /* Version 4 */
  343.         #if GENERATING68K
  344.             typedef short int PRINTF_INT;        /* type of arguments to printf et al. */
  345.             typedef long double PRINTF_DOUBLE;
  346.             typedef    int SCANF_INT;                /* type of arguments to scanf et al. */
  347.             typedef double SCANF_DOUBLE;
  348.         #endif
  349.         #if GENERATINGPOWERPC
  350.             typedef int PRINTF_INT;                /* type of arguments to printf et al. */
  351.             typedef double PRINTF_DOUBLE;
  352.             typedef int SCANF_INT;                /* type of arguments to scanf et al. */
  353.             typedef double SCANF_DOUBLE;
  354.         #endif
  355.     #endif
  356.     #if THINK_C || THINK_CPLUS || SYMANTEC_C    /* Declare our own QuickDraw globals, allocated by MATLABMain.h */
  357.         extern THINK_C_QD mex_qd;
  358.         #define qd mex_qd
  359.     #else
  360.         #define mex_qd qd
  361.     #endif
  362. #else
  363.     typedef long int INT;
  364.     #if SHORT_DOUBLE_OK
  365.         typedef short double DOUBLE;/* not allowed by Standard C */
  366.     #else
  367.         typedef double DOUBLE;
  368.     #endif
  369.     typedef int PRINTF_INT;            /* type of arguments to printf et al. */
  370.     typedef double PRINTF_DOUBLE;
  371.     typedef int SCANF_INT;            /* type of arguments to scanf et al. */
  372.     typedef double SCANF_DOUBLE;
  373.     #if SHORT_DOUBLE_OK
  374.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  375.             #pragma options align=native
  376.         #endif
  377.         typedef struct {
  378.             char *name;
  379.             INT type;
  380.             INT m;
  381.             INT n;
  382.             DOUBLE *pr;
  383.             DOUBLE *pi;
  384.         } Matrix;
  385.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  386.             #pragma options align=reset
  387.         #endif
  388.     #endif
  389. #endif
  390.  
  391. /*  Standard C headers */
  392. #if MATLAB
  393.     /* The <assert.h> macro requires modification to work in a MATLAB shared library. */
  394.     #define NDEBUG        /* disable the standard assert.h macro */
  395.     #undef assert
  396.     #define assert(x)    if(!(x)){\
  397.         PrintfExit("Assertion (" #x ") failed at %s:%d\n",__FILE__,__LINE__);\
  398.     }
  399. #else
  400.     #include <assert.h>
  401. #endif
  402. #include <ctype.h>
  403. #include <float.h>
  404. #include <limits.h>
  405. #include <stdlib.h>
  406. #include <string.h>
  407. #include <time.h>
  408. #if MAC_C && (UNIVERSAL_HEADERS>=2)
  409.     #include <fp.h>
  410. #else
  411.     #if GENERATINGPOWERPC || GENERATING68881
  412.         /* as advised by math.h, we don't enable these if using 8-byte doubles on 68k */
  413.         #define _NOERRORCHECK_ 1        /* encourage use of 8881 intrinsic functions */
  414.         #define _INLINE_FPU_CALLS_ 1    /* encourage use of 8881 intrinsic functions */
  415.     #endif
  416.     #include <math.h>
  417.     #if !defined(__FP__)    /* make sure that math.h hasn't included fp.h */
  418.         #define round(x) floor(0.5+(x))    /* used by many VideoToolbox routines */
  419.     #endif
  420. #endif
  421.  
  422. /*  Macintosh headers */
  423. #if MAC_C
  424.     #if THINK_C || THINK_CPLUS || SYMANTEC_C
  425.         #include <console.h>
  426.     #endif
  427.     #include <Devices.h>
  428.     #include <Errors.h>
  429.     #include <Events.h>
  430.     #include <FixMath.h>
  431.     #include <Fonts.h>
  432.     #if UNIVERSAL_HEADERS>2
  433.         #include <Gestalt.h>    /* Apple abbreviated the filename */
  434.     #else
  435.         #include <GestaltEqu.h>
  436.     #endif
  437.     #include <Memory.h>
  438.     #include <Menus.h>
  439.     #include <OSEvents.h>
  440.     #include <OSUtils.h>    /*  required */
  441.     #include <Packages.h>
  442.     #include <Palettes.h>
  443.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  444.         #include <profile.h>/* only needed if you want timing info */
  445.     #endif
  446.     #include <QDOffscreen.h>
  447.     #include <Resources.h>
  448.     #include <Retrace.h>    /*  required */
  449.     #if __MWERKS__
  450.         #include <SIOUX.h>
  451.     #endif
  452.     #include <Slots.h>
  453.     #include <Sound.h>
  454.     #if THINK_C && !UNIVERSAL_HEADERS
  455.         #include <pascal.h>    /* CtoPStr() and PtoCStr() */
  456.         #ifndef c2pstr
  457.             #define c2pstr(s) CtoPstr(s)
  458.             #define p2cstr(s) PtoCstr(s)
  459.         #endif
  460.     #else
  461.         #include <Strings.h>/* c2pstr() and p2cstr() */
  462.         #define CtoPstr c2pstr
  463.         #define PtoCstr p2cstr
  464.     #endif
  465.     #include <Timer.h>        /*  required */
  466.     #include <ToolUtils.h>
  467.     #include <Traps.h>
  468.     #include <Video.h>
  469.     #include <Windows.h>    /*  required */
  470.     /*
  471.     Old Memory.h header files, before Apple's Universal Headers, don't define the new
  472.     BlockMoveData(), so we do it here, to retain compability with the old header files.
  473.     */
  474.     #if !UNIVERSAL_HEADERS
  475.         #pragma parameter BlockMoveData(__A0,__A1,__D0)
  476.         extern pascal void BlockMoveData(const void *srcPtr,void *destPtr,Size byteCount)=0xA22E;
  477.     #endif
  478. #endif
  479.  
  480. /*
  481. This redefines the standard C functions, malloc, etc. to instead call Apple's
  482. corresponding routines, e.g. NewPtr. The THINK C memory management routines are 
  483. poor because they are bad about freeing space, tending to fragment the free space. 
  484. */
  485. #if THINK_C && !defined(SYMANTEC_C)
  486.     #include "MacMemory.h"
  487. #endif
  488.  
  489. /*
  490. MATLAB AND THE NEWLINE CHARACTER
  491. In most C environments the newline character is '\n' (ascii 10). In Apple's
  492. wisdom they chose to separate lines in Macintosh files with the ascii 13
  493. character, which is usually called the return character '\r'. Standard C
  494. specifies that the stdio library will use '\n' as the newline character. This
  495. potentially creates a compatibility problem between Mac C programs and C
  496. programs written for the rest of the world's computers, since one wants any text
  497. files they produce to be appropriate to the local environment. Both MPW and
  498. THINK C resolve the problem behind the scenes, but they do it in different ways.
  499. MPW redefines the association between symbolic names and character codes, making
  500. '\n' be 13 and '\r' be 10. THINK C instead modifies the stdio library so that
  501. reads and writes to a "text" (i.e. not binary) stream are translated, exchanging
  502. character codes 10 and 13. Both solutions work. However, when we use THINK C to
  503. create code resources for MATLAB we are forced to use the MPW stdio library that
  504. is built into MATLAB. Unfortunately this bypasses both compilers' fixes to the
  505. newline problem. The problem affects every single text i/o operation, e.g. every
  506. printf and scanf. Alas, there is no way to get the pre-processor to redefine /n
  507. and /r.
  508.  
  509. Our quick fix is to create a macro called NL that is normally defined as the
  510. newline string "\n", but which is instead defined as "\015" (i.e. ascii 13) when
  511. MATLAB is true. Programs such as Assign.c that have replaced all instances of
  512. "\n" by NL will then work whether or not MATLAB is true. The obvious drawback is
  513. that this quick solution requires these modifications to the source files.
  514. */
  515. #if MATLAB && THINK_C    /* Quick fix */
  516.     #define NL "\r"
  517.     #define NEWLINE '\r'
  518. #else
  519.     #define NL "\n"        /* the standard new-line string */
  520.     #define NEWLINE '\n'
  521. #endif
  522.  
  523. /*
  524. TRUE and FALSE
  525. */
  526. #ifndef TRUE
  527.     #define FALSE    0
  528.     #define TRUE    1
  529. #endif
  530.  
  531. /*
  532. NAN & INF
  533. If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
  534. IsFinite() definitions & prototypes below. 
  535. Apple's fp.h header defines isnan() and isfinite().
  536. Apple's header files math.h and fp.h both define HUGE_VAL and pi.
  537. fp.h also defines INFINITY, NAN, isfinite(), and isnan().
  538. */
  539. #if !defined(INF)
  540.     #define INF HUGE_VAL    /* HUGE_VAL is defined in math.h and fp.h */
  541. #endif
  542. #if !defined(NAN)
  543. /*    #define NAN    (0.0/0.0)    */    /* evaluated at runtime */
  544.     #define NAN    Nan            /* global defined in Nan.c */
  545. #endif
  546.  
  547. /*
  548. NUMERICAL CONSTANTS
  549. It's sad to say, but THINK C 5.02 loses two bits of precision converting between
  550. doubles and ascii text, in either direction. Thus you will obtain more accurate
  551. results by computing the numerical constants below at runtime rather than using
  552. these predefined constants. The ANSI Numerical C Extensions group is moving to
  553. require C compilers to preserve precision, so there is hope for the future. Of
  554. course most applications would never notice a loss of two bits precision out of
  555. the total double precision given by the 64 bits in the mantissa.
  556. */
  557. #if !defined(PI)
  558.     #if UNIVERSAL_HEADERS>=2
  559.         #define PI        pi                        /* pi is defined in math.h and fp.h */
  560.     #else
  561.         #define PI        3.1415926535897932385    /* computed in Mathematica */
  562.     #endif
  563. #endif
  564. #if !defined(LOGPI)
  565.     #define LOGPI    1.14472988584940017414    /* computed in Mathematica */
  566. #endif
  567. #if !defined(LOG2)
  568.     #define LOG2    0.69314718055994530942    /* computed in Mathematica */
  569. #endif
  570. #if !defined(LOG10)
  571.     #define LOG10    2.30258509299404568402    /* computed in Mathematica */
  572. #endif
  573.  
  574. #if MAC_C
  575.     /*
  576.     CLUTSIZE
  577.     Inline code that returns the same answer as GDClutSize(device).
  578.     */
  579.     #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
  580.     
  581.     /*  Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
  582.     /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
  583. #endif
  584.  
  585. /*
  586. FIXED POINT ARITHMETIC
  587. Apple defines a handy data type called Fixed that is stored in a long, but is
  588. assumed to have a decimal point in the middle. Many operations, e.g. adding two
  589. Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
  590. directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
  591. FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
  592. compilers define double in various ways, depending on whether a floating point
  593. unit is to be used. The Apple-provided routines for doing type conversion to and
  594. from Fixed are only appropriate if you are NOT using the floating point unit.
  595. The ones defined below are faster and work with or without the FPU.
  596. */
  597. #define LongToFix(x) ((long)(x)<<16)
  598. #define FixToLong(x) ((x)>>16)
  599. #define DoubleToFix(x) ((long)((x)*65536.+0.5))
  600. #define FixToDouble(x) ((double)(x)*(1./65536.))
  601.  
  602. #if MAC_C
  603.     /*
  604.     StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
  605.     Apple's StackSpace(), declared in Memory.h, that returns the number of bytes 
  606.     allocated for the stack.
  607.     */
  608.     #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
  609. #endif
  610.  
  611. #if MAC_C
  612.     /* AfterDark.c */
  613.  
  614.     OSErr AfterDarkEnable(void);
  615.     OSErr AfterDarkDisable(void);
  616. #endif
  617.  
  618. /* Assign.c */
  619.  
  620. #define ASSIGN_DIMS 3        /* Feel free to increase or decrease ASSIGN_DIMS. */
  621. typedef struct {
  622.     short type;
  623.     unsigned sizedOnce:1;    /* dim[] is meaningful */
  624.     unsigned sized:1;        /* dim[] is final */
  625.     unsigned malloced:1;    /* allocated by malloc */
  626.     char *name;
  627.     void *ptr;                /* for array, address of element zero */
  628.     long dim[ASSIGN_DIMS];    /* zero indicates a scalar */
  629.     long firstElement;        /* for 1-d array, index of first array element. Usually 0 */
  630.     const char *comment;    /* text string, or NULL */
  631. } Description;
  632. enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
  633.     ,assignNoComment=8,assignNoPrintfExit=0x10
  634.     ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
  635. };
  636. enum {assignMemoryError=-1,assignTypeError=-2
  637.     ,assignVariableError=-3,assignUnknownVariableError=-4
  638.     ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
  639.     ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
  640.     ,assignSemicolonError=-10,assignFileError=-11
  641.     ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
  642.     ,assignInconsistentDimensionsError=-14
  643.     ,assignCouldntFindDescription=-15
  644. };
  645. enum{charType=1,unsignedCharType,shortType,unsignedShortType
  646.     ,longType,unsignedLongType
  647.     ,floatType
  648.     #if SHORT_DOUBLE_OK
  649.         ,shortDoubleType
  650.     #endif
  651.     ,doubleType
  652.     ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
  653.     ,longPtrType,unsignedLongPtrType
  654.     ,floatPtrType
  655.     #if SHORT_DOUBLE_OK
  656.         ,shortDoublePtrType
  657.     #endif
  658.     ,doublePtrType
  659.     ,stringType,unknownType
  660. };
  661. FILE *OpenCalFileRead(char *filename);
  662. FILE *OpenCalFileReadAndCheck(char *filename);
  663. FILE *OpenCalFileWrite(char *filename);
  664. void AppendDescriptions(Description **d,Description *s);
  665. void CopyDescriptions(Description *d,Description *s);
  666. Description *AllocateDescriptions(long n);
  667. void FreeDescriptions(Description *d);
  668. long NumberOfDescriptions(Description *d);
  669. Description NullDescription(void);
  670. int IsNullDescription(Description d);
  671. #define IsNullDescription(d) ((d).type==0)
  672. int AssignmentLineWasBlank(void);
  673. int UnequalDescribedVars(Description d1[],Description d2[],short flags);
  674. int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
  675. int CopyDescribedVars(Description d1[],Description d2[],short flags);
  676. int CopyDescribedVarPair(Description *d1,Description *d2,short flags);
  677. long InitializeADescribedVar(Description *d,short flags);
  678. long InitializeDescribedVars(Description d[],short flags);
  679. long FindDescribedDim(Description d[],void *ptr,int i,short flags);
  680. long FindDescription(Description d[],void *ptr,short flags);
  681. void FreeADescribedVar(Description *d,short flags);
  682. void FreeDescribedPtrVars(Description d[],short flags);
  683. void FreeDescribedVars(Description d[],short flags);
  684. void KeepDescribedVars(Description d[],short flags);
  685. void KeepADescribedVar(Description *d,short flags);
  686. long PrintAnAssignment(FILE *stream,Description *d,short flags);
  687. long PrintAssignments(FILE *stream,Description d[],short flags);
  688. long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
  689. long ReadAssignmentLine(FILE *stream,Description d[],short flags);
  690. long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
  691. long ReadAssignmentStream(FILE *stream,Description d[],short flags);
  692. long ReadAssignmentFile(const char *filename,Description d[],short flags);
  693. Description Describe(short type,void *ptr,char *name,const char *comment);
  694. Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
  695. Description DescribeFirstLast(short type,void *ptr,char *name
  696.     ,const char *comment,long firstElement,long lastElement);
  697.  
  698. #if MAC_C
  699.     /* AtExitToShell.c */
  700.     
  701.     int AtExitToShell(void(*userFunctionPtr)(void));
  702. #endif
  703.  
  704. /* Binomial.c */
  705.  
  706. long    BinomialSample(double p,long n);
  707. int        BinomialSampleQuickly(int n);
  708. double    BinomialLowerBound(double P,long k,long n);
  709. double    BinomialUpperBound(double P,long k,long n);
  710. double    BinomialPdf(double p,long k,long n);
  711. double    Binomial(double p,long k,long n);
  712. double    IncompleteBeta(double x,double a,double b);
  713. double    InverseBinomial(double P,long k,long n);
  714. double    InverseIncompleteBeta(double p,double a,double b);
  715.  
  716. /* BreakLines.c */
  717.  
  718. char *BreakLines(char *string,long lineLength);
  719. void PrintWrappedText(FILE *stream,const char *s);
  720. void PrintWrappedTextToFile(const char *filename,const char *s);
  721. void PrintWrappedComment(FILE *stream,const char *s);
  722. void PrintWrappedCommentToFile(const char *filename,const char *s);
  723.  
  724. #if MAC_C
  725.     /* CardSlot.c */
  726.     
  727.     OSErr    CardSlot(char *cardName);
  728.     
  729.     /* CenterRectInRect.c */
  730.     
  731.     void CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
  732.     void OffsetRectTile(Rect *r,int nx,int ny);
  733.     Boolean IsRectInRect(Rect *r,Rect *R);
  734.     void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  735.     void ExpandRect(Rect *r,double hMag,double vMag);
  736.     void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  737.     void LocalToGlobalRect(Rect *r);
  738.     void GlobalToLocalRect(Rect *r);
  739.  
  740. #endif
  741.  
  742. /* ChiSquare.c */
  743.  
  744. double    PChiSquare (double chiSquare,int n);
  745.  
  746. /* Choose.c */
  747.  
  748. #if !MAC_C
  749.     #define Boolean unsigned char
  750. #endif
  751. int Choose(int defaultChoice,const char *query,char *choices[],int n);
  752. char *ChoiceStr(char *choices[],int n);
  753. int MultipleChoice(short defaultChoice,short n,char *choices[]);
  754. Boolean YesOrNo(Boolean defaultAnswer);
  755. extern char *noYes[];
  756. #if !MAC_C
  757.     #undef Boolean
  758. #endif
  759.  
  760. #if MAC_C
  761.     /* ChooseScreen.c */
  762.     
  763.     int ChooseScreen(int screen,const char *question);
  764.  
  765.     /* ConvolveX.c */
  766.     
  767.     void    ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  768.                 Rect *srcRectPtr,Rect *dstRectPtr);
  769.  
  770.     /* ConvolveY.c */
  771.     
  772.     void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  773.                 Rect *srcRectPtr,Rect *dstRectPtr);
  774.     
  775.     /* CopyBitsQuickly.c */
  776.     
  777.     enum{addOverQuickly=40,addOverParallel=40,mulOver};
  778.     int    CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits
  779.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  780.     
  781.     /* CopyQuickDrawGlobals.c */
  782.     
  783.     void CopyQuickDrawGlobals(void);
  784.     #define CopyQuickdrawGlobals CopyQuickDrawGlobals    /*  old spelling */
  785.     
  786.     /* CopyWindows.c */
  787.     
  788.     enum{copyLiterally=0x10000,copyColorize=0x20000};
  789.     enum{srcCopyLiterally=srcCopy+copyLiterally,addOverLiterally=addOver+copyLiterally
  790.         ,addOverParallelLiterally=addOverParallel+copyLiterally
  791.         ,mulOverLiterally=mulOver+copyLiterally};
  792.     int CopyWindows(CWindowPtr srcWindow,CWindowPtr dstWindow
  793.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  794.  
  795.     /* CreateTrialSnds.c */
  796.     
  797.     void CreateTrialSnds(void);
  798. #endif
  799.  
  800. /* DatedString.c */
  801.  
  802. char    *DatedString(unsigned long seconds);
  803.  
  804. #if MAC_C
  805.     /* DrawPrintf.c */
  806.     
  807.     void DrawPrintf(char *s, ...);
  808. #endif
  809.  
  810. /* Exponential.c */
  811.  
  812. double ExponentialPdf(double x);
  813.  
  814. /* ffprintf.c */
  815.  
  816. int ffprintf(FILE *stream[2],char *format,...);
  817.  
  818. #if MAC_C
  819.     /* FlushCacheRange.c */
  820.     
  821.     void FlushCacheRange (void *address, unsigned long count);
  822.     
  823.     /* GDOpenWindow.c */
  824.     
  825.     void AddExplicitPalette(WindowPtr window);
  826.     void RemovePalette(WindowPtr window);
  827.     WindowPtr GDOpenWindow1(GDHandle device);
  828.     void GDDisposeWindow1(WindowPtr window);
  829.     CWindowPtr GDOpenWindow(GDHandle device);
  830.     void GDDisposeWindow(CWindowPtr myWindow);
  831.     void GDGrayColorTable(GDHandle device);
  832.     void SwapWindowExplicitMode(CWindowPtr window,Boolean *explicit);
  833.     BitMap *GetBitMapPtr(CWindowPtr window);
  834.     Boolean IsGWorldPtr(CWindowPtr window);
  835.     Boolean IsGrafPtr(CWindowPtr window);
  836.     
  837.     /* GDPrintf.c */
  838.     
  839.     void GDPrintf(char *s, ...);
  840.     
  841.     /* GDTime.c */
  842.     
  843.     double GDFrameRate(GDHandle device);
  844.     double GDMovieRate(GDHandle device,int quickly);
  845.     double GDMovieSize(GDHandle device,int quickly);
  846.     double GDVBLRate(GDHandle device);
  847.     double TickRate(void);
  848.     typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
  849.         ,ColorSpec *aTable);
  850.     OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
  851.         ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
  852.     
  853.     /* GDVideo.c */
  854.     
  855.     #define MAX_SCREENS 8
  856.     OSErr DriverGestalt(int refNum,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  857.     OSErr GDGestalt(GDHandle device,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  858.     Boolean GDGestaltIsOn(GDHandle device);
  859.     char  *GDCardName(GDHandle device);
  860.     extern short gdClutSizeTable[33];
  861.     short GDClutSize(GDHandle device);
  862.     long GDColors(GDHandle device);
  863.     OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
  864.     short GDDacSize(GDHandle device);
  865.     OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  866.     OSErr GDGetDisplayMode(GDHandle device,unsigned long *displayModeIDPtr
  867.         ,unsigned short *modePtr,unsigned short *pagePtr,Ptr *baseAddrPtr);
  868.     OSErr GDGetNextResolution(GDHandle device,unsigned long previousDisplayModeID
  869.         ,unsigned long *displayModeIDPtr,unsigned long *horizontalPixelsPtr
  870.         ,unsigned long *verticalLinesPtr,Fixed *refreshRatePtr
  871.         ,unsigned short *maxDepthModePtr);
  872.     OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
  873.     OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
  874.     OSErr GDGetDelay(GDHandle device,Boolean *dontWaitForVBLPtr,double *nanosecondsPtr);
  875.     OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  876.     OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
  877.     OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
  878.     OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
  879.     OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  880.     OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
  881.     OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
  882.     OSErr GDGrayPage(GDHandle device,short page);
  883.     Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
  884.     short GDModePixelSize(GDHandle device,short mode);
  885.     unsigned char *GDName(GDHandle device);
  886.     char *GDNameStr(GDHandle device);
  887.     ColorSpec *GDNewLinearColorTable(GDHandle device);
  888.     short GDPixelSize(GDHandle device);
  889.     OSErr GDPrintGammaTable(FILE *o,GDHandle device);
  890.     OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  891.     OSErr GDRestoreDeviceClut(GDHandle device);
  892.     OSErr GDRestoreGamma(GDHandle device);
  893.     OSErr GDSaveGamma(GDHandle device);
  894.     OSErr GDSetDefaultMode(GDHandle device,short mode);
  895.     OSErr GDSetDelay(GDHandle device,Boolean dontWaitForVBL,double nanoseconds);
  896.     OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  897.     OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
  898.     OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
  899.         ,ColorSpec *table);
  900.     OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
  901.     OSErr GDSetGray(GDHandle device,Boolean flag);
  902.     OSErr GDSetInterrupt(GDHandle device,Boolean flag);
  903.     OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
  904.     OSErr GDSetPageDrawn(GDHandle device,short page);
  905.     OSErr GDSetPageShown(GDHandle device,short page);
  906.     OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
  907.     OSErr GDSwitchMode(GDHandle device,short mode,long displayModeID,short page,Ptr *baseAddrPtr);
  908.     short GDType(GDHandle device);
  909.     OSErr GDUncorrectedGamma(GDHandle device);
  910.     int GDVersion(GDHandle device);
  911.     int PatchMacIIciVideoDriver(void);
  912.     
  913.     /* GetClicks.c */
  914.     
  915.     short    GetClicks(void);
  916.  
  917.     /* GetScreenDevice.c */
  918.     
  919.     GDHandle    GetScreenDevice(int n);
  920.     int            GetScreenIndex(GDHandle device);
  921.     GDHandle    SlotToScreenDevice(int n);
  922.     GDHandle    GetDeviceByRefNum(int n);
  923.     short int    GetDeviceSlot(GDHandle device);            /* gives nonsense on PCI bus */
  924.     char        *GetDeviceSlotName(GDHandle device);    /* works on NuBus, PCI bus, and no bus */
  925.     GDHandle    GetWindowDevice(WindowPtr theWindow);
  926.     GDHandle    GetRectDevice(Rect *r);
  927.  
  928. #endif
  929.  
  930. /* GetTimeDateString.c */
  931.  
  932. char *GetTimeDateString(time_t t);
  933.  
  934. #if MAC_C
  935.     /* GetVersionString.c */
  936.  
  937.     char *GetVersionString(void);
  938.  
  939.     /* GetVoltage.c */
  940.     
  941.     double    VoltsDuringFrame(double frames);
  942.     double    GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
  943.                 ,double *sdPtr);
  944.     short    GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
  945.                 ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
  946.     short    InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
  947.                 ,double *voltDeltaPtr,double *voltZeroPtr);
  948.     short    RetrieveVoltages(long *nPtr,unsigned short readings[]);
  949.     int        ForeRunnerSlot(void);
  950.     enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
  951. #endif
  952.  
  953. /* HexToBinary.c */
  954.  
  955. int HexToBinary(char *string,void *ptr);
  956. char *BinaryToHex(size_t n,void *ptr,char *string);
  957.  
  958. #if MAC_C
  959.     /* HideMenuBar.c */
  960.     
  961.     void    HideMenuBar(void);
  962.     void    ShowMenuBar(void);
  963.     void SquareCorners(GDHandle device);
  964.     void RestoreCorners(GDHandle device);
  965.     void UnclipScreen(GDHandle device);
  966.     void RestoreScreenClipping(GDHandle device);
  967.     
  968.     /* Identify.c */
  969.     
  970.     char *IdentifyApplication(void);
  971.     char *IdentifyCompiler(void);
  972.     char *IdentifyGreenwichMeanTime(void);
  973.     char *IdentifyMachine(void);
  974.     char *IdentifyModel(void);
  975.     char *IdentifyOwner(void);
  976.     char *IdentifyVideo(GDHandle device);
  977.     char *IdentifyVM(void);
  978.     
  979.     /* ImageStatistics */
  980.  
  981.     double ImageEnergy(GWorldPtr aWorld,Rect *aRect,double background);
  982.     void ImageStatistics(GWorldPtr world,Rect *rect
  983.         ,long *minPtr,long *maxPtr,double *meanPtr,double *meanSquarePtr);
  984.  
  985.     /* IsCmdPeriod.c */
  986.     
  987.     Boolean IsCmdPeriod(EventRecord *event);
  988.  
  989.     /* IsFileSharingOn.c */
  990.  
  991.     Boolean IsFileSharingOn(void);
  992.     OSErr KillFileSharing(void);
  993.  
  994. #endif
  995.  
  996. /* IsNan.c */
  997.  
  998. int IsNan(double x);
  999. int IsInf(double x);
  1000. #ifndef IsFinite    /* neither NAN nor ±INF */
  1001.     #define IsFinite(x) \
  1002.     (sizeof(x)>8?    \
  1003.     ((*(short *)&(x) & 0x7FFF)!=0x7FFF)        /* 10 or 12 byte double */\
  1004.     :((*(short *)&(x) & 0x7FF0)!=0x7FF0))    /* 8 byte double */
  1005. #endif
  1006.  
  1007. #if MAC_C
  1008.     /* kbhit.c */
  1009.     
  1010.     int    kbhit(void);
  1011.     int    getcharUnbuffered(void);
  1012.  
  1013.     /* KillEveryoneButMe.c */
  1014.     
  1015.     OSErr KillEveryoneButMe(void);
  1016. #endif
  1017.  
  1018. /* Log2L.c */
  1019.  
  1020. long Log2L(unsigned long j);
  1021.  
  1022. #if MAC_C
  1023.     
  1024.     /* MaximizeConsoleHeight.c */
  1025.     
  1026.     void MaximizeConsoleHeight(void);
  1027. #endif
  1028.  
  1029. /* Mean.c */
  1030.  
  1031. double Mean(double x[],long n,double *sdPtr);
  1032. double MeanF(float x[],long n,double *sdPtr);
  1033. double MeanB(char x[],long n,double *sdPtr);
  1034. double MeanUB(unsigned char x[],long n,double *sdPtr);
  1035. double MeanW(short x[],long n,double *sdPtr);
  1036. double MeanUW(unsigned short x[],long n,double *sdPtr);
  1037. double MeanL(long x[],long n,double *sdPtr);
  1038. double MeanUL(unsigned long x[],long n,double *sdPtr);
  1039.  
  1040. /* Nan.c */
  1041. extern const short __NAN[];
  1042. #define Nan (*(double *)__NAN)
  1043.  
  1044. #if MAC_C
  1045.     /* NoiseFill.c */
  1046.     
  1047.     int NoiseFill(CWindowPtr window,Rect *r,double dx,double dy,Boolean randomPhase);
  1048.     int NoiseFillBits(PixMap *bits,Rect *r,double dx,double dy,Boolean randomPhase);
  1049.     int MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *bits);    /* Obsolete */
  1050.     
  1051.     /* NoisePdfFill.c */
  1052.     
  1053.     OSErr NoisePdfFill(GWorldPtr world,Rect *rectPtr
  1054.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1055.     OSErr NoisePdfAdd(GWorldPtr world,Rect *rectPtr
  1056.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1057.     enum{kBinaryPdf=0,kBinomialPdf,kGaussianPdf,kUniformPdf};
  1058. #endif
  1059.  
  1060. /* Normal.c */
  1061.  
  1062. double NormalPdf(double x);
  1063. double Normal(double x);
  1064. double InverseNormal(double p);
  1065. double NormalSample(void);
  1066. double Normal2DPdf(double r);
  1067. double Normal2D(double r);
  1068. double InverseNormal2D(double p);
  1069. double Normal2DSample(void);
  1070. double InverseNormal2DPdf(double p);
  1071. void BoundedNormalIntegers(short *distribution,long n,double mean,double sd
  1072.     ,short min,short max);
  1073.  
  1074. /* nrand.c */
  1075.  
  1076. unsigned long nrand(unsigned long n);
  1077.  
  1078. /* OpenDataFiles.c */
  1079.  
  1080. unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
  1081.                     ,char *inName,char *outName);
  1082.  
  1083. /* OpenPreferencesFolder.c */
  1084.  
  1085. #if !MAC_C
  1086.     #define OSErr short
  1087. #endif
  1088. OSErr OpenPreferencesFolder(void);
  1089. OSErr ClosePreferencesFolder(void);
  1090. OSErr OpenPreferencesWD(short *wdRefNumPtr);
  1091. #if !MAC_C
  1092.     #undef OSErr
  1093. #endif
  1094.  
  1095. #if MAC_C
  1096.     /*    PixMapToPICT.c */
  1097.  
  1098.     void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  1099.         ,int pixelSize,ColorTable **cTable);
  1100.  
  1101.     /*    PixMapToPostScript.c */
  1102.     
  1103.     void WindowToEPS(CWindowPtr window,char *filename,Rect *rectPtr
  1104.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels,float reflectance[256]);
  1105.     void PixMapToEPS(char *filename,PixMap **pm,Rect *rectPtr
  1106.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1107.     void PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
  1108.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1109.     void AppendToFile(char *filename,char *string);
  1110.     
  1111.     /* PlotXY.c */
  1112.     
  1113.     typedef struct{
  1114.         Boolean continuing;    /* zero to start a new curve */
  1115.         long color;            /* e.g. blackColor, blueColor */
  1116.         short lineWidth;    /* in pixels, zero for none */
  1117.         short symbolWidth;    /* in pixels, zero for none */
  1118.         short dashOffset;    /* in pixels */
  1119.         short dash[5];        /* in pixels. The array is terminated by a zero element */
  1120.         short h,v;            /* reserved for internal use */
  1121.         Fixed pathLengthF;    /* reserved for internal use */
  1122.     } PlotXYStyle;
  1123.     void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
  1124. #endif
  1125.  
  1126. /* PrintfExit.c */
  1127.  
  1128. int PrintfExit(const char *format,...);
  1129.  
  1130. #if MAC_C
  1131.     /* PrintfGWorld.c */
  1132.  
  1133.     void PrintfGWorld(GWorldPtr our);
  1134.     void PrintStringAsBitmap(unsigned char *s);
  1135. #endif
  1136.  
  1137. /* PupilMTF.c */
  1138.  
  1139. double PupilMTF(double cPerDeg,double diameterMm,double wavelengthNm);
  1140.  
  1141. #if MAC_C
  1142.     /* QD32Exists.c */
  1143.     
  1144.     Boolean         QD8Exists(void);
  1145.     Boolean            QD32Exists(void);
  1146.     Boolean            NewPaletteManager(void);
  1147. #endif
  1148.  
  1149. /* randU.c */
  1150.  
  1151. unsigned short    randU(void);
  1152. unsigned long    randUL(void);
  1153. void            srandU(unsigned n);
  1154. void            RandFill(void *address,long bytes);
  1155.  
  1156. /* ReadMATLABFile.c */
  1157.  
  1158. int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
  1159.     ,double **real,double **imag);
  1160. int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
  1161.     ,short **real,short **imag);
  1162. int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
  1163.     ,double **real,double **imag);
  1164. int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
  1165.     ,short **real,short **imag);
  1166. int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
  1167. int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
  1168.  
  1169. #if MAC_C
  1170.     /* RectToAddress.c */
  1171.     
  1172.     unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr, 
  1173.         short *pixelSizePtr,short *bitsOffsetPtr);
  1174.     Ptr GetPixBaseAddr32(PixMap **pm);
  1175. #endif
  1176.     
  1177. /*    Require.c    */
  1178.  
  1179. void Require(long quickDrawVersion);
  1180. struct PrecompileSizeofInt{
  1181.     int i;
  1182. };
  1183. struct PrecompileSizeofDouble{
  1184.     double d;
  1185. };
  1186.  
  1187. #if MAC_C
  1188.     /* RestoreCluts.c */
  1189.     
  1190.     void RestoreCluts(void);
  1191.     
  1192.     /*    SetEntriesQuickly.c */
  1193.     
  1194.     OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
  1195.     short macltset(GDHandle device,register short start
  1196.         ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
  1197.     short GetCardType(GDHandle device);
  1198.     char *GetCardBase(GDHandle device);
  1199.     OSErr WaitForNextBlanking(GDHandle device);
  1200.     
  1201.     /* SetFileInfo.c */
  1202.     
  1203.     void    SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
  1204.     
  1205.     /* SetMouse.c */
  1206.     
  1207.     void    SetMouse(Point where);
  1208.     
  1209.     /* SetOnePixel.c */
  1210.     
  1211.     void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
  1212.     unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
  1213.     unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
  1214.     void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
  1215.     unsigned long GetDevicePixel(GDHandle device,int x,int y);
  1216.     void SetOnePixel(int x,int y,unsigned long value);
  1217.     unsigned long GetOnePixel(int x,int y);
  1218.     #define SetIPixel SetDevicePixel    /*  So that old programs won't break. */
  1219.     #define GetIPixel GetDevicePixel    /*  So that old programs won't break. */
  1220.     
  1221.     /* SetPixelsQuickly.c */
  1222.     
  1223.     int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1224.     int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1225.     int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1226.     int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1227.     int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1228.     int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1229.     int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1230.     int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1231.     
  1232.     /* SetPriority.c */
  1233.     
  1234.     void SwapPriority(char *priority);
  1235.     void SetPriority(int i);
  1236.     int GetPriority(void);
  1237. #endif
  1238.  
  1239. /* Shuffle.c */
  1240.  
  1241. void Shuffle(void *array,long elements,size_t elementSize);
  1242.  
  1243. #if MAC_C
  1244.     /* SndPlay1.c */
  1245.     
  1246.     OSErr SndPlay1(Handle snd);
  1247.     void SndStop1(void);
  1248.     short SndDone1(void);
  1249.  
  1250.     /* StringToDateAndSecs.c */
  1251.     
  1252.     double StringToDateAndSecs(char *string,DateTimeRec *date);
  1253.  
  1254.     /* StringBounds.c */
  1255.     
  1256.     void CharBounds(char a,Rect *bounds,long *count);
  1257.     void StrBounds(char *s,Rect *bounds,long *count);
  1258.     double StrOutlineLength(char *s);
  1259.     void StringBounds(const unsigned char *s,Rect *bounds,long *count);
  1260.     double StringOutlineLength(const unsigned char *s);
  1261.  
  1262.     /* Timer.c */
  1263.     
  1264.     struct Timer{
  1265.         TMTask time;
  1266.         long ourA5;
  1267.         long interval,elapsed,elapsedIntervals;
  1268.         long timeToStartTimer;            /*  minimum time in µs */
  1269.         long stopDelay;                    /*  µs from call to stop, re from call to start */
  1270.         long timeManagerVersion;
  1271.         struct Timer *next,*previous;    /*  doubly linked list of Timers */
  1272.     };
  1273.     typedef struct Timer Timer;
  1274.     
  1275.     Timer *NewTimer(void);
  1276.     void DisposeTimer(Timer *t);
  1277.     void StartTimer(Timer *t);
  1278.     long StopTimer(Timer *t);                    /*  µs */
  1279.     double StopTimerSecs(Timer *t);                /*  s */
  1280.     long PeekTimer(Timer *t);                    /*  µs */
  1281.     double PeekTimerSecs(Timer *t);                /*  s */
  1282.     
  1283.     /* TitleBarHeight.c */
  1284.     
  1285.     int TitleBarHeight(WindowPtr window);
  1286.     
  1287.     /* TrapAvailable.c */
  1288.     
  1289.     Boolean    TrapAvailable(short theTrap);
  1290. #endif
  1291.  
  1292. /* Uniform.c */
  1293.  
  1294. double UniformSample(void);
  1295.  
  1296. #if MAC_C
  1297.     /* VBLInstall.c */
  1298.     
  1299.     struct VBLTaskAndA5 {
  1300.         volatile VBLTask vbl;
  1301.         long ourA5;
  1302.         #if USESROUTINEDESCRIPTORS || GENERATINGCFM
  1303.             UniversalProcPtr subroutine;
  1304.         #else
  1305.             void (*subroutine)(struct VBLTaskAndA5 *vblData);
  1306.         #endif
  1307.         GDHandle device;
  1308.         long slot;
  1309.         volatile long newFrame;        /* Boolean */
  1310.         volatile long frame;        /* count up from zero */
  1311.         volatile long framesLeft;    /* count down to zero */
  1312.         long framesDesired;
  1313.         Timer *frameTimer;            /* time ms since last VBL interrupt, see Timer.c */
  1314.         void *ptr;                    /* use this for whatever you want */
  1315.     };
  1316.     typedef struct VBLTaskAndA5 VBLTaskAndA5;    
  1317.     OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,long frames);
  1318.     OSErr VBLRemove(VBLTaskAndA5 *vblData);
  1319.     void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
  1320.     
  1321.     /* VideoTFB.c */
  1322.     
  1323.     Boolean TFBInSlot(int slot);
  1324.     void    SetUpTFB(int slot);
  1325.     void    RampClutTFB(int slot);
  1326.     void    GrayClutTFB(int slot);
  1327.     void    LoadClutTFB(int slot,unsigned char rgb[256][3]);
  1328.     void    NewBlankingTFB(int slot);
  1329.     void    NewFieldTFB(int slot);
  1330.     int        BlankingTFB(int slot);
  1331.     void    SetDepthTFB(int slot,short int bits);
  1332.     void    SynchSetDepthTFB(int masterSlot,int slot,short int bits);
  1333.     void    SynchToMainDeviceTFB(GDHandle device);
  1334.     void    HaltTFB(int slot);
  1335.     void    RestartTFB(int slot,short int bits);
  1336.     void    HaltDeviceTFB(GDHandle device);
  1337.     void    RestartDeviceTFB(GDHandle device);
  1338.     void    ScrollTFB(int slot,short int bits,long x,long y);
  1339.     void    PanTFB(int slot,long int x);
  1340. #endif
  1341.  
  1342. /* VLambda.c */
  1343.  
  1344. double VLambda(double nm);
  1345. double VLambdaPrime(double nm);
  1346.  
  1347. #if MAC_C
  1348.     /* Zoom.c */
  1349.     
  1350.     void Zoom(WindowPtr theWindow,int zoomDir,EventRecord *event);
  1351. #endif
  1352.  
  1353. #endif /* _VIDEOTOOLBOX_ */
  1354.