Logo Search packages:      
Sourcecode: djvulibre version File versions

void GPixmap::ordered_32k_dither ( int  xmin = 0,
int  ymin = 0 
)

Dithers the image to 32768 colors. This function applies an ordered dithering algorithm to reduce the image to 32768 predefined colors. These predefined colors are located on a color cube of 32x32x32 colors: the color RGB coordinates can only take values in which the three least significant bits are set to #1#. This is useful for displaying images with less than 24 bits per pixel. Arguments xmin# and ymin# control the position of the dithering grids. This is useful for dithering tiled images. Arguments xmin# and ymin# must be the position of the bottom left corner of the tile contained in this GPixmap. Properly setting these arguments eliminates dithering artifacts on the tile boundaries.

Definition at line 757 of file GPixmap.cpp.

References GPixel::b, GPixel::g, and GPixel::r.

{
  static unsigned char quantize[256+8+8];
  static unsigned char *quant = quantize + 8;
  static char  dither_ok = 0;
  static short dither[16][16] = 
  {
    {   0,192, 48,240, 12,204, 60,252,  3,195, 51,243, 15,207, 63,255 },
    { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
    {  32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
    { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
    {   8,200, 56,248,  4,196, 52,244, 11,203, 59,251,  7,199, 55,247 },
    { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
    {  40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
    { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
    {   2,194, 50,242, 14,206, 62,254,  1,193, 49,241, 13,205, 61,253 },
    { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
    {  34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
    { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
    {  10,202, 58,250,  6,198, 54,246,  9,201, 57,249,  5,197, 53,245 },
    { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
    {  42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
    { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  };
  // Prepare tables
  if (!dither_ok)
  {
    int i, j;
    for (i=0; i<16; i++)
      for (j=0; j<16; j++)
        dither[i][j] = ((255 - 2*dither[i][j]) * 8) / 512;    
    j = -8;
    for (i=3; i<256; i+=8)
      while (j <= i)
        quant[j++] = i;
    while (j<256+8)
      quant[j++] = 0xff;
    dither_ok = 1;
  }
  // Go dithering
  for (int y=0; y<nrows; y++)
  {
    GPixel *pix = (*this)[y];
    for (int x=0; x<ncolumns; x++, pix++)
    {
      pix->r = quant[ pix->r + dither[(x+xmin+0)&0xf][(y+ymin+0)&0xf] ];
      pix->g = quant[ pix->g + dither[(x+xmin+5)&0xf][(y+ymin+11)&0xf] ];
      pix->b = quant[ pix->b + dither[(x+xmin+11)&0xf][(y+ymin+5)&0xf] ];
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index