gdevxcmp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevxcmp.h,v 1.4 2002/02/21 22:24:52 giles Exp $ */
  14. /* X driver color mapping structure */
  15. #ifndef gdevxcmp_INCLUDED
  16. # define gdevxcmp_INCLUDED
  17. /*
  18. * The structure defined in this file is used in only one place, in the
  19. * gx_device_X structure defined in gdevx.h. We define it as a separate
  20. * structure because its function is logically separate from the rest of the
  21. * X driver, and because this function (color mapping / management) accounts
  22. * for the single largest piece of the driver.
  23. */
  24. /* Define pixel value to RGB mapping */
  25. typedef struct x11_rgb_s {
  26. gx_color_value rgb[3];
  27. bool defined;
  28. } x11_rgb_t;
  29. /* Define dynamic color hash table structure */
  30. typedef struct x11_color_s x11_color_t;
  31. struct x11_color_s {
  32. XColor color;
  33. x11_color_t *next;
  34. };
  35. /*
  36. * Define X color values. Fortuitously, these are the same as Ghostscript
  37. * color values; in gdevxcmp.c, we are pretty sloppy about aliasing the
  38. * two.
  39. */
  40. typedef ushort X_color_value;
  41. #define X_max_color_value 0xffff
  42. #if HaveStdCMap /* Standard colormap stuff is only in X11R4 and later. */
  43. /* Define the structure for values computed from a standard cmap component. */
  44. typedef struct x11_cmap_values_s {
  45. int cv_shift; /* 16 - log2(max_value + 1) */
  46. X_color_value nearest[64]; /* [i] = i * 0xffff / max_value */
  47. int pixel_shift; /* log2(mult) */
  48. } x11_cmap_values_t;
  49. #endif
  50. typedef struct x11_cman_s {
  51. /*
  52. * num_rgb is the number of possible R/G/B values, i.e.,
  53. * 1 << the bits_per_rgb of the X visual.
  54. */
  55. int num_rgb;
  56. /*
  57. * color_mask is a mask that selects the high-order N bits of an
  58. * X color value, where N may be the mask width for TrueColor or
  59. * StaticGray and is bits_per_rgb for the other visual classes.
  60. *
  61. * match_mask is the mask used for comparing colors. It may have
  62. * fewer bits than color_mask if the device is not using halftones.
  63. */
  64. struct cmm_ {
  65. X_color_value red, green, blue;
  66. } color_mask, match_mask;
  67. #if HaveStdCMap /* Standard colormap stuff is only in X11R4 and later. */
  68. struct {
  69. /*
  70. * map is the X standard colormap for the display and screen,
  71. * if one is available.
  72. */
  73. XStandardColormap *map;
  74. /*
  75. * When possible, we precompute shift values and tables that replace
  76. * some multiplies and divides.
  77. */
  78. bool fast;
  79. x11_cmap_values_t red, green, blue;
  80. /*
  81. * If free_map is true, we allocated the map ourselves (to
  82. * represent a TrueColor or Static Gray visual), and must free it
  83. * when closing the device.
  84. */
  85. bool free_map;
  86. } std_cmap;
  87. #endif /* HaveStdCmap */
  88. /*
  89. * color_to_rgb is a reverse map from pixel values to RGB values. It
  90. * only maps pixels values up to 255: pixel values above this must go
  91. * through the standard colormap or query the server.
  92. */
  93. struct cmc_ {
  94. int size; /* min(1 << depth, 256) */
  95. x11_rgb_t *values; /* [color_to_rgb.size] */
  96. } color_to_rgb;
  97. /*
  98. * For systems with writable colormaps and no suitable standard
  99. * colormap, dither_ramp is a preallocated ramp or cube used for
  100. * dithering.
  101. */
  102. #define CUBE_INDEX(r,g,b) (((r) * xdev->color_info.dither_colors + (g)) * \
  103. xdev->color_info.dither_colors + (b))
  104. x_pixel *dither_ramp; /* [color_info.dither_colors^3] if color,
  105. [color_info.dither_grays] if gray */
  106. /*
  107. * For systems with writable colormaps, dynamic.colors is a chained
  108. * hash table that maps RGB values (masked with color_mask) to
  109. * pixel values. Entries are added dynamically.
  110. */
  111. struct cmd_ {
  112. int size;
  113. x11_color_t **colors; /* [size] */
  114. int shift; /* 16 - log2(size) */
  115. int used;
  116. int max_used;
  117. } dynamic;
  118. } x11_cman_t;
  119. #endif /* gdevxcmp_INCLUDED */