JBIG2Stream.cc (xpdf-4.03) | : | JBIG2Stream.cc (xpdf-4.04) | ||
---|---|---|---|---|
skipping to change at line 1150 | skipping to change at line 1150 | |||
gfree(table); | gfree(table); | |||
} | } | |||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | |||
// JBIG2Stream | // JBIG2Stream | |||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | |||
JBIG2Stream::JBIG2Stream(Stream *strA, Object *globalsStreamA): | JBIG2Stream::JBIG2Stream(Stream *strA, Object *globalsStreamA): | |||
FilterStream(strA) | FilterStream(strA) | |||
{ | { | |||
decoded = gFalse; | ||||
pageBitmap = NULL; | pageBitmap = NULL; | |||
arithDecoder = new JArithmeticDecoder(); | arithDecoder = new JArithmeticDecoder(); | |||
genericRegionStats = new JArithmeticDecoderStats(1 << 1); | genericRegionStats = new JArithmeticDecoderStats(1 << 1); | |||
refinementRegionStats = new JArithmeticDecoderStats(1 << 1); | refinementRegionStats = new JArithmeticDecoderStats(1 << 1); | |||
iadhStats = new JArithmeticDecoderStats(1 << 9); | iadhStats = new JArithmeticDecoderStats(1 << 9); | |||
iadwStats = new JArithmeticDecoderStats(1 << 9); | iadwStats = new JArithmeticDecoderStats(1 << 9); | |||
iaexStats = new JArithmeticDecoderStats(1 << 9); | iaexStats = new JArithmeticDecoderStats(1 << 9); | |||
iaaiStats = new JArithmeticDecoderStats(1 << 9); | iaaiStats = new JArithmeticDecoderStats(1 << 9); | |||
iadtStats = new JArithmeticDecoderStats(1 << 9); | iadtStats = new JArithmeticDecoderStats(1 << 9); | |||
skipping to change at line 1208 | skipping to change at line 1209 | |||
delete huffDecoder; | delete huffDecoder; | |||
delete mmrDecoder; | delete mmrDecoder; | |||
delete str; | delete str; | |||
} | } | |||
Stream *JBIG2Stream::copy() { | Stream *JBIG2Stream::copy() { | |||
return new JBIG2Stream(str->copy(), &globalsStream); | return new JBIG2Stream(str->copy(), &globalsStream); | |||
} | } | |||
void JBIG2Stream::reset() { | void JBIG2Stream::reset() { | |||
GList *t; | ||||
segments = new GList(); | segments = new GList(); | |||
globalSegments = new GList(); | globalSegments = new GList(); | |||
decoded = gFalse; | ||||
// read the globals stream | ||||
if (globalsStream.isStream()) { | ||||
curStr = globalsStream.getStream(); | ||||
curStr->reset(); | ||||
arithDecoder->setStream(curStr); | ||||
huffDecoder->setStream(curStr); | ||||
mmrDecoder->setStream(curStr); | ||||
readSegments(); | ||||
curStr->close(); | ||||
// swap the newly read segments list into globalSegments | ||||
t = segments; | ||||
segments = globalSegments; | ||||
globalSegments = t; | ||||
} | ||||
// read the main stream | ||||
curStr = str; | ||||
curStr->reset(); | ||||
arithDecoder->setStream(curStr); | ||||
huffDecoder->setStream(curStr); | ||||
mmrDecoder->setStream(curStr); | ||||
readSegments(); | ||||
if (pageBitmap) { | ||||
dataPtr = pageBitmap->getDataPtr(); | ||||
dataEnd = dataPtr + pageBitmap->getDataSize(); | ||||
} else { | ||||
dataPtr = dataEnd = NULL; | ||||
} | ||||
} | } | |||
void JBIG2Stream::close() { | void JBIG2Stream::close() { | |||
if (pageBitmap) { | if (pageBitmap) { | |||
delete pageBitmap; | delete pageBitmap; | |||
pageBitmap = NULL; | pageBitmap = NULL; | |||
} | } | |||
if (segments) { | if (segments) { | |||
deleteGList(segments, JBIG2Segment); | deleteGList(segments, JBIG2Segment); | |||
segments = NULL; | segments = NULL; | |||
} | } | |||
if (globalSegments) { | if (globalSegments) { | |||
deleteGList(globalSegments, JBIG2Segment); | deleteGList(globalSegments, JBIG2Segment); | |||
globalSegments = NULL; | globalSegments = NULL; | |||
} | } | |||
dataPtr = dataEnd = NULL; | dataPtr = dataEnd = NULL; | |||
FilterStream::close(); | FilterStream::close(); | |||
} | } | |||
int JBIG2Stream::getChar() { | int JBIG2Stream::getChar() { | |||
if (!decoded) { | ||||
decodeImage(); | ||||
} | ||||
if (dataPtr && dataPtr < dataEnd) { | if (dataPtr && dataPtr < dataEnd) { | |||
return (*dataPtr++ ^ 0xff) & 0xff; | return (*dataPtr++ ^ 0xff) & 0xff; | |||
} | } | |||
return EOF; | return EOF; | |||
} | } | |||
int JBIG2Stream::lookChar() { | int JBIG2Stream::lookChar() { | |||
if (!decoded) { | ||||
decodeImage(); | ||||
} | ||||
if (dataPtr && dataPtr < dataEnd) { | if (dataPtr && dataPtr < dataEnd) { | |||
return (*dataPtr ^ 0xff) & 0xff; | return (*dataPtr ^ 0xff) & 0xff; | |||
} | } | |||
return EOF; | return EOF; | |||
} | } | |||
int JBIG2Stream::getBlock(char *blk, int size) { | int JBIG2Stream::getBlock(char *blk, int size) { | |||
int n, i; | int n, i; | |||
if (!decoded) { | ||||
decodeImage(); | ||||
} | ||||
if (size <= 0) { | if (size <= 0) { | |||
return 0; | return 0; | |||
} | } | |||
if (dataEnd - dataPtr < size) { | if (dataEnd - dataPtr < size) { | |||
n = (int)(dataEnd - dataPtr); | n = (int)(dataEnd - dataPtr); | |||
} else { | } else { | |||
n = size; | n = size; | |||
} | } | |||
for (i = 0; i < n; ++i) { | for (i = 0; i < n; ++i) { | |||
blk[i] = *dataPtr++ ^ 0xff; | blk[i] = *dataPtr++ ^ 0xff; | |||
skipping to change at line 1301 | skipping to change at line 1280 | |||
GString *JBIG2Stream::getPSFilter(int psLevel, const char *indent, | GString *JBIG2Stream::getPSFilter(int psLevel, const char *indent, | |||
GBool okToReadStream) { | GBool okToReadStream) { | |||
return NULL; | return NULL; | |||
} | } | |||
GBool JBIG2Stream::isBinary(GBool last) { | GBool JBIG2Stream::isBinary(GBool last) { | |||
return str->isBinary(gTrue); | return str->isBinary(gTrue); | |||
} | } | |||
void JBIG2Stream::decodeImage() { | ||||
GList *t; | ||||
// read the globals stream | ||||
if (globalsStream.isStream()) { | ||||
curStr = globalsStream.getStream(); | ||||
curStr->reset(); | ||||
arithDecoder->setStream(curStr); | ||||
huffDecoder->setStream(curStr); | ||||
mmrDecoder->setStream(curStr); | ||||
readSegments(); | ||||
curStr->close(); | ||||
// swap the newly read segments list into globalSegments | ||||
t = segments; | ||||
segments = globalSegments; | ||||
globalSegments = t; | ||||
} | ||||
// read the main stream | ||||
curStr = str; | ||||
curStr->reset(); | ||||
arithDecoder->setStream(curStr); | ||||
huffDecoder->setStream(curStr); | ||||
mmrDecoder->setStream(curStr); | ||||
readSegments(); | ||||
if (pageBitmap) { | ||||
dataPtr = pageBitmap->getDataPtr(); | ||||
dataEnd = dataPtr + pageBitmap->getDataSize(); | ||||
} else { | ||||
dataPtr = dataEnd = NULL; | ||||
} | ||||
decoded = gTrue; | ||||
} | ||||
void JBIG2Stream::readSegments() { | void JBIG2Stream::readSegments() { | |||
Guint segNum, segFlags, segType, page, segLength; | Guint segNum, segFlags, segType, page, segLength; | |||
Guint refFlags, nRefSegs; | Guint refFlags, nRefSegs; | |||
Guint *refSegs; | Guint *refSegs; | |||
int c1, c2, c3; | int c1, c2, c3; | |||
Guint i; | Guint i; | |||
done = gFalse; | done = gFalse; | |||
while (!done && readULong(&segNum)) { | while (!done && readULong(&segNum)) { | |||
skipping to change at line 2045 | skipping to change at line 2060 | |||
if (!readULong(&numInstances)) { | if (!readULong(&numInstances)) { | |||
goto eofError; | goto eofError; | |||
} | } | |||
// get symbol dictionaries and tables | // get symbol dictionaries and tables | |||
codeTables = new GList(); | codeTables = new GList(); | |||
numSyms = 0; | numSyms = 0; | |||
for (i = 0; i < nRefSegs; ++i) { | for (i = 0; i < nRefSegs; ++i) { | |||
if ((seg = findSegment(refSegs[i]))) { | if ((seg = findSegment(refSegs[i]))) { | |||
if (seg->getType() == jbig2SegSymbolDict) { | if (seg->getType() == jbig2SegSymbolDict) { | |||
numSyms += ((JBIG2SymbolDict *)seg)->getSize(); | Guint segSize = ((JBIG2SymbolDict *)seg)->getSize(); | |||
if (segSize > INT_MAX || numSyms > INT_MAX - segSize) { | ||||
error(errSyntaxError, getPos(), | ||||
"Too many symbols in JBIG2 text region"); | ||||
delete codeTables; | ||||
return; | ||||
} | ||||
numSyms += segSize; | ||||
} else if (seg->getType() == jbig2SegCodeTable) { | } else if (seg->getType() == jbig2SegCodeTable) { | |||
codeTables->append(seg); | codeTables->append(seg); | |||
} | } | |||
} else { | } else { | |||
error(errSyntaxError, getPos(), | error(errSyntaxError, getPos(), | |||
"Invalid segment reference in JBIG2 text region"); | "Invalid segment reference in JBIG2 text region"); | |||
delete codeTables; | delete codeTables; | |||
return; | return; | |||
} | } | |||
} | } | |||
skipping to change at line 3936 | skipping to change at line 3958 | |||
!readUByte(&flags) || !readUWord(&striping)) { | !readUByte(&flags) || !readUWord(&striping)) { | |||
goto eofError; | goto eofError; | |||
} | } | |||
if (pageW == 0 || pageH == 0 || pageW > INT_MAX / pageW) { | if (pageW == 0 || pageH == 0 || pageW > INT_MAX / pageW) { | |||
error(errSyntaxError, getPos(), "Bad page size in JBIG2 stream"); | error(errSyntaxError, getPos(), "Bad page size in JBIG2 stream"); | |||
return; | return; | |||
} | } | |||
pageDefPixel = (flags >> 2) & 1; | pageDefPixel = (flags >> 2) & 1; | |||
defCombOp = (flags >> 3) & 3; | defCombOp = (flags >> 3) & 3; | |||
// this will only happen if there are multiple page info segments | ||||
if (pageBitmap) { | ||||
delete pageBitmap; | ||||
} | ||||
// allocate the page bitmap | // allocate the page bitmap | |||
if (pageH == 0xffffffff) { | if (pageH == 0xffffffff) { | |||
curPageH = striping & 0x7fff; | curPageH = striping & 0x7fff; | |||
} else { | } else { | |||
curPageH = pageH; | curPageH = pageH; | |||
} | } | |||
pageBitmap = new JBIG2Bitmap(0, pageW, curPageH); | pageBitmap = new JBIG2Bitmap(0, pageW, curPageH); | |||
// default pixel value | // default pixel value | |||
if (pageDefPixel) { | if (pageDefPixel) { | |||
End of changes. 9 change blocks. | ||||
33 lines changed or deleted | 60 lines changed or added |