X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=pdf2swf%2Fxpdf%2FJArithmeticDecoder.cc;h=195b73e1c24280b37a751a6604c3cc78f1e53a41;hp=fd297445b278ba8fb276fb7f7b8c71682241304f;hb=85c46a8011c7fd5e4bda282266006c972ea7606b;hpb=b0d012f83219d898e9cd92281d9996bc9ff13b5f diff --git a/pdf2swf/xpdf/JArithmeticDecoder.cc b/pdf2swf/xpdf/JArithmeticDecoder.cc index fd29744..195b73e 100644 --- a/pdf2swf/xpdf/JArithmeticDecoder.cc +++ b/pdf2swf/xpdf/JArithmeticDecoder.cc @@ -22,7 +22,7 @@ JArithmeticDecoderStats::JArithmeticDecoderStats(int contextSizeA) { contextSize = contextSizeA; - cxTab = (Guchar *)gmalloc(contextSize * sizeof(Guchar)); + cxTab = (Guchar *)gmallocn(contextSize, sizeof(Guchar)); reset(); } @@ -89,24 +89,24 @@ int JArithmeticDecoder::switchTab[47] = { JArithmeticDecoder::JArithmeticDecoder() { str = NULL; -} - -JArithmeticDecoder::~JArithmeticDecoder() { - while (dataLen > 0) { - readByte(); - } + dataLen = 0; + limitStream = gFalse; } inline Guint JArithmeticDecoder::readByte() { - if (dataLen == 0) { - return 0xff; - } - if (dataLen > 0) { + if (limitStream) { --dataLen; + if (dataLen < 0) { + return 0xff; + } } return (Guint)str->getChar() & 0xff; } +JArithmeticDecoder::~JArithmeticDecoder() { + cleanup(); +} + void JArithmeticDecoder::start() { buf0 = readByte(); buf1 = readByte(); @@ -119,6 +119,28 @@ void JArithmeticDecoder::start() { a = 0x80000000; } +void JArithmeticDecoder::restart(int dataLenA) { + int oldDataLen; + + oldDataLen = dataLen; + dataLen = dataLenA; + if (oldDataLen == -1) { + buf1 = readByte(); + } else if (oldDataLen <= -2) { + buf0 = readByte(); + buf1 = readByte(); + } +} + +void JArithmeticDecoder::cleanup() { + if (limitStream) { + while (dataLen > 0) { + buf0 = buf1; + buf1 = readByte(); + } + } +} + int JArithmeticDecoder::decodeBit(Guint context, JArithmeticDecoderStats *stats) { int bit;