home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GSCSPACE.H < prev    next >
C/C++ Source or Header  |  1994-07-31  |  7KB  |  221 lines

  1. /* Copyright (C) 1991, 1992, 1993 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. /* gscspace.h */
  20. /* Client interface to color spaces */
  21.  
  22. #ifndef gscspace_INCLUDED
  23. #  define gscspace_INCLUDED
  24.  
  25. #include "gsccolor.h"
  26. #include "gsstruct.h"        /* needed for enum_ptrs & reloc_ptrs */
  27.  
  28. /* Color space type indices */
  29. typedef enum {
  30.         /* Supported in all configurations */
  31.     gs_color_space_index_DeviceGray = 0,
  32.     gs_color_space_index_DeviceRGB,
  33.         /* Supported in extended Level 1, and in Level 2 */
  34.     gs_color_space_index_DeviceCMYK,
  35.         /* Supported in Level 2 only */
  36.     gs_color_space_index_CIEBasedABC,
  37.     gs_color_space_index_CIEBasedA,
  38.     gs_color_space_index_Separation,
  39.     gs_color_space_index_Indexed,
  40.     gs_color_space_index_Pattern
  41. } gs_color_space_index;
  42.  
  43. /*
  44.  * Color spaces are complicated because different spaces involve
  45.  * different kinds of parameters, as follows:
  46.  
  47. Space        Space parameters        Color parameters
  48. -----        ----------------        ----------------
  49. DeviceGray    (none)                1 real [0-1]
  50. DeviceRGB    (none)                3 reals [0-1]
  51. DeviceCMYK    (none)                4 reals [0-1]
  52. CIEBasedABC    dictionary            3 reals
  53. CIEBasedA    dictionary            1 real
  54. Separation    name, alt_space, tint_xform    1 real [0-1]
  55. Indexed        base_space, hival, lookup    1 int [0-hival]
  56. Pattern        colored: (none)            dictionary
  57.         uncolored: base_space        dictionary + base space params
  58.  
  59. Space        Underlying or alternate space
  60. -----        -----------------------------
  61. Separation    Device, CIE
  62. Indexed        Device, CIE
  63. Pattern        Device, CIE, Separation, Indexed
  64.  
  65.  * Logically speaking, each color space type should be a different
  66.  * structure type at the allocator level.  This would potentially require
  67.  * either reference counting or garbage collector for color spaces, but that
  68.  * is probably better than the current design, which uses fixed-size color
  69.  * space objects and a second level of type discrimination.
  70.  */
  71.  
  72. /* Color space type objects */
  73. typedef struct gs_color_space_s gs_color_space;
  74.  
  75. /* An opaque type for device colors. */
  76. #ifndef gx_device_color_DEFINED
  77. #  define gx_device_color_DEFINED
  78. typedef struct gx_device_color_s gx_device_color;
  79. #endif
  80.  
  81. /* Color space types (classes): */
  82. typedef struct gs_color_space_type_s {
  83.  
  84.     gs_color_space_index index;
  85.  
  86.     int num_components;        /* # of components in a color */
  87.                     /* in this space, -1 if variable */
  88.  
  89.     /* ------ Procedures ------ */
  90.  
  91.     /* Construct the initial color value for this space. */
  92.  
  93. #define cs_proc_init_color(proc)\
  94.   void proc(P2(gs_client_color *, const gs_color_space *))
  95. #define cs_init_color(pcc, pcs)\
  96.   (*(pcs)->type->init_color)(pcc, pcs)
  97. #define cs_full_init_color(pcc, pcs)\
  98.   ((pcc)->pattern = 0, cs_init_color(pcc, pcs))
  99.     cs_proc_init_color((*init_color));
  100.  
  101.     /* Map a color to a device color. */
  102.  
  103. #define cs_proc_remap_color(proc)\
  104.   int proc(P4(const gs_client_color *, const gs_color_space *,\
  105.     gx_device_color *, const gs_state *))
  106.     cs_proc_remap_color((*remap_color));
  107.  
  108.     /* Install the color space in a graphics state. */
  109.  
  110. #define cs_proc_install_cspace(proc)\
  111.   int proc(P2(gs_color_space *, gs_state *))
  112.     cs_proc_install_cspace((*install_cspace));
  113.  
  114.     /* Adjust reference counts of indirect color space components. */
  115. #define cs_proc_adjust_cspace_count(proc)\
  116.   void proc(P3(const gs_color_space *, gs_state *, int))
  117. #define cs_adjust_cspace_count(pgs, delta)\
  118.   (*(pgs)->color_space->type->adjust_cspace_count)((pgs)->color_space, pgs, delta)
  119.     cs_proc_adjust_cspace_count((*adjust_cspace_count));
  120.  
  121.     /* Adjust reference counts of indirect color components. */
  122.  
  123. #define cs_proc_adjust_color_count(proc)\
  124.   void proc(P4(const gs_client_color *, const gs_color_space *, gs_state *, int))
  125. #define cs_adjust_color_count(pgs, delta)\
  126.   (*(pgs)->color_space->type->adjust_color_count)((pgs)->ccolor, (pgs)->color_space, pgs, delta)
  127.     cs_proc_adjust_color_count((*adjust_color_count));
  128.  
  129. /* Adjust both reference counts. */
  130. #define cs_adjust_counts(pgs, delta)\
  131.   cs_adjust_color_count(pgs, delta), cs_adjust_cspace_count(pgs, delta)
  132.  
  133.     /* Enumerate the pointers in a color space. */
  134.  
  135.     struct_proc_enum_ptrs((*enum_ptrs));
  136.  
  137.     /* Relocate the pointers in a color space. */
  138.  
  139.     struct_proc_reloc_ptrs((*reloc_ptrs));
  140.  
  141. } gs_color_space_type;
  142. /* Standard color space procedures */
  143. cs_proc_init_color(gx_init_paint_1);
  144. cs_proc_init_color(gx_init_paint_3);
  145. cs_proc_install_cspace(gx_no_install_cspace);
  146. cs_proc_adjust_cspace_count(gx_no_adjust_cspace_count);
  147. cs_proc_adjust_color_count(gx_no_adjust_color_count);
  148. #define gx_no_cspace_enum_ptrs gs_no_struct_enum_ptrs
  149. #define gx_no_cspace_reloc_ptrs gs_no_struct_reloc_ptrs
  150.  
  151. /* Standard color space types */
  152. extern const gs_color_space_type
  153.     gs_color_space_type_DeviceGray,
  154.     gs_color_space_type_DeviceRGB,
  155.     gs_color_space_type_DeviceCMYK;
  156.  
  157.     /* Base color spaces (Device and CIE) */
  158.  
  159. typedef struct gs_cie_abc_s gs_cie_abc;
  160. typedef struct gs_cie_a_s gs_cie_a;
  161. #define gs_base_cspace_params\
  162.     gs_cie_abc *abc;\
  163.     gs_cie_a *a
  164. typedef struct gs_base_color_space_s {
  165.     const gs_color_space_type _ds *type;
  166.     union {
  167.         gs_base_cspace_params;
  168.     } params;
  169. } gs_base_color_space;
  170.  
  171.     /* Paint (non-pattern) color spaces (base + Separation + Indexed) */
  172.  
  173. typedef ulong gs_separation_name;        /* BOGUS */
  174.  
  175. typedef struct gs_indexed_map_s gs_indexed_map;
  176. typedef struct gs_separation_params_s {
  177.     gs_separation_name sname;
  178.     gs_base_color_space alt_space;
  179.     gs_indexed_map *map;
  180. } gs_separation_params;
  181. typedef struct gs_indexed_params_s {
  182.     gs_base_color_space base_space;
  183.     int hival;
  184.     union {
  185.         gs_const_string table;    /* size is implicit */
  186.         gs_indexed_map *map;
  187.     } lookup;
  188.     bool use_proc;        /* 0 = use table, 1 = use proc & map */
  189. } gs_indexed_params;
  190. #define gs_paint_cspace_params\
  191.     gs_base_cspace_params;\
  192.     gs_separation_params separation;\
  193.     gs_indexed_params indexed
  194. typedef struct gs_paint_color_space_s {
  195.     const gs_color_space_type _ds *type;
  196.     union {
  197.         gs_paint_cspace_params;
  198.     } params;
  199. } gs_paint_color_space;
  200.  
  201.     /* General color spaces (including patterns) */
  202.  
  203. typedef struct gs_pattern_params_s {
  204.     bool has_base_space;
  205.     gs_paint_color_space base_space;
  206. } gs_pattern_params;
  207. struct gs_color_space_s {
  208.     const gs_color_space_type _ds *type;
  209.     union {
  210.         gs_paint_cspace_params;
  211.         gs_pattern_params pattern;
  212.     } params;
  213. };
  214. extern_st(st_color_space);
  215. #define public_st_color_space()    /* in gscolor.c */\
  216.   gs_public_st_composite(st_color_space, gs_color_space,\
  217.     "gs_color_space", color_space_enum_ptrs, color_space_reloc_ptrs)
  218. #define st_color_space_max_ptrs 2 /* 1 base + 1 indexed */
  219.  
  220. #endif                    /* gscspace_INCLUDED */
  221.