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

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

Saves the image into ByteStream bs# using the PBM format. Argument raw# selects the ``Raw PBM'' (1) or the ``Ascii PBM'' (0) format. The image is saved as a bilevel image. All non zero pixels are considered black pixels. See section {PNM and RLE file formats}.

Definition at line 915 of file GBitmap.cpp.

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

{
  // check arguments
  if (grays > 2)
    G_THROW( ERR_MSG("GBitmap.cant_make_PBM") );
  GMonitorLock lock(monitor());
  // header
  {
    GUTF8String head;
    head.format("P%c\n%d %d\n", (raw ? '4' : '1'), ncolumns, nrows);
    bs.writall((void*)(const char *)head, head.length());
  }
  // body
  if(raw)
  {
    if(!rle)
      compress();
    const unsigned char *runs=rle;
    const unsigned char * const runs_end=rle+rlelength;
    const int count=(ncolumns+7)>>3;
    unsigned char *buf;
    GPBuffer<unsigned char> gbuf(buf,count);
    while(runs<runs_end)
    {
      rle_get_bitmap(ncolumns,runs,buf,false);
      bs.writall(buf,count);
    }
  }else
  {
    if (!bytes)
      uncompress();
    const unsigned char *row = bytes + border;
    int n = nrows - 1;
    row += n * bytes_per_row;
    while (n >= 0)
    {
      unsigned char eol='\n';
      for (int c=0; c<ncolumns;)
      {
        unsigned char bit= (row[c] ? '1' : '0');
        bs.write((void*)&bit, 1);
        c += 1;
        if (c==ncolumns || (c&(int)RUNMSBMASK)==0) 
          bs.write((void*)&eol, 1);          
       }
      // next row
      row -= bytes_per_row;
      n -= 1;
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index