[Pkg-javascript-commits] [pdf.js] 61/139: fixed multi precinct handling in jpx
David Prévot
taffit at moszumanska.debian.org
Fri Jan 9 21:18:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit da5c0cf0e2c7378b5b625ecce52b291df49b5158
Author: Paul Roit <plroit at gmail.com>
Date: Thu Nov 13 09:06:41 2014 +0100
fixed multi precinct handling in jpx
fixes #5475
---
src/core/jpx.js | 48 +++++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/src/core/jpx.js b/src/core/jpx.js
index 3c6a210..c7e1fd4 100644
--- a/src/core/jpx.js
+++ b/src/core/jpx.js
@@ -480,6 +480,23 @@ var JpxImage = (function JpxImageClosure() {
// Section B.6 Division resolution to precincts
var precinctWidth = 1 << dimensions.PPx;
var precinctHeight = 1 << dimensions.PPy;
+ // Jasper introduces codeblock groups for mapping each subband codeblocks
+ // to precincts. Precinct partition divides a resolution according to width
+ // and height parameters. The subband that belongs to the resolution level
+ // has a different size than the level, unless it is the zero resolution.
+
+ // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
+ // The precinct partitioning for a particular subband is derived from a
+ // partitioning of its parent LL band (i.e., the LL band at the next higher
+ // resolution level)... The LL band associated with each resolution level is
+ // divided into precincts... Each of the resulting precinct regions is then
+ // mapped into its child subbands (if any) at the next lower resolution
+ // level. This is accomplished by using the coordinate transformation
+ // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
+ // coordinates of a point in the LL band and child subband, respectively.
+ var isZeroRes = resolution.resLevel === 0;
+ var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
+ var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
Math.ceil(resolution.trx1 / precinctWidth) -
Math.floor(resolution.trx0 / precinctWidth) : 0);
@@ -487,18 +504,15 @@ var JpxImage = (function JpxImageClosure() {
Math.ceil(resolution.try1 / precinctHeight) -
Math.floor(resolution.try0 / precinctHeight) : 0);
var numprecincts = numprecinctswide * numprecinctshigh;
- var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
- precinctWidth;
- var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
- precinctHeight;
+
resolution.precinctParameters = {
- precinctXOffset: precinctXOffset,
- precinctYOffset: precinctYOffset,
precinctWidth: precinctWidth,
precinctHeight: precinctHeight,
numprecinctswide: numprecinctswide,
numprecinctshigh: numprecinctshigh,
- numprecincts: numprecincts
+ numprecincts: numprecincts,
+ precinctWidthInSubband: precinctWidthInSubband,
+ precinctHeightInSubband: precinctHeightInSubband
};
}
function buildCodeblocks(context, subband, dimensions) {
@@ -525,18 +539,21 @@ var JpxImage = (function JpxImageClosure() {
tbx1: codeblockWidth * (i + 1),
tby1: codeblockHeight * (j + 1)
};
- // calculate precinct number
- var pi = Math.floor((codeblock.tbx0 -
- precinctParameters.precinctXOffset) /
- precinctParameters.precinctWidth);
- var pj = Math.floor((codeblock.tby0 -
- precinctParameters.precinctYOffset) /
- precinctParameters.precinctHeight);
- precinctNumber = pj + pi * precinctParameters.numprecinctswide;
+
codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
+
+ // Calculate precinct number for this codeblock, codeblock position
+ // should be relative to its subband, use actual dimension and position
+ // See comment about codeblock group width and height
+ var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
+ precinctParameters.precinctWidthInSubband);
+ var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
+ precinctParameters.precinctHeightInSubband);
+ precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
+
codeblock.precinctNumber = precinctNumber;
codeblock.subbandType = subband.type;
codeblock.Lblock = 3;
@@ -701,6 +718,7 @@ var JpxImage = (function JpxImageClosure() {
resolution.try0 = Math.ceil(component.tcy0 / scale);
resolution.trx1 = Math.ceil(component.tcx1 / scale);
resolution.try1 = Math.ceil(component.tcy1 / scale);
+ resolution.resLevel = r;
buildPrecincts(context, resolution, blocksDimensions);
resolutions.push(resolution);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list