JArithmeticDecoderStats::JArithmeticDecoderStats(int contextSizeA) {
contextSize = contextSizeA;
- cxTab = (Guchar *)gmalloc(contextSize * sizeof(Guchar));
+ cxTab = (Guchar *)gmallocn(contextSize, sizeof(Guchar));
reset();
}
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();
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;