"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xpdf/JPXStream.cc" between
xpdf-4.01.01.tar.gz and xpdf-4.02.tar.gz

About: Xpdf is a PDF viewer for X.

JPXStream.cc  (xpdf-4.01.01):JPXStream.cc  (xpdf-4.02)
skipping to change at line 417 skipping to change at line 417
void JPXStream::fillReadBuf() { void JPXStream::fillReadBuf() {
JPXTileComp *tileComp; JPXTileComp *tileComp;
Guint tileIdx, tx, ty; Guint tileIdx, tx, ty;
int pix, pixBits, k; int pix, pixBits, k;
GBool eol; GBool eol;
do { do {
if (curY >= (img.ySize >> reduction)) { if (curY >= (img.ySize >> reduction)) {
return; return;
} }
tileIdx = ((curY - img.yTileOffsetR) / img.yTileSizeR) * img.nXTiles tileIdx = (((curY << reduction) - img.yTileOffset) / img.yTileSize)
+ (curX - img.xTileOffsetR) / img.xTileSizeR; * img.nXTiles
+ ((curX << reduction) - img.xTileOffset) / img.xTileSize;
#if 1 //~ ignore the palette, assume the PDF ColorSpace object is valid #if 1 //~ ignore the palette, assume the PDF ColorSpace object is valid
tileComp = &img.tiles[tileIdx].tileComps[curComp]; tileComp = &img.tiles[tileIdx].tileComps[curComp];
#else #else
tileComp = &img.tiles[tileIdx].tileComps[havePalette ? 0 : curComp]; tileComp = &img.tiles[tileIdx].tileComps[havePalette ? 0 : curComp];
#endif #endif
//~ can curX/curY be less than x/yTileOffsetR? tx = jpxFloorDiv(curX - jpxCeilDivPow2(img.tiles[tileIdx].x0, reduction),
//~ if yes, we need to use tx = max(0, ....)
tx = jpxFloorDiv((curX - img.xTileOffsetR) % img.xTileSizeR,
tileComp->hSep); tileComp->hSep);
ty = jpxFloorDiv((curY - img.yTileOffsetR) % img.yTileSizeR, ty = jpxFloorDiv(curY - jpxCeilDivPow2(img.tiles[tileIdx].y0, reduction),
tileComp->vSep); tileComp->vSep);
pix = (int)tileComp->data[ty * tileComp->w + tx]; pix = (int)tileComp->data[ty * tileComp->w + tx];
pixBits = tileComp->prec; pixBits = tileComp->prec;
eol = gFalse; eol = gFalse;
#if 1 //~ ignore the palette, assume the PDF ColorSpace object is valid #if 1 //~ ignore the palette, assume the PDF ColorSpace object is valid
if (++curComp == img.nComps) { if (++curComp == img.nComps) {
#else #else
if (havePalette) { if (havePalette) {
if (pix >= 0 && pix < palette.nEntries) { if (pix >= 0 && pix < palette.nEntries) {
pix = palette.c[pix * palette.nComps + curComp]; pix = palette.c[pix * palette.nComps + curComp];
skipping to change at line 466 skipping to change at line 465
readBuf = (readBuf << pixBits) | (pix & ((1 << pixBits) - 1)); readBuf = (readBuf << pixBits) | (pix & ((1 << pixBits) - 1));
} }
readBufLen += pixBits; readBufLen += pixBits;
if (eol && (k = readBufLen & 7)) { if (eol && (k = readBufLen & 7)) {
readBuf <<= 8 - k; readBuf <<= 8 - k;
readBufLen += 8 - k; readBufLen += 8 - k;
} }
} while (readBufLen < 8); } while (readBufLen < 8);
} }
GString *JPXStream::getPSFilter(int psLevel, const char *indent) { GString *JPXStream::getPSFilter(int psLevel, const char *indent,
GBool okToReadStream) {
return NULL; return NULL;
} }
GBool JPXStream::isBinary(GBool last) { GBool JPXStream::isBinary(GBool last) {
return str->isBinary(gTrue); return str->isBinary(gTrue);
} }
void JPXStream::getImageParams(int *bitsPerComponent, void JPXStream::getImageParams(int *bitsPerComponent,
StreamColorSpaceMode *csMode) { StreamColorSpaceMode *csMode) {
Guint boxType, boxLen, dataLen, csEnum; Guint boxType, boxLen, dataLen, csEnum;
skipping to change at line 963 skipping to change at line 963
img.xTileSize + img.xTileOffset <= img.xOffset || img.xTileSize + img.xTileOffset <= img.xOffset ||
img.yTileSize + img.yTileOffset <= img.yOffset || img.yTileSize + img.yTileOffset <= img.yOffset ||
img.nComps == 0) { img.nComps == 0) {
error(errSyntaxError, getPos(), "Error in JPX SIZ marker segment"); error(errSyntaxError, getPos(), "Error in JPX SIZ marker segment");
return jpxDecodeFatalError; return jpxDecodeFatalError;
} }
img.xSizeR = jpxCeilDivPow2(img.xSize, reduction); img.xSizeR = jpxCeilDivPow2(img.xSize, reduction);
img.ySizeR = jpxCeilDivPow2(img.ySize, reduction); img.ySizeR = jpxCeilDivPow2(img.ySize, reduction);
img.xOffsetR = jpxCeilDivPow2(img.xOffset, reduction); img.xOffsetR = jpxCeilDivPow2(img.xOffset, reduction);
img.yOffsetR = jpxCeilDivPow2(img.yOffset, reduction); img.yOffsetR = jpxCeilDivPow2(img.yOffset, reduction);
img.xTileSizeR = jpxCeilDivPow2(img.xTileSize, reduction);
img.yTileSizeR = jpxCeilDivPow2(img.yTileSize, reduction);
img.xTileOffsetR = jpxCeilDivPow2(img.xTileOffset, reduction);
img.yTileOffsetR = jpxCeilDivPow2(img.yTileOffset, reduction);
img.nXTiles = (img.xSize - img.xTileOffset + img.xTileSize - 1) img.nXTiles = (img.xSize - img.xTileOffset + img.xTileSize - 1)
/ img.xTileSize; / img.xTileSize;
img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1) img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
/ img.yTileSize; / img.yTileSize;
// check for overflow before allocating memory // check for overflow before allocating memory
if (img.nXTiles <= 0 || img.nYTiles <= 0 || if (img.nXTiles <= 0 || img.nYTiles <= 0 ||
img.nXTiles >= INT_MAX / img.nYTiles) { img.nXTiles >= INT_MAX / img.nYTiles) {
error(errSyntaxError, getPos(), error(errSyntaxError, getPos(),
"Bad tile count in JPX SIZ marker segment"); "Bad tile count in JPX SIZ marker segment");
return jpxDecodeFatalError; return jpxDecodeFatalError;
skipping to change at line 1452 skipping to change at line 1448
if (!haveQCD) { if (!haveQCD) {
error(errSyntaxError, getPos(), error(errSyntaxError, getPos(),
"Missing QCD marker segment in JPX stream"); "Missing QCD marker segment in JPX stream");
return jpxDecodeFatalError; return jpxDecodeFatalError;
} }
//----- read the tile-parts //----- read the tile-parts
ok = gTrue; ok = gTrue;
while (1) { while (1) {
if (!readTilePart()) { if (!readTilePart()) {
ok = gFalse; return jpxDecodeFatalError;
break;
} }
if (!readMarkerHdr(&segType, &segLen)) { if (!readMarkerHdr(&segType, &segLen)) {
error(errSyntaxError, getPos(), "Error in JPX codestream"); error(errSyntaxError, getPos(), "Error in JPX codestream");
ok = gFalse; ok = gFalse;
break; break;
} }
if (segType != 0x90) { // SOT - start of tile if (segType != 0x90) { // SOT - start of tile
break; break;
} }
} }
skipping to change at line 1916 skipping to change at line 1911
if ((tile->x1 = img.xTileOffset + (j + 1) * img.xTileSize) > img.xSize) { if ((tile->x1 = img.xTileOffset + (j + 1) * img.xTileSize) > img.xSize) {
tile->x1 = img.xSize; tile->x1 = img.xSize;
} }
if ((tile->y1 = img.yTileOffset + (i + 1) * img.yTileSize) > img.ySize) { if ((tile->y1 = img.yTileOffset + (i + 1) * img.yTileSize) > img.ySize) {
tile->y1 = img.ySize; tile->y1 = img.ySize;
} }
tile->comp = 0; tile->comp = 0;
tile->res = 0; tile->res = 0;
tile->precinct = 0; tile->precinct = 0;
tile->layer = 0; tile->layer = 0;
tile->done = gFalse;
tile->maxNDecompLevels = 0; tile->maxNDecompLevels = 0;
for (comp = 0; comp < img.nComps; ++comp) { for (comp = 0; comp < img.nComps; ++comp) {
tileComp = &tile->tileComps[comp]; tileComp = &tile->tileComps[comp];
if (tileComp->nDecompLevels > tile->maxNDecompLevels) { if (tileComp->nDecompLevels > tile->maxNDecompLevels) {
tile->maxNDecompLevels = tileComp->nDecompLevels; tile->maxNDecompLevels = tileComp->nDecompLevels;
} }
tileComp->x0 = jpxCeilDiv(tile->x0, tileComp->hSep); tileComp->x0 = jpxCeilDiv(tile->x0, tileComp->hSep);
tileComp->y0 = jpxCeilDiv(tile->y0, tileComp->vSep); tileComp->y0 = jpxCeilDiv(tile->y0, tileComp->vSep);
tileComp->x1 = jpxCeilDiv(tile->x1, tileComp->hSep); tileComp->x1 = jpxCeilDiv(tile->x1, tileComp->hSep);
tileComp->y1 = jpxCeilDiv(tile->y1, tileComp->vSep); tileComp->y1 = jpxCeilDiv(tile->y1, tileComp->vSep);
tileComp->cbW = 1 << tileComp->codeBlockW; tileComp->cbW = 1 << tileComp->codeBlockW;
tileComp->cbH = 1 << tileComp->codeBlockH; tileComp->cbH = 1 << tileComp->codeBlockH;
tileComp->w = jpxCeilDivPow2(tileComp->x1 - tileComp->x0, reduction); tileComp->w = jpxCeilDivPow2(tileComp->x1, reduction)
tileComp->h = jpxCeilDivPow2(tileComp->y1 - tileComp->y0, reduction); - jpxCeilDivPow2(tileComp->x0, reduction);
tileComp->h = jpxCeilDivPow2(tileComp->y1, reduction)
- jpxCeilDivPow2(tileComp->y0, reduction);
if (tileComp->w == 0 || tileComp->h == 0) {
error(errSyntaxError, getPos(),
"Invalid tile size or sample separation in JPX stream");
return gFalse;
}
tileComp->data = (int *)gmallocn(tileComp->w * tileComp->h, sizeof(int)); tileComp->data = (int *)gmallocn(tileComp->w * tileComp->h, sizeof(int));
if (tileComp->x1 - tileComp->x0 > tileComp->y1 - tileComp->y0) { if (tileComp->x1 - tileComp->x0 > tileComp->y1 - tileComp->y0) {
n = tileComp->x1 - tileComp->x0; n = tileComp->x1 - tileComp->x0;
} else { } else {
n = tileComp->y1 - tileComp->y0; n = tileComp->y1 - tileComp->y0;
} }
tileComp->buf = (int *)gmallocn(n + 8, sizeof(int)); tileComp->buf = (int *)gmallocn(n + 8, sizeof(int));
for (r = 0; r <= tileComp->nDecompLevels; ++r) { for (r = 0; r <= tileComp->nDecompLevels; ++r) {
resLevel = &tileComp->resLevels[r]; resLevel = &tileComp->resLevels[r];
k = r == 0 ? tileComp->nDecompLevels k = r == 0 ? tileComp->nDecompLevels
: tileComp->nDecompLevels - r + 1; : tileComp->nDecompLevels - r + 1;
resLevel->x0 = jpxCeilDivPow2(tileComp->x0, k); resLevel->x0 = jpxCeilDivPow2(tileComp->x0, k);
resLevel->y0 = jpxCeilDivPow2(tileComp->y0, k); resLevel->y0 = jpxCeilDivPow2(tileComp->y0, k);
resLevel->x1 = jpxCeilDivPow2(tileComp->x1, k); resLevel->x1 = jpxCeilDivPow2(tileComp->x1, k);
resLevel->y1 = jpxCeilDivPow2(tileComp->y1, k); resLevel->y1 = jpxCeilDivPow2(tileComp->y1, k);
// the JPEG 2000 spec says that packets for empty res levels
// should all be present in the codestream (B.6, B.9, B.10),
// but it appears that encoders drop packets if the res level
// AND the subbands are all completely empty
resLevel->empty = resLevel->x0 == resLevel->x1 ||
resLevel->y0 == resLevel->y1;
if (r == 0) { if (r == 0) {
resLevel->bx0[0] = resLevel->x0; resLevel->bx0[0] = resLevel->x0;
resLevel->by0[0] = resLevel->y0; resLevel->by0[0] = resLevel->y0;
resLevel->bx1[0] = resLevel->x1; resLevel->bx1[0] = resLevel->x1;
resLevel->by1[0] = resLevel->y1; resLevel->by1[0] = resLevel->y1;
resLevel->empty = resLevel->bx0[0] == resLevel->bx1[0] || resLevel->empty = resLevel->empty &&
resLevel->by0[0] == resLevel->by1[0]; (resLevel->bx0[0] == resLevel->bx1[0] ||
resLevel->by0[0] == resLevel->by1[0]);
} else { } else {
resLevel->bx0[0] = jpxCeilDivPow2(tileComp->x0 - (1 << (k-1)), k); resLevel->bx0[0] = jpxCeilDivPow2(tileComp->x0 - (1 << (k-1)), k);
resLevel->by0[0] = resLevel->y0; resLevel->by0[0] = resLevel->y0;
resLevel->bx1[0] = jpxCeilDivPow2(tileComp->x1 - (1 << (k-1)), k); resLevel->bx1[0] = jpxCeilDivPow2(tileComp->x1 - (1 << (k-1)), k);
resLevel->by1[0] = resLevel->y1; resLevel->by1[0] = resLevel->y1;
resLevel->bx0[1] = resLevel->x0; resLevel->bx0[1] = resLevel->x0;
resLevel->by0[1] = jpxCeilDivPow2(tileComp->y0 - (1 << (k-1)), k); resLevel->by0[1] = jpxCeilDivPow2(tileComp->y0 - (1 << (k-1)), k);
resLevel->bx1[1] = resLevel->x1; resLevel->bx1[1] = resLevel->x1;
resLevel->by1[1] = jpxCeilDivPow2(tileComp->y1 - (1 << (k-1)), k); resLevel->by1[1] = jpxCeilDivPow2(tileComp->y1 - (1 << (k-1)), k);
resLevel->bx0[2] = jpxCeilDivPow2(tileComp->x0 - (1 << (k-1)), k); resLevel->bx0[2] = jpxCeilDivPow2(tileComp->x0 - (1 << (k-1)), k);
resLevel->by0[2] = jpxCeilDivPow2(tileComp->y0 - (1 << (k-1)), k); resLevel->by0[2] = jpxCeilDivPow2(tileComp->y0 - (1 << (k-1)), k);
resLevel->bx1[2] = jpxCeilDivPow2(tileComp->x1 - (1 << (k-1)), k); resLevel->bx1[2] = jpxCeilDivPow2(tileComp->x1 - (1 << (k-1)), k);
resLevel->by1[2] = jpxCeilDivPow2(tileComp->y1 - (1 << (k-1)), k); resLevel->by1[2] = jpxCeilDivPow2(tileComp->y1 - (1 << (k-1)), k);
resLevel->empty = (resLevel->bx0[0] == resLevel->bx1[0] || resLevel->empty = resLevel->empty &&
(resLevel->bx0[0] == resLevel->bx1[0] ||
resLevel->by0[0] == resLevel->by1[0]) && resLevel->by0[0] == resLevel->by1[0]) &&
(resLevel->bx0[1] == resLevel->bx1[1] || (resLevel->bx0[1] == resLevel->bx1[1] ||
resLevel->by0[1] == resLevel->by1[1]) && resLevel->by0[1] == resLevel->by1[1]) &&
(resLevel->bx0[2] == resLevel->bx1[2] || (resLevel->bx0[2] == resLevel->bx1[2] ||
resLevel->by0[2] == resLevel->by1[2]); resLevel->by0[2] == resLevel->by1[2]);
} }
resLevel->precincts = (JPXPrecinct *)gmallocn(1, sizeof(JPXPrecinct)); resLevel->precincts = (JPXPrecinct *)gmallocn(1, sizeof(JPXPrecinct));
for (pre = 0; pre < 1; ++pre) { for (pre = 0; pre < 1; ++pre) {
resLevel->precincts[pre].subbands = NULL; resLevel->precincts[pre].subbands = NULL;
} }
skipping to change at line 2120 skipping to change at line 2131
JPXResLevel *resLevel; JPXResLevel *resLevel;
JPXPrecinct *precinct; JPXPrecinct *precinct;
JPXSubband *subband; JPXSubband *subband;
JPXCodeBlock *cb; JPXCodeBlock *cb;
Guint ttVal; Guint ttVal;
Guint bits, cbX, cbY, nx, ny, i, j, n, sb; Guint bits, cbX, cbY, nx, ny, i, j, n, sb;
int level; int level;
tile = &img.tiles[tileIdx]; tile = &img.tiles[tileIdx];
// if the tile is finished, just skip this tile part
if (tile->done) {
bufStr->discardChars(tilePartLen);
return gTrue;
}
// read all packets from this tile-part // read all packets from this tile-part
while (1) { while (1) {
if (tilePartToEOC) { if (tilePartToEOC) {
//~ peek for an EOC marker //~ peek for an EOC marker
cover(93); cover(93);
} else if (tilePartLen == 0) { } else if (tilePartLen == 0) {
break; break;
} }
tileComp = &tile->tileComps[tile->comp]; tileComp = &tile->tileComps[tile->comp];
skipping to change at line 2376 skipping to change at line 2393
nextPacket: nextPacket:
switch (tile->progOrder) { switch (tile->progOrder) {
case 0: // layer, resolution level, component, precinct case 0: // layer, resolution level, component, precinct
cover(58); cover(58);
if (++tile->comp == img.nComps) { if (++tile->comp == img.nComps) {
tile->comp = 0; tile->comp = 0;
if (++tile->res == tile->maxNDecompLevels + 1) { if (++tile->res == tile->maxNDecompLevels + 1) {
tile->res = 0; tile->res = 0;
if (++tile->layer == tile->nLayers) { if (++tile->layer == tile->nLayers) {
tile->layer = 0; tile->layer = 0;
tile->done = gTrue;
} }
} }
} }
break; break;
case 1: // resolution level, layer, component, precinct case 1: // resolution level, layer, component, precinct
cover(59); cover(59);
if (++tile->comp == img.nComps) { if (++tile->comp == img.nComps) {
tile->comp = 0; tile->comp = 0;
if (++tile->layer == tile->nLayers) { if (++tile->layer == tile->nLayers) {
tile->layer = 0; tile->layer = 0;
if (++tile->res == tile->maxNDecompLevels + 1) { if (++tile->res == tile->maxNDecompLevels + 1) {
tile->res = 0; tile->res = 0;
tile->done = gTrue;
} }
} }
} }
break; break;
case 2: // resolution level, precinct, component, layer case 2: // resolution level, precinct, component, layer
//~ this isn't correct -- see B.12.1.3 //~ this isn't correct -- see B.12.1.3
cover(60); cover(60);
if (++tile->layer == tile->nLayers) { if (++tile->layer == tile->nLayers) {
tile->layer = 0; tile->layer = 0;
if (++tile->comp == img.nComps) { if (++tile->comp == img.nComps) {
tile->comp = 0; tile->comp = 0;
if (++tile->res == tile->maxNDecompLevels + 1) { if (++tile->res == tile->maxNDecompLevels + 1) {
tile->res = 0; tile->res = 0;
tile->done = gTrue;
} }
} }
} }
break; break;
case 3: // precinct, component, resolution level, layer case 3: // precinct, component, resolution level, layer
//~ this isn't correct -- see B.12.1.4 //~ this isn't correct -- see B.12.1.4
cover(61); cover(61);
if (++tile->layer == tile->nLayers) { if (++tile->layer == tile->nLayers) {
tile->layer = 0; tile->layer = 0;
if (++tile->res == tile->maxNDecompLevels + 1) { if (++tile->res == tile->maxNDecompLevels + 1) {
tile->res = 0; tile->res = 0;
if (++tile->comp == img.nComps) { if (++tile->comp == img.nComps) {
tile->comp = 0; tile->comp = 0;
tile->done = gTrue;
} }
} }
} }
break; break;
case 4: // component, precinct, resolution level, layer case 4: // component, precinct, resolution level, layer
//~ this isn't correct -- see B.12.1.5 //~ this isn't correct -- see B.12.1.5
cover(62); cover(62);
if (++tile->layer == tile->nLayers) { if (++tile->layer == tile->nLayers) {
tile->layer = 0; tile->layer = 0;
if (++tile->res == tile->maxNDecompLevels + 1) { if (++tile->res == tile->maxNDecompLevels + 1) {
tile->res = 0; tile->res = 0;
if (++tile->comp == img.nComps) { if (++tile->comp == img.nComps) {
tile->comp = 0; tile->comp = 0;
tile->done = gTrue;
} }
} }
} }
break; break;
} }
} }
return gTrue; return gTrue;
err: err:
 End of changes. 17 change blocks. 
18 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)