Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

void GBitmap::change_grays ( int  grays  ) 

Changes the number of gray levels. The argument grays# must be in the range #2# to #256#. All the pixel values are then rescaled and clipped in range #0# to grays-1#.

Definition at line 491 of file GBitmap.cpp.

References monitor(), and set_grays().

{
  GMonitorLock lock(monitor());
  // set number of grays
  int ng = ngrays - 1;
  int og = grays - 1;
  set_grays(ngrays);
  // setup conversion table
  unsigned char conv[256];
  for (int i=0; i<256; i++)
    {
      if (i > og)
        conv[i] = ng;
      else
        conv[i] = (i*ng+og/2)/og;
    }
  // perform conversion
  for (int row=0; row<nrows; row++)
    {
      unsigned char *p = (*this)[row];
      for (int n=0; n<ncolumns; n++)
        p[n] = conv[ p[n] ];
    }
}


Generated by  Doxygen 1.6.0   Back to index