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

void GBitmap::init ( ByteStream ref,
int  border = 0 
)

Reads PBM, PGM or RLE data from ByteStream ref# into this GBitmap. The previous content of the GBitmap object is lost. The optional argument border# specifies the size of the optional border of white pixels surrounding the image. See {PNM and RLE file formats} for more information.

Definition at line 293 of file GBitmap.cpp.

References init(), monitor(), and ByteStream::readall().

{
  GMonitorLock lock(monitor());
  // Get magic number
  char magic[2];
  magic[0] = magic[1] = 0;
  ref.readall((void*)magic, sizeof(magic));
  char lookahead = '\n';
  int acolumns = read_integer(lookahead, ref);
  int arows = read_integer(lookahead, ref);
  int maxval = 1;
  init(arows, acolumns, aborder);
  // go reading file
  if (magic[0]=='P')
    {
      switch(magic[1])
        {
        case '1':
          grays = 2;
          read_pbm_text(ref); 
          return;
        case '2':
          maxval = read_integer(lookahead, ref);
          if (maxval > 65535)
            G_THROW("Cannot read PGM with depth greater than 16 bits.");
          grays = (maxval>255 ? 256 : maxval+1);
          read_pgm_text(ref, maxval); 
          return;
        case '4':
          grays = 2;
          read_pbm_raw(ref); 
          return;
        case '5':
          maxval = read_integer(lookahead, ref);
          if (maxval > 65535)
            G_THROW("Cannot read PGM with depth greater than 16 bits.");
          grays = (maxval>255 ? 256 : maxval+1);
          read_pgm_raw(ref, maxval); 
          return;
        }
    }
  else if (magic[0]=='R')
    {
      switch(magic[1])
        {
        case '4':
          grays = 2;
          read_rle_raw(ref); 
          return;
        }
    }
  G_THROW( ERR_MSG("GBitmap.bad_format") );
}


Generated by  Doxygen 1.6.0   Back to index