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

void GBitmap::save_pgm ( ByteStream bs,
int  raw = 1 
)

Saves the image into ByteStream bs# using the PGM format. Argument raw# selects the ``Raw PGM'' (1) or the ``Ascii PGM'' (0) format. The image is saved as a gray level image. See section {PNM and RLE file formats}.

Definition at line 968 of file GBitmap.cpp.

References GUTF8String::format(), GBaseString::length(), monitor(), uncompress(), ByteStream::writall(), and ByteStream::write().

{
  // checks
  GMonitorLock lock(monitor());
  if (!bytes)
    uncompress();
  // header
  GUTF8String head;
  head.format("P%c\n%d %d\n%d\n", (raw ? '5' : '2'), ncolumns, nrows, grays-1);
  bs.writall((void*)(const char *)head, head.length());
  // body
  const unsigned char *row = bytes + border;
  int n = nrows - 1;
  row += n * bytes_per_row;
  while (n >= 0)
    {
      if (raw)
        {
          for (int c=0; c<ncolumns; c++)
            {
              char x = grays - 1 - row[c];
              bs.write((void*)&x, 1);
            }
        }
      else 
        {
          unsigned char eol='\n';
          for (int c=0; c<ncolumns; )
            {
              head.format("%d ", grays - 1 - row[c]);
              bs.writall((void*)(const char *)head, head.length());
              c += 1;
              if (c==ncolumns || (c&0x1f)==0) 
                bs.write((void*)&eol, 1);          
            }
        }
      row -= bytes_per_row;
      n -= 1;
    }
}


Generated by  Doxygen 1.6.0   Back to index