picture.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. *
  3. * Copyright © 2000 SuSE, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of SuSE not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. SuSE makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as is"
  13. * without express or implied warranty.
  14. *
  15. * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  17. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21. *
  22. * Author: Keith Packard, SuSE, Inc.
  23. */
  24. #ifndef _PICTURE_H_
  25. #define _PICTURE_H_
  26. typedef struct _DirectFormat *DirectFormatPtr;
  27. typedef struct _PictFormat *PictFormatPtr;
  28. typedef struct _Picture *PicturePtr;
  29. /*
  30. * While the protocol is generous in format support, the
  31. * sample implementation allows only packed RGB and GBR
  32. * representations for data to simplify software rendering,
  33. */
  34. #define PICT_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) | \
  35. ((type) << 16) | \
  36. ((a) << 12) | \
  37. ((r) << 8) | \
  38. ((g) << 4) | \
  39. ((b)))
  40. /*
  41. * gray/color formats use a visual index instead of argb
  42. */
  43. #define PICT_VISFORMAT(bpp,type,vi) (((bpp) << 24) | \
  44. ((type) << 16) | \
  45. ((vi)))
  46. #define PICT_FORMAT_BPP(f) (((f) >> 24) )
  47. #define PICT_FORMAT_TYPE(f) (((f) >> 16) & 0xff)
  48. #define PICT_FORMAT_A(f) (((f) >> 12) & 0x0f)
  49. #define PICT_FORMAT_R(f) (((f) >> 8) & 0x0f)
  50. #define PICT_FORMAT_G(f) (((f) >> 4) & 0x0f)
  51. #define PICT_FORMAT_B(f) (((f) ) & 0x0f)
  52. #define PICT_FORMAT_RGB(f) (((f) ) & 0xfff)
  53. #define PICT_FORMAT_VIS(f) (((f) ) & 0xffff)
  54. #define PICT_TYPE_OTHER 0
  55. #define PICT_TYPE_A 1
  56. #define PICT_TYPE_ARGB 2
  57. #define PICT_TYPE_ABGR 3
  58. #define PICT_TYPE_COLOR 4
  59. #define PICT_TYPE_GRAY 5
  60. #define PICT_FORMAT_COLOR(f) (PICT_FORMAT_TYPE(f) & 2)
  61. /* 32bpp formats */
  62. typedef enum _PictFormatShort {
  63. PICT_a8r8g8b8 = PICT_FORMAT(32, PICT_TYPE_ARGB, 8, 8, 8, 8),
  64. PICT_x8r8g8b8 = PICT_FORMAT(32, PICT_TYPE_ARGB, 0, 8, 8, 8),
  65. PICT_a8b8g8r8 = PICT_FORMAT(32, PICT_TYPE_ABGR, 8, 8, 8, 8),
  66. PICT_x8b8g8r8 = PICT_FORMAT(32, PICT_TYPE_ABGR, 0, 8, 8, 8),
  67. /* 24bpp formats */
  68. PICT_r8g8b8 = PICT_FORMAT(24, PICT_TYPE_ARGB, 0, 8, 8, 8),
  69. PICT_b8g8r8 = PICT_FORMAT(24, PICT_TYPE_ABGR, 0, 8, 8, 8),
  70. /* 16bpp formats */
  71. PICT_r5g6b5 = PICT_FORMAT(16, PICT_TYPE_ARGB, 0, 5, 6, 5),
  72. PICT_b5g6r5 = PICT_FORMAT(16, PICT_TYPE_ABGR, 0, 5, 6, 5),
  73. PICT_a1r5g5b5 = PICT_FORMAT(16, PICT_TYPE_ARGB, 1, 5, 5, 5),
  74. PICT_x1r5g5b5 = PICT_FORMAT(16, PICT_TYPE_ARGB, 0, 5, 5, 5),
  75. PICT_a1b5g5r5 = PICT_FORMAT(16, PICT_TYPE_ABGR, 1, 5, 5, 5),
  76. PICT_x1b5g5r5 = PICT_FORMAT(16, PICT_TYPE_ABGR, 0, 5, 5, 5),
  77. PICT_a4r4g4b4 = PICT_FORMAT(16, PICT_TYPE_ARGB, 4, 4, 4, 4),
  78. PICT_x4r4g4b4 = PICT_FORMAT(16, PICT_TYPE_ARGB, 0, 4, 4, 4),
  79. PICT_a4b4g4r4 = PICT_FORMAT(16, PICT_TYPE_ABGR, 4, 4, 4, 4),
  80. PICT_x4b4g4r4 = PICT_FORMAT(16, PICT_TYPE_ABGR, 0, 4, 4, 4),
  81. /* 8bpp formats */
  82. PICT_a8 = PICT_FORMAT(8, PICT_TYPE_A, 8, 0, 0, 0),
  83. PICT_r3g3b2 = PICT_FORMAT(8, PICT_TYPE_ARGB, 0, 3, 3, 2),
  84. PICT_b2g3r3 = PICT_FORMAT(8, PICT_TYPE_ABGR, 0, 3, 3, 2),
  85. PICT_a2r2g2b2 = PICT_FORMAT(8, PICT_TYPE_ARGB, 2, 2, 2, 2),
  86. PICT_a2b2g2r2 = PICT_FORMAT(8, PICT_TYPE_ABGR, 2, 2, 2, 2),
  87. PICT_c8 = PICT_FORMAT(8, PICT_TYPE_COLOR, 0, 0, 0, 0),
  88. PICT_g8 = PICT_FORMAT(8, PICT_TYPE_GRAY, 0, 0, 0, 0),
  89. PICT_x4a4 = PICT_FORMAT(8, PICT_TYPE_A, 4, 0, 0, 0),
  90. PICT_x4c4 = PICT_FORMAT(8, PICT_TYPE_COLOR, 0, 0, 0, 0),
  91. PICT_x4g4 = PICT_FORMAT(8, PICT_TYPE_GRAY, 0, 0, 0, 0),
  92. /* 4bpp formats */
  93. PICT_a4 = PICT_FORMAT(4, PICT_TYPE_A, 4, 0, 0, 0),
  94. PICT_r1g2b1 = PICT_FORMAT(4, PICT_TYPE_ARGB, 0, 1, 2, 1),
  95. PICT_b1g2r1 = PICT_FORMAT(4, PICT_TYPE_ABGR, 0, 1, 2, 1),
  96. PICT_a1r1g1b1 = PICT_FORMAT(4, PICT_TYPE_ARGB, 1, 1, 1, 1),
  97. PICT_a1b1g1r1 = PICT_FORMAT(4, PICT_TYPE_ABGR, 1, 1, 1, 1),
  98. PICT_c4 = PICT_FORMAT(4, PICT_TYPE_COLOR, 0, 0, 0, 0),
  99. PICT_g4 = PICT_FORMAT(4, PICT_TYPE_GRAY, 0, 0, 0, 0),
  100. /* 1bpp formats */
  101. PICT_a1 = PICT_FORMAT(1, PICT_TYPE_A, 1, 0, 0, 0),
  102. PICT_g1 = PICT_FORMAT(1, PICT_TYPE_GRAY, 0, 0, 0, 0),
  103. } PictFormatShort;
  104. /*
  105. * For dynamic indexed visuals (GrayScale and PseudoColor), these control the
  106. * selection of colors allocated for drawing to Pictures. The default
  107. * policy depends on the size of the colormap:
  108. *
  109. * Size Default Policy
  110. * ----------------------------
  111. * < 64 PolicyMono
  112. * < 256 PolicyGray
  113. * 256 PolicyColor (only on PseudoColor)
  114. *
  115. * The actual allocation code lives in miindex.c, and so is
  116. * austensibly server dependent, but that code does:
  117. *
  118. * PolicyMono Allocate no additional colors, use black and white
  119. * PolicyGray Allocate 13 gray levels (11 cells used)
  120. * PolicyColor Allocate a 4x4x4 cube and 13 gray levels (71 cells used)
  121. * PolicyAll Allocate as big a cube as possible, fill with gray (all)
  122. *
  123. * Here's a picture to help understand how many colors are
  124. * actually allocated (this is just the gray ramp):
  125. *
  126. * gray level
  127. * all 0000 1555 2aaa 4000 5555 6aaa 8000 9555 aaaa bfff d555 eaaa ffff
  128. * b/w 0000 ffff
  129. * 4x4x4 5555 aaaa
  130. * extra 1555 2aaa 4000 6aaa 8000 9555 bfff d555 eaaa
  131. *
  132. * The default colormap supplies two gray levels (black/white), the
  133. * 4x4x4 cube allocates another two and nine more are allocated to fill
  134. * in the 13 levels. When the 4x4x4 cube is not allocated, a total of
  135. * 11 cells are allocated.
  136. */
  137. #define PictureCmapPolicyInvalid -1
  138. #define PictureCmapPolicyDefault 0
  139. #define PictureCmapPolicyMono 1
  140. #define PictureCmapPolicyGray 2
  141. #define PictureCmapPolicyColor 3
  142. #define PictureCmapPolicyAll 4
  143. extern int PictureCmapPolicy;
  144. int PictureParseCmapPolicy(const char *name);
  145. extern int RenderErrBase;
  146. extern int RenderClientPrivateIndex;
  147. /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
  148. # if defined (_LP64) || \
  149. defined(__alpha__) || defined(__alpha) || \
  150. defined(ia64) || defined(__ia64__) || \
  151. defined(__sparc64__) || \
  152. defined(__s390x__) || \
  153. defined(amd64) || defined (__amd64__) || \
  154. (defined(sgi) && (_MIPS_SZLONG == 64))
  155. typedef long xFixed_32_32;
  156. # else
  157. # if defined(__GNUC__) && \
  158. ((__GNUC__ > 2) || \
  159. ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 7)))
  160. __extension__
  161. # endif
  162. typedef long long int xFixed_32_32;
  163. # endif
  164. typedef xFixed_32_32 xFixed_48_16;
  165. #define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff)
  166. #define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31))
  167. typedef CARD32 xFixed_1_31;
  168. typedef CARD32 xFixed_1_16;
  169. typedef INT32 xFixed_16_16;
  170. /*
  171. * An unadorned "xFixed" is the same as xFixed_16_16,
  172. * (since it's quite common in the code)
  173. */
  174. typedef xFixed_16_16 xFixed;
  175. #define XFIXED_BITS 16
  176. #define xFixedToInt(f) (int) ((f) >> XFIXED_BITS)
  177. #define IntToxFixed(i) ((xFixed) (i) << XFIXED_BITS)
  178. #define xFixedE ((xFixed) 1)
  179. #define xFixed1 (IntToxFixed(1))
  180. #define xFixed1MinusE (xFixed1 - xFixedE)
  181. #define xFixedFrac(f) ((f) & xFixed1MinusE)
  182. #define xFixedFloor(f) ((f) & ~xFixed1MinusE)
  183. #define xFixedCeil(f) xFixedFloor((f) + xFixed1MinusE)
  184. #define xFixedFraction(f) ((f) & xFixed1MinusE)
  185. #define xFixedMod2(f) ((f) & (xFixed1 | xFixed1MinusE))
  186. /* whether 't' is a well defined not obviously empty trapezoid */
  187. #define xTrapezoidValid(t) ((t)->left.p1.y != (t)->left.p2.y && \
  188. (t)->right.p1.y != (t)->right.p2.y && \
  189. (int) ((t)->bottom - (t)->top) > 0)
  190. /*
  191. * Standard NTSC luminance conversions:
  192. *
  193. * y = r * 0.299 + g * 0.587 + b * 0.114
  194. *
  195. * Approximate this for a bit more speed:
  196. *
  197. * y = (r * 153 + g * 301 + b * 58) / 512
  198. *
  199. * This gives 17 bits of luminance; to get 15 bits, lop the low two
  200. */
  201. #define CvtR8G8B8toY15(s) (((((s) >> 16) & 0xff) * 153 + \
  202. (((s) >> 8) & 0xff) * 301 + \
  203. (((s) ) & 0xff) * 58) >> 2)
  204. #endif /* _PICTURE_H_ */