home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / gsfunc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-30  |  3.9 KB  |  115 lines

  1. /* Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gsfunc.h */
  20. /* Generic definitions for Functions */
  21.  
  22. #ifndef gsfunc_INCLUDED
  23. #  define gsfunc_INCLUDED
  24.  
  25. /* ---------------- Types and structures ---------------- */
  26.  
  27. /*
  28.  * gs_function_type_t is defined as equivalent to int, rather than as an
  29.  * enum type, because we can't enumerate all its possible values here in the
  30.  * generic definitions.
  31.  */
  32. typedef int gs_function_type_t;
  33.  
  34. /*
  35.  * Define information common to all Function types.
  36.  * We separate the private part from the parameters so that
  37.  * clients can create statically initialized parameter structures.
  38.  */
  39. #define gs_function_params_common\
  40.   int m;            /* # of inputs */\
  41.   const float *Domain;        /* 2 x m */\
  42.   int n;            /* # of outputs */\
  43.   const float *Range        /* 2 x n, optional */
  44.  
  45. /* Define a generic function, for use as the target type of pointers. */
  46. typedef struct gs_function_params_s {
  47.   gs_function_params_common;
  48. } gs_function_params_t;
  49. typedef struct gs_function_s gs_function_t;
  50. typedef int (*fn_evaluate_proc_t)(P3(const gs_function_t *pfn,
  51.                      const float *in, float *out));
  52. typedef void (*fn_free_params_proc_t)(P2(gs_function_params_t *params,
  53.                      gs_memory_t *mem));
  54. typedef void (*fn_free_proc_t)(P3(gs_function_t *pfn,
  55.                   bool free_params, gs_memory_t *mem));
  56. typedef struct gs_function_head_s {
  57.   gs_function_type_t type;
  58.   fn_evaluate_proc_t evaluate;
  59.   fn_free_params_proc_t free_params;
  60.   fn_free_proc_t free;
  61. } gs_function_head_t;
  62. struct gs_function_s {
  63.   gs_function_head_t head;
  64.   gs_function_params_t params;
  65. };
  66. #define FunctionType(pfn) ((pfn)->head.type)
  67.  
  68. /*
  69.  * Each specific function type has a definition in its own header file
  70.  * for its parameter record.  In order to keep names from overflowing
  71.  * various compilers' limits, we take the name of the function type and
  72.  * reduce it to the first and last letter of each word, e.g., for
  73.  * Sampled functions, XxYy is Sd.
  74.  
  75. typedef struct gs_function_XxYy_params_s {
  76.   gs_function_params_common;
  77.   << P additional members >>
  78. } gs_function_XxYy_params_t;
  79. #define private_st_function_XxYy()\
  80.   gs_private_st_suffix_addP(st_function_XxYy, gs_function_XxYy_t,\
  81.     "gs_function_XxYy_t", function_XxYy_enum_ptrs, function_XxYy_reloc_ptrs,\
  82.     st_function, <<params.additional_members>>)
  83.  
  84.  */
  85.  
  86. /* ---------------- Procedures ---------------- */
  87.  
  88. /*
  89.  * Each specific function type has a pair of procedures in its own
  90.  * header file, one to allocate and initialize an instance of that type,
  91.  * and one to free the parameters of that type.
  92.  
  93. int gs_function_XxYy_init(P3(gs_function_t **ppfn,
  94.                 const gs_function_XxYy_params_t *params,
  95.                 gs_memory_t *mem));
  96.  
  97. void gs_function_XxYy_free_params(P2(gs_function_XxYy_params_t *params,
  98.                     gs_memory_t *mem));
  99.  
  100. */
  101.  
  102. /* Evaluate a function. */
  103. #define gs_function_evaluate(pfn, in, out)\
  104.   (*(pfn)->head.evaluate)(pfn, in, out)
  105.  
  106. /* Free function parameters. */
  107. #define gs_function_free_params(pfn, mem)\
  108.   (*(pfn)->head.free_params)(&(pfn)->params, mem)
  109.  
  110. /* Free a function's implementation, optionally including its parameters. */
  111. #define gs_function_free(pfn, free_params, mem)\
  112.   (*(pfn)->head.free)(pfn, free_params, mem)
  113.  
  114. #endif                    /* gsfunc_INCLUDED */
  115.