gxbitops.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright (C) 1997, 1998 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: gxbitops.h,v 1.4 2002/02/21 22:24:52 giles Exp $ */
  14. /* Internal definitions for bitmap operations */
  15. #ifndef gxbitops_INCLUDED
  16. # define gxbitops_INCLUDED
  17. #include "gsbitops.h"
  18. /*
  19. * Macros for processing bitmaps in the largest possible chunks.
  20. * Bits within a byte are always stored big-endian;
  21. * bytes are likewise stored in left-to-right order, i.e., big-endian.
  22. * Note that this is the format used for the source of copy_mono.
  23. * It used to be the case that bytes were stored in the natural
  24. * platform order, and the client had force them into big-endian order
  25. * by calling gdev_mem_ensure_byte_order, but this no longer necessary.
  26. *
  27. * Note that we use type uint for register variables holding a chunk:
  28. * for this reason, the chunk size cannot be larger than uint.
  29. */
  30. /* Generic macros for chunk accessing. */
  31. #define cbytes(ct) size_of(ct) /* sizeof may be unsigned */
  32. # define chunk_bytes cbytes(chunk)
  33. /* The clog2_bytes macro assumes that ints are 2, 4, or 8 bytes in size. */
  34. #define clog2_bytes(ct) (size_of(ct) == 8 ? 3 : size_of(ct)>>1)
  35. # define chunk_log2_bytes clog2_bytes(chunk)
  36. #define cbits(ct) (size_of(ct)*8) /* sizeof may be unsigned */
  37. # define chunk_bits cbits(chunk)
  38. #define clog2_bits(ct) (clog2_bytes(ct)+3)
  39. # define chunk_log2_bits clog2_bits(chunk)
  40. #define cbit_mask(ct) (cbits(ct)-1)
  41. # define chunk_bit_mask cbit_mask(chunk)
  42. #define calign_bytes(ct)\
  43. (sizeof(ct) == 1 ? 1:\
  44. sizeof(ct) == sizeof(short) ? arch_align_short_mod :\
  45. sizeof(ct) == sizeof(int) ? arch_align_int_mod : arch_align_long_mod)
  46. # define chunk_align_bytes calign_bytes(chunk)
  47. #define calign_bit_mask(ct) (calign_bytes(ct)*8-1)
  48. # define chunk_align_bit_mask calign_bit_mask(chunk)
  49. /*
  50. * The obvious definition for cmask is:
  51. * #define cmask(ct) ((ct)~(ct)0)
  52. * but this doesn't work on the VAX/VMS compiler, which fails to truncate
  53. * the value to 16 bits when ct is ushort.
  54. * Instead, we have to generate the mask with no extra 1-bits.
  55. * We can't do this in the obvious way:
  56. * #define cmask(ct) ((1 << (size_of(ct) * 8)) - 1)
  57. * because some compilers won't allow a shift of the full type size.
  58. * Instead, we have to do something really awkward:
  59. */
  60. #define cmask(ct) ((ct) (((((ct)1 << (size_of(ct)*8-2)) - 1) << 2) + 3))
  61. # define chunk_all_bits cmask(chunk)
  62. /*
  63. * The obvious definition for chi_bits is:
  64. * #define chi_bits(ct,n) (cmask(ct)-(cmask(ct)>>(n)))
  65. * but this doesn't work on the DEC/MIPS compilers.
  66. * Instead, we have to restrict chi_bits to only working for values of n
  67. * between 0 and cbits(ct)-1, and use
  68. */
  69. #define chi_bits(ct,n) (ct)(~(ct)1 << (cbits(ct)-1 - (n)))
  70. # define chunk_hi_bits(n) chi_bits(chunk,n)
  71. /* Define whether this is a machine where chunks are long, */
  72. /* but the machine can't shift a long by its full width. */
  73. #define arch_cant_shift_full_chunk\
  74. (arch_is_big_endian && !arch_ints_are_short && !arch_can_shift_full_long)
  75. /* Pointer arithmetic macros. */
  76. #define inc_ptr(ptr,delta)\
  77. (ptr = (void *)((byte *)ptr + (delta)))
  78. /* Define macros for setting up left- and right-end masks. */
  79. /* These are used for monobit operations, and for filling */
  80. /* with 2- and 4-bit-per-pixel patterns. */
  81. /*
  82. * Define the chunk size for monobit copying operations.
  83. */
  84. #if arch_is_big_endian
  85. # define mono_copy_chunk uint
  86. # define set_mono_right_mask(var, w)\
  87. (var = ((w) == chunk_bits ? chunk_all_bits : chunk_hi_bits(w)))
  88. /*
  89. * We have to split the following statement because of a bug in the Xenix C
  90. * compiler (it produces a signed rather than an unsigned shift if we don't
  91. * split).
  92. */
  93. # define set_mono_thin_mask(var, w, bit)\
  94. set_mono_right_mask(var, w), var >>= (bit)
  95. /*
  96. * We have to split the following statement in two because of a bug
  97. * in the DEC VAX/VMS C compiler.
  98. */
  99. # define set_mono_left_mask(var, bit)\
  100. (var = chunk_all_bits, var >>= (bit))
  101. #else
  102. # define mono_copy_chunk bits16
  103. extern const bits16 mono_copy_masks[17];
  104. # if mono_fill_chunk_bytes == 2
  105. # define mono_fill_masks mono_copy_masks
  106. # else
  107. extern const bits32 mono_fill_masks[33];
  108. # endif
  109. /*
  110. * We define mono_masks as either mono_fill_masks or
  111. * mono_copy_masks before using the following macros.
  112. */
  113. # define set_mono_left_mask(var, bit)\
  114. (var = mono_masks[bit])
  115. # define set_mono_thin_mask(var, w, bit)\
  116. (var = ~mono_masks[(w) + (bit)] & mono_masks[bit])
  117. # define set_mono_right_mask(var, ebit)\
  118. (var = ~mono_masks[ebit])
  119. #endif
  120. #endif /* gxbitops_INCLUDED */