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

  1. /****************************************************************************
  2. *
  3. *                       MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1996 SciTech Software.
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $Workfile:   halftone.h  $
  9. * Version:      $Revision:   1.4  $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MS DOS)
  13. *
  14. * Description:  Header file for the windows compatible HalfToning tables
  15. *               for creating a HalfTone palette and for performing the
  16. *               HalfTone dithering algorithm in 8/15/16 bpp modes.
  17. *
  18. *               The halftone palette is set up to use entries from 20 to
  19. *               226 in the physical palette, leaving the top 20 and bottom
  20. *               20 for operating system specific use.
  21. *
  22. * $Date:   07 Apr 1997 17:22:00  $ $Author:   KendallB  $
  23. *
  24. ****************************************************************************/
  25.  
  26. #ifndef __HALFTONE_H
  27. #define __HALFTONE_H
  28.  
  29. /*---------------------- Macro and type definitions -----------------------*/
  30.  
  31. #ifndef __MGRAPH_H
  32. typedef struct {
  33.     unsigned char   blue;       /* Blue component of color              */
  34.     unsigned char   green;      /* Green component of color             */
  35.     unsigned char   red;        /* Blue component of color              */
  36.     unsigned char   alpha;      /* Alpha or alignment byte              */
  37.     } palette_t;
  38. #endif
  39.  
  40. /* Macros to halfTone dither an 8bpp RGB pixel */
  41.  
  42. #define PACK_COLOR_DITHER8(p,x,y,R,G,B)                         \
  43. {                                                               \
  44.     uchar dither = _MGL_dither8x8[(((y) & 7) << 3) + ((x) & 7)];\
  45.     (p) = 20 +                                                  \
  46.         _MGL_div51[R] + (_MGL_mod51[R] > dither) +              \
  47.         _MGL_mul6[_MGL_div51[G] + (_MGL_mod51[G] > dither)] +   \
  48.         _MGL_mul36[_MGL_div51[B] + (_MGL_mod51[B] > dither)];   \
  49. }
  50.  
  51. #define HALFTONE_VARS_8                                         \
  52.     int    __Rdiv51,__Rmod51;                                   \
  53.     int    __Gdiv51,__Gmod51;                                   \
  54.     int    __Bdiv51,__Bmod51;                                   \
  55.     uchar  *__dp
  56.  
  57. #define SETUP_DITHER8(y,R,G,B)                                  \
  58. {                                                               \
  59.     __dp = &_MGL_dither8x8[((y) & 7) << 3];                     \
  60.     __Rdiv51 = _MGL_div51[R];                                   \
  61.     __Rmod51 = _MGL_mod51[R];                                   \
  62.     __Gdiv51 = _MGL_div51[G];                                   \
  63.     __Gmod51 = _MGL_mod51[G];                                   \
  64.     __Bdiv51 = _MGL_div51[B];                                   \
  65.     __Bmod51 = _MGL_mod51[B];                                   \
  66. }
  67.  
  68. #define PACK_COLOR2_DITHER8(p,x)                                \
  69. {                                                               \
  70.     uchar __dither = __dp[(x) & 7];                             \
  71.     (p) = 20 +                                                  \
  72.         __Rdiv51 + (__Rmod51 > __dither) +                      \
  73.         _MGL_mul6[__Gdiv51 + (__Gmod51 > __dither)] +           \
  74.         _MGL_mul36[__Bdiv51 + (__Bmod51 > __dither)];           \
  75. }
  76.  
  77. /* Macros to halfTone dither a 16bit 5/5/5 RGB pixel */
  78.  
  79. #define PACK_COLOR_DITHER555(p,x,y,R,G,B)                               \
  80. {                                                                       \
  81.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];       \
  82.     (p) = (ushort)                                                      \
  83.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 10) +      \
  84.         (((ulong)_MGL_div8[G] + (_MGL_mod8[G] > _dither)) << 5) +       \
  85.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));       \
  86. }
  87.  
  88. #define HALFTONE_VARS_16                                        \
  89.     int    __Rdiv8,__Rmod8;                                     \
  90.     int    __Gdiv8,__Gmod8;                                     \
  91.     int    __Bdiv8,__Bmod8;                                     \
  92.     uchar  *__dp
  93.  
  94. #define SETUP_DITHER555(y,R,G,B)                                \
  95. {                                                               \
  96.     __dp = &_MGL_dither4x4[((y) & 3) << 2];                     \
  97.     __Rdiv8 = _MGL_div8[R];                                     \
  98.     __Rmod8 = _MGL_mod8[R];                                     \
  99.     __Gdiv8 = _MGL_div8[G];                                     \
  100.     __Gmod8 = _MGL_mod8[G];                                     \
  101.     __Bdiv8 = _MGL_div8[B];                                     \
  102.     __Bmod8 = _MGL_mod8[B];                                     \
  103. }
  104.  
  105. #define PACK_COLOR2_DITHER555(p,x)                              \
  106. {                                                               \
  107.     uchar _dither = __dp[(x) & 3];                              \
  108.     (p) = (ushort)                                              \
  109.        (((__Rdiv8 + (__Rmod8 > _dither)) << 10) +               \
  110.         ((__Gdiv8 + (__Gmod8 > _dither)) << 5) +                \
  111.         ((__Bdiv8 + (__Bmod8 > _dither)) << 0));                \
  112. }
  113.  
  114. /* Macros to halfTone dither a 16bit 5/6/5 RGB pixel */
  115.  
  116. #define PACK_COLOR_DITHER565(p,x,y,R,G,B)                               \
  117. {                                                                       \
  118.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];       \
  119.     (p) = (ushort)                                                      \
  120.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 11) +      \
  121.         (((ulong)_MGL_div4[G] + (_MGL_mod4[G] > (_dither>>1))) << 5) +  \
  122.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));       \
  123. }
  124.  
  125. #define SETUP_DITHER565(y,R,G,B)                                \
  126. {                                                               \
  127.     __dp = &_MGL_dither4x4[((y) & 3) << 2];                     \
  128.     __Rdiv8 = _MGL_div8[R];                                     \
  129.     __Rmod8 = _MGL_mod8[R];                                     \
  130.     __Gdiv8 = _MGL_div4[G];                                     \
  131.     __Gmod8 = _MGL_mod4[G];                                     \
  132.     __Bdiv8 = _MGL_div8[B];                                     \
  133.     __Bmod8 = _MGL_mod8[B];                                     \
  134. }
  135.  
  136. #define PACK_COLOR2_DITHER565(p,x)                              \
  137. {                                                               \
  138.     uchar __dither = __dp[(x) & 3];                             \
  139.     (p) = (ushort)                                              \
  140.        (((__Rdiv8 + (__Rmod8 > __dither)) << 11) +              \
  141.         ((__Gdiv8 + (__Gmod8 > (__dither>>1))) << 5) +          \
  142.         ((__Bdiv8 + (__Bmod8 > __dither)) << 0));               \
  143. }
  144.  
  145. /*--------------------------- Global Variables ----------------------------*/
  146.  
  147. extern palette_t    _VARAPI _MGL_halftonePal[];
  148.  
  149. /* Division lookup tables.  These tables compute 0-255 divided by 51 and
  150.  * modulo 51.  These tables could approximate gamma correction.
  151.  */
  152.  
  153. extern unsigned char _VARAPI _MGL_div51[256];
  154. extern unsigned char _VARAPI _MGL_mod51[256];
  155. extern unsigned char _VARAPI _MGL_div8[256];
  156. extern unsigned char _VARAPI _MGL_mod8[256];
  157. extern unsigned char _VARAPI _MGL_div4[256];
  158. extern unsigned char _VARAPI _MGL_mod4[256];
  159.  
  160. /* Multiplication lookup tables. These compute 0-5 times 6 and 36. */
  161.  
  162. extern unsigned char _VARAPI _MGL_mul6[6];
  163. extern unsigned char _VARAPI _MGL_mul36[6];
  164.  
  165. /* Dither matrices */
  166.  
  167. extern unsigned char _VARAPI _MGL_dither8x8[64];
  168. extern unsigned char _VARAPI _MGL_dither4x4[16];
  169.  
  170. /*------------------------- Function Prototypes ---------------------------*/
  171.  
  172. #ifdef  __cplusplus
  173. extern "C" {
  174. #endif
  175.  
  176. void    MGLAPI MGL_getHalfTonePalette(palette_t *pal);
  177. uchar   MGLAPI MGL_halfTonePixel(int x,int y,uchar R,uchar G,uchar B);
  178. ushort  MGLAPI MGL_halfTonePixel555(int x,int y,uchar R,uchar G,uchar B);
  179. ushort  MGLAPI MGL_halfTonePixel565(int x,int y,uchar R,uchar G,uchar B);
  180.  
  181. #ifdef  __cplusplus
  182. }
  183. #endif
  184.  
  185. #endif  /* __HALFTONE_H */
  186.  
  187.