Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuInfo::decode ( ByteStream bs  ) 

Decodes the DjVu #"INFO"# chunk. This function reads binary data from ByteStream bs# and populates the fields of this DjVuInfo object. It is normally called after detecting an #"INFO"# chunk header with function {IFFByteStream::get_chunk}.

Definition at line 97 of file DjVuInfo.cpp.

References compressable, dpi, ByteStream::EndOfFile, gamma, height, orientation, ByteStream::readall(), version, and width.

{
  // Set to default values
  width = 0;
  height = 0;
  version = DJVUVERSION;
  dpi = 300;
  gamma = 2.2;
  compressable=false;
  orientation=GRect::BULRNR;
  // Read data
  unsigned char buffer[10];
  int  size = bs.readall((void*)buffer, sizeof(buffer));
  if (size == 0)
    G_THROW( ByteStream::EndOfFile );
  if (size < 5)
    G_THROW( ERR_MSG("DjVuInfo.corrupt_file") );
  // Analyze data with backward compatibility in mind!
  if (size>=2)
    width = (buffer[0]<<8) + buffer[1];
  if (size>=4)
    height = (buffer[2]<<8) + buffer[3];
  if (size>=5)
    version = buffer[4];
  if (size>=6 && buffer[5]!=0xff)
    version = (buffer[5]<<8) + buffer[4];
  if (size>=8 && buffer[7]!=0xff)
    dpi = (buffer[7]<<8) + buffer[6];
  if (size>=9)
    gamma = 0.1 * buffer[8];
  int flags=0;
  if (size>=10)
    flags = buffer[9];
  // Fixup
  if (gamma<0.3)
     gamma=0.3;
  if (gamma>5.0)
     gamma=5.0;
  if (dpi < 25 || dpi > 6000)
    dpi = 300;
  if(flags&COMPRESSABLE_FLAG)
    compressable=true;
  if(version>=DJVUVERSION_ORIENTATION)
  {
    orientation=(GRect::Orientations)(flags&((int)GRect::BOTTOM_UP|(int)GRect::MIRROR|(int)GRect::ROTATE90_CW));
  }
}


Generated by  Doxygen 1.6.0   Back to index