home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / halftone.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  15.4 KB  |  315 lines

  1. /****************************************************************************
  2. *
  3. *                       MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1996 SciTech Software.
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $Workfile:   halftone.c  $
  9. * Version:      $Revision:   1.8  $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MS DOS)
  13. *
  14. * Description:  Default HalfTone palette and associated lookup tables
  15. *               for performing fast halftone dithering.
  16. *
  17. *               The halftone palette is set up to use entries from 20 to
  18. *               226 in the physical palette, leaving the top 20 and bottom
  19. *               20 for operating system specific use.
  20. *
  21. * $Date:   07 Apr 1997 17:21:54  $ $Author:   KendallB  $
  22. *
  23. ****************************************************************************/
  24.  
  25. #include "mgl.h"
  26. #include <string.h>
  27.  
  28. /*------------------------- Implementation --------------------------------*/
  29.  
  30. void MGLAPI MGL_getHalfTonePalette(palette_t *pal)
  31. { memcpy(pal,_MGL_halftonePal,sizeof(palette_t) * 256); }
  32.  
  33. uchar MGLAPI MGL_halfTonePixel(int x,int y,uchar R,uchar G,uchar B)
  34. /****************************************************************************
  35. *
  36. * Function:     MGL_halfTonePixel
  37. * Parameters:   x,y     - Pixel coordinate (only needs to be relative)
  38. *               R,G,B   - RGB value for the pixel (8 bit components)
  39. * Returns:      Color index for the pixel in default HalfTone palette
  40. *
  41. * Description:  Compute the index in the color table for a specified
  42. *               24 bit RGB pixel value. This routine uses fast table
  43. *               lookup and an 8x8 ordered dither to do the conversion.
  44. *
  45. ****************************************************************************/
  46. {
  47.     uchar dither = _MGL_dither8x8[((x & 7) << 3) + (y & 7)];
  48.     return 20 +
  49.         _MGL_div51[R] + (_MGL_mod51[R] > dither) +
  50.         _MGL_mul6[_MGL_div51[G] + (_MGL_mod51[G] > dither)] +
  51.         _MGL_mul36[_MGL_div51[B] + (_MGL_mod51[B] > dither)];
  52. }
  53.  
  54. ushort MGLAPI MGL_halfTonePixel555(int x,int y,uchar R,uchar G,uchar B)
  55. /****************************************************************************
  56. *
  57. * Function:     MGL_halfTonePixel555
  58. * Parameters:   x,y     - Pixel coordinate (only needs to be relative)
  59. *               R,G,B   - RGB value for the pixel (8 bit components)
  60. * Returns:      Color index for the pixel in default HalfTone palette
  61. *
  62. * Description:  Compute the index in the color table for a specified
  63. *               24 bit RGB pixel value. This routine uses fast table
  64. *               lookup and an 8x8 ordered dither to do the conversion.
  65. *
  66. ****************************************************************************/
  67. {
  68.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];
  69.     return (ushort)
  70.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 10) +
  71.         (((ulong)_MGL_div8[G] + (_MGL_mod8[G] > _dither)) << 5) +
  72.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));
  73. }
  74.  
  75. ushort MGLAPI MGL_halfTonePixel565(int x,int y,uchar R,uchar G,uchar B)
  76. /****************************************************************************
  77. *
  78. * Function:     MGL_halfTonePixel565
  79. * Parameters:   x,y     - Pixel coordinate (only needs to be relative)
  80. *               R,G,B   - RGB value for the pixel (8 bit components)
  81. * Returns:      Color index for the pixel in default HalfTone palette
  82. *
  83. * Description:  Compute the index in the color table for a specified
  84. *               24 bit RGB pixel value. This routine uses fast table
  85. *               lookup and an 8x8 ordered dither to do the conversion.
  86. *
  87. ****************************************************************************/
  88. {
  89.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];
  90.     return (ushort)
  91.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 11) +
  92.         (((ulong)_MGL_div4[G] + (_MGL_mod4[G] > (_dither>>1))) << 5) +
  93.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));
  94. }
  95.  
  96. /*------------------------- Lookup Tables ---------------------------------*/
  97.  
  98. /* Default windows compatible halftone palette. This includes the default
  99.  * Windows system colors in the first 10 and last 10 entries in the
  100.  * palette.
  101.  */
  102.  
  103. palette_t _VARAPI _MGL_halftonePal[256] = {
  104.     {0x00,0x00,0x00,0}, {0xA8,0x00,0x00,0}, {0x00,0xA8,0x00,0}, {0xA8,0xA8,0x00,0},
  105.     {0x00,0x00,0xA8,0}, {0xA8,0x00,0xA8,0}, {0x00,0x54,0xA8,0}, {0xA8,0xA8,0xA8,0},
  106.     {0x54,0x54,0x54,0}, {0xFC,0x54,0x54,0}, {0x54,0xFC,0x54,0}, {0xFC,0xFC,0x54,0},
  107.     {0x54,0x54,0xFC,0}, {0xFC,0x54,0xFC,0}, {0x54,0xFC,0xFC,0}, {0xFC,0xFC,0xFC,0},
  108.     {0x00,0x00,0x00,0}, {0x14,0x14,0x14,0}, {0x20,0x20,0x20,0}, {0x2C,0x2C,0x2C,0},
  109.     {0x00,0x00,0x00,0}, {0x00,0x00,0x33,0}, {0x00,0x00,0x66,0}, {0x00,0x00,0x99,0},
  110.     {0x00,0x00,0xCC,0}, {0x00,0x00,0xFF,0}, {0x00,0x33,0x00,0}, {0x00,0x33,0x33,0},
  111.     {0x00,0x33,0x66,0}, {0x00,0x33,0x99,0}, {0x00,0x33,0xCC,0}, {0x00,0x33,0xFF,0},
  112.     {0x00,0x66,0x00,0}, {0x00,0x66,0x33,0}, {0x00,0x66,0x66,0}, {0x00,0x66,0x99,0},
  113.     {0x00,0x66,0xCC,0}, {0x00,0x66,0xFF,0}, {0x00,0x99,0x00,0}, {0x00,0x99,0x33,0},
  114.     {0x00,0x99,0x66,0}, {0x00,0x99,0x99,0}, {0x00,0x99,0xCC,0}, {0x00,0x99,0xFF,0},
  115.     {0x00,0xCC,0x00,0}, {0x00,0xCC,0x33,0}, {0x00,0xCC,0x66,0}, {0x00,0xCC,0x99,0},
  116.     {0x00,0xCC,0xCC,0}, {0x00,0xCC,0xFF,0}, {0x00,0xFF,0x00,0}, {0x00,0xFF,0x00,0},
  117.     {0x00,0xFF,0x66,0}, {0x00,0xFF,0x99,0}, {0x00,0xFF,0xCC,0}, {0x00,0xFF,0xFF,0},
  118.     {0x33,0x00,0x00,0}, {0x33,0x00,0x33,0}, {0x33,0x00,0x66,0}, {0x33,0x00,0x99,0},
  119.     {0x33,0x00,0xCC,0}, {0x33,0x00,0xFF,0}, {0x33,0x33,0x00,0}, {0x33,0x33,0x33,0},
  120.     {0x33,0x33,0x66,0}, {0x33,0x33,0x99,0}, {0x33,0x33,0xCC,0}, {0x33,0x33,0xFF,0},
  121.     {0x33,0x66,0x00,0}, {0x33,0x66,0x33,0}, {0x33,0x66,0x66,0}, {0x33,0x66,0x99,0},
  122.     {0x33,0x66,0xCC,0}, {0x33,0x66,0xFF,0}, {0x33,0x99,0x00,0}, {0x33,0x99,0x33,0},
  123.     {0x33,0x99,0x66,0}, {0x33,0x99,0x99,0}, {0x33,0x99,0xCC,0}, {0x33,0x99,0xFF,0},
  124.     {0x33,0xCC,0x00,0}, {0x33,0xCC,0x33,0}, {0x33,0xCC,0x66,0}, {0x33,0xCC,0x99,0},
  125.     {0x33,0xCC,0xCC,0}, {0x33,0xCC,0xFF,0}, {0x00,0xFF,0x00,0}, {0x33,0xFF,0x33,0},
  126.     {0x33,0xFF,0x66,0}, {0x33,0xFF,0x99,0}, {0x33,0xFF,0xCC,0}, {0x33,0xFF,0xFF,0},
  127.     {0x66,0x00,0x00,0}, {0x66,0x00,0x33,0}, {0x66,0x00,0x66,0}, {0x66,0x00,0x99,0},
  128.     {0x66,0x00,0xCC,0}, {0x66,0x00,0xFF,0}, {0x66,0x33,0x00,0}, {0x66,0x33,0x33,0},
  129.     {0x66,0x33,0x66,0}, {0x66,0x33,0x99,0}, {0x66,0x33,0xCC,0}, {0x66,0x33,0xFF,0},
  130.     {0x66,0x66,0x00,0}, {0x66,0x66,0x33,0}, {0x66,0x66,0x66,0}, {0x66,0x66,0x99,0},
  131.     {0x66,0x66,0xCC,0}, {0x66,0x66,0xFF,0}, {0x66,0x99,0x00,0}, {0x66,0x99,0x33,0},
  132.     {0x66,0x99,0x66,0}, {0x66,0x99,0x99,0}, {0x66,0x99,0xCC,0}, {0x66,0x99,0xFF,0},
  133.     {0x66,0xCC,0x00,0}, {0x66,0xCC,0x33,0}, {0x66,0xCC,0x66,0}, {0x66,0xCC,0x99,0},
  134.     {0x66,0xCC,0xCC,0}, {0x66,0xCC,0xFF,0}, {0x66,0xFF,0x00,0}, {0x66,0xFF,0x33,0},
  135.     {0x66,0xFF,0x66,0}, {0x66,0xFF,0x99,0}, {0x66,0xFF,0xCC,0}, {0x66,0xFF,0xFF,0},
  136.     {0x99,0x00,0x00,0}, {0x99,0x00,0x33,0}, {0x99,0x00,0x66,0}, {0x99,0x00,0x99,0},
  137.     {0x99,0x00,0xCC,0}, {0x99,0x00,0xFF,0}, {0x99,0x33,0x00,0}, {0x99,0x33,0x33,0},
  138.     {0x99,0x33,0x66,0}, {0x99,0x33,0x99,0}, {0x99,0x33,0xCC,0}, {0x99,0x33,0xFF,0},
  139.     {0x99,0x66,0x00,0}, {0x99,0x66,0x33,0}, {0x99,0x66,0x66,0}, {0x99,0x66,0x99,0},
  140.     {0x99,0x66,0xCC,0}, {0x99,0x66,0xFF,0}, {0x99,0x99,0x00,0}, {0x99,0x99,0x33,0},
  141.     {0x99,0x99,0x66,0}, {0x99,0x99,0x99,0}, {0x99,0x99,0xCC,0}, {0x99,0x99,0xFF,0},
  142.     {0x99,0xCC,0x00,0}, {0x99,0xCC,0x33,0}, {0x99,0xCC,0x66,0}, {0x99,0xCC,0x99,0},
  143.     {0x99,0xCC,0xCC,0}, {0x99,0xCC,0xFF,0}, {0x99,0xFF,0x00,0}, {0x99,0xFF,0x33,0},
  144.     {0x99,0xFF,0x66,0}, {0x99,0xFF,0x99,0}, {0x99,0xFF,0xCC,0}, {0x99,0xFF,0xFF,0},
  145.     {0xCC,0x00,0x00,0}, {0xCC,0x00,0x33,0}, {0xCC,0x00,0x66,0}, {0xCC,0x00,0x99,0},
  146.     {0xCC,0x00,0xCC,0}, {0xCC,0x00,0xFF,0}, {0xCC,0x33,0x00,0}, {0xCC,0x33,0x33,0},
  147.     {0xCC,0x33,0x66,0}, {0xCC,0x33,0x99,0}, {0xCC,0x33,0xCC,0}, {0xCC,0x33,0xFF,0},
  148.     {0xCC,0x66,0x00,0}, {0xCC,0x66,0x33,0}, {0xCC,0x66,0x66,0}, {0xCC,0x66,0x99,0},
  149.     {0xCC,0x66,0xCC,0}, {0xCC,0x66,0xFF,0}, {0xCC,0x99,0x00,0}, {0xCC,0x99,0x33,0},
  150.     {0xCC,0x99,0x66,0}, {0xCC,0x99,0x99,0}, {0xCC,0x99,0xCC,0}, {0xCC,0x99,0xFF,0},
  151.     {0xCC,0xCC,0x00,0}, {0xCC,0xCC,0x33,0}, {0xCC,0xCC,0x66,0}, {0xCC,0xCC,0x99,0},
  152.     {0xCC,0xCC,0xCC,0}, {0xCC,0xCC,0xFF,0}, {0xCC,0xFF,0x00,0}, {0xCC,0xFF,0x33,0},
  153.     {0xCC,0xFF,0x66,0}, {0xCC,0xFF,0x99,0}, {0xCC,0xFF,0xCC,0}, {0xCC,0xFF,0xFF,0},
  154.     {0xFF,0x00,0x00,0}, {0xFF,0x00,0x00,0}, {0xFF,0x00,0x66,0}, {0xFF,0x00,0x99,0},
  155.     {0xFF,0x00,0xCC,0}, {0xFF,0x00,0xFF,0}, {0xFF,0x00,0x00,0}, {0xFF,0x33,0x33,0},
  156.     {0xFF,0x33,0x66,0}, {0xFF,0x33,0x99,0}, {0xFF,0x33,0xCC,0}, {0xFF,0x33,0xFF,0},
  157.     {0xFF,0x66,0x00,0}, {0xFF,0x66,0x33,0}, {0xFF,0x66,0x66,0}, {0xFF,0x66,0x99,0},
  158.     {0xFF,0x66,0xCC,0}, {0xFF,0x66,0xFF,0}, {0xFF,0x99,0x00,0}, {0xFF,0x99,0x33,0},
  159.     {0xFF,0x99,0x66,0}, {0xFF,0x99,0x99,0}, {0xFF,0x99,0xCC,0}, {0xFF,0x99,0xFF,0},
  160.     {0xFF,0xCC,0x00,0}, {0xFF,0xCC,0x33,0}, {0xFF,0xCC,0x66,0}, {0xFF,0xCC,0x99,0},
  161.     {0xFF,0xCC,0xCC,0}, {0xFF,0xCC,0xFF,0}, {0xFF,0xFF,0x00,0}, {0xFF,0xFF,0x33,0},
  162.     {0xFF,0xFF,0x66,0}, {0xFF,0xFF,0x99,0}, {0xFF,0xFF,0xCC,0}, {0xFF,0xFF,0xFF,0},
  163.     {0x2C,0x40,0x40,0}, {0x2C,0x40,0x3C,0}, {0x2C,0x40,0x34,0}, {0x2C,0x40,0x30,0},
  164.     {0x2C,0x40,0x2C,0}, {0x30,0x40,0x2C,0}, {0x34,0x40,0x2C,0}, {0x3C,0x40,0x2C,0},
  165.     {0x40,0x40,0x2C,0}, {0x40,0x3C,0x2C,0}, {0x40,0x34,0x2C,0}, {0x40,0x30,0x2C,0},
  166.     {0x54,0x54,0x54,0}, {0xFC,0x54,0x54,0}, {0x54,0xFC,0x54,0}, {0xFC,0xFC,0x54,0},
  167.     {0x54,0x54,0xFC,0}, {0xFC,0x54,0xFC,0}, {0x54,0xFC,0xFC,0}, {0xFC,0xFC,0xFC,0},
  168.     };
  169.  
  170. /* Division lookup tables.  These tables compute 0-255 divided by 51 and
  171.  * modulo 51.  These tables could approximate gamma correction.
  172.  */
  173.  
  174. uchar _VARAPI _MGL_div51[256] = {
  175.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  176.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  177.     0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  178.     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  179.     1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  180.     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  181.     2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  182.     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  183.     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  184.     4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  185.     4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
  186.     };
  187.  
  188. uchar _VARAPI _MGL_mod51[256] = {
  189.     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  190.     20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  191.     38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6,
  192.     7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
  193.     26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  194.     44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  195.     13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
  196.     31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  197.     49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  198.     18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  199.     36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3,
  200.     4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  201.     23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  202.     41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0,
  203.     };
  204.  
  205. /* Multiplication lookup tables. These compute 0-5 times 6 and 36. */
  206.  
  207. uchar _VARAPI _MGL_mul6[6] = {
  208.     0, 6, 12, 18, 24, 30
  209.     };
  210.  
  211. uchar _VARAPI _MGL_mul36[6] = {
  212.     0, 36, 72, 108, 144, 180
  213.     };
  214.  
  215. /* Ordered 8x8 dither matrix for 8 bit to 2.6 bit halftones. */
  216.  
  217. uchar _VARAPI _MGL_dither8x8[64] = {
  218.      0, 38,  9, 47,  2, 40, 11, 50,
  219.     25, 12, 35, 22, 27, 15, 37, 24,
  220.      6, 44,  3, 41,  8, 47,  5, 43,
  221.     31, 19, 28, 15, 34, 21, 31, 18,
  222.      1, 39, 11, 49,  0, 39, 10, 48,
  223.     27, 14, 36, 23, 26, 13, 35, 23,
  224.      7, 46,  4, 43,  7, 45,  3, 42,
  225.     33, 20, 30, 17, 32, 19, 29, 16,
  226.     };
  227.  
  228. /* Division lookup tables for 16bpp dithering */
  229.  
  230. uchar _VARAPI _MGL_div8[256] = {
  231.     0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,
  232.     2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,
  233.     4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
  234.     6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,
  235.     8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,
  236.     10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  237.     12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,
  238.     14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,
  239.     16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,
  240.     18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,
  241.     20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,
  242.     22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,
  243.     24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,
  244.     26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,
  245.     28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,
  246.     30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,
  247.     };
  248.  
  249. uchar _VARAPI _MGL_mod8[256] = {
  250.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  251.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  252.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  253.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  254.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  255.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  256.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  257.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  258.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  259.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  260.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  261.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  262.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  263.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  264.     0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,
  265.     0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0,
  266.     };
  267.  
  268. uchar _VARAPI _MGL_div4[256] = {
  269.     0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,
  270.     4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,
  271.     8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,
  272.     12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,
  273.     16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,
  274.     20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,
  275.     24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,
  276.     28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,
  277.     32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,
  278.     36,36,36,36,37,37,37,37,38,38,38,38,39,39,39,39,
  279.     40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,
  280.     44,44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,
  281.     48,48,48,48,49,49,49,49,50,50,50,50,51,51,51,51,
  282.     52,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,
  283.     56,56,56,56,57,57,57,57,58,58,58,58,59,59,59,59,
  284.     60,60,60,60,61,61,61,61,62,62,62,62,63,63,63,63,
  285.     };
  286.  
  287. uchar _VARAPI _MGL_mod4[256] = {
  288.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  289.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  290.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  291.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  292.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  293.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  294.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  295.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  296.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  297.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  298.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  299.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  300.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  301.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  302.     0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,
  303.     0,1,2,3,0,1,2,3,0,1,2,3,0,0,0,0,
  304.     };
  305.  
  306. /* Ordered 4x4 dither matrix for 8 bit to 5 bit halftones. */
  307.  
  308. uchar _VARAPI _MGL_dither4x4[16] = {
  309.     0, 4, 1, 5,
  310.     6, 2, 7, 3,
  311.     1, 5, 0, 4,
  312.     7, 3, 6, 2,
  313.     };
  314.  
  315.