Logo Search packages:      
Sourcecode: djvulibre version File versions

int IWBitmap::Encode::encode_chunk ( GP< ByteStream gbs,
const IWEncoderParms parms 
) [virtual]

Encodes one data chunk into ByteStream bs#. Parameter parms# controls how much data is generated. The chunk data is written to ByteStream bs# with no IFF header. Successive calls to encode_chunk# encode successive chunks. You must call close_codec# after encoding the last chunk of a file.

Definition at line 1467 of file IW44EncodeCodec.cpp.

References IWEncoderParms::bytes, ZPCodec::create(), IWEncoderParms::decibels, and IWEncoderParms::slices.

Referenced by encode_iff().

{
  // Check
  if (parm.slices==0 && parm.bytes==0 && parm.decibels==0)
    G_THROW( ERR_MSG("IW44Image.need_stop") );
  if (! ymap)
    G_THROW( ERR_MSG("IW44Image.empty_object") );
  // Open codec
  if (!ycodec_enc)
  {
    cslice = cserial = cbytes = 0;
    ycodec_enc = new Codec::Encode(*ymap);
  }
  // Adjust cbytes
  cbytes += sizeof(struct IW44Image::PrimaryHeader);
  if (cserial == 0)
    cbytes += sizeof(struct IW44Image::SecondaryHeader) + sizeof(struct IW44Image::TertiaryHeader);
  // Prepare zcoded slices
  int flag = 1;
  int nslices = 0;
  GP<ByteStream> gmbs=ByteStream::create();
  ByteStream &mbs=*gmbs;
  DJVU_PROGRESS_TASK(chunk,"encode chunk",parm.slices-cslice);
  {
    float estdb = -1.0;
    GP<ZPCodec> gzp=ZPCodec::create(gmbs, true, true);
    ZPCodec &zp=*gzp;
    while (flag)
      {
        if (parm.decibels>0  && estdb>=parm.decibels)
          break;
        if (parm.bytes>0  && mbs.tell()+cbytes>=parm.bytes)
          break;
        if (parm.slices>0 && nslices+cslice>=parm.slices)
          break;
        DJVU_PROGRESS_RUN(chunk, (1+nslices-cslice)|0xf);
        flag = ycodec_enc->code_slice(zp);
        if (flag && parm.decibels>0.0)
          if (ycodec_enc->curband==0 || estdb>=parm.decibels-DECIBEL_PRUNE)
            estdb = ycodec_enc->estimate_decibel(db_frac);
        nslices++;
      }
  }
  // Write primary header
  struct IW44Image::PrimaryHeader primary;
  primary.serial = cserial;
  primary.slices = nslices;
  primary.encode(gbs);
  // Write auxilliary headers
  if (cserial == 0)
    {
      struct IW44Image::SecondaryHeader secondary;
      secondary.major = IWCODEC_MAJOR + 0x80;
      secondary.minor = IWCODEC_MINOR;
      secondary.encode(gbs);
      struct IW44Image::TertiaryHeader tertiary;
      tertiary.xhi = (ymap->iw >> 8) & 0xff;
      tertiary.xlo = (ymap->iw >> 0) & 0xff;
      tertiary.yhi = (ymap->ih >> 8) & 0xff;
      tertiary.ylo = (ymap->ih >> 0) & 0xff;
      tertiary.crcbdelay = 0;
      tertiary.encode(gbs);
    }
  // Write slices
  mbs.seek(0);
  gbs->copy(mbs);
  // Return
  cbytes  += mbs.tell();
  cslice  += nslices;
  cserial += 1;
  return flag;
}


Generated by  Doxygen 1.6.0   Back to index