Merge pull request #5485 from CodingFabian/save-pr-5479
fixed multi precinct handling in jpx
This commit is contained in:
commit
de9838018e
@ -480,6 +480,23 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
// Section B.6 Division resolution to precincts
|
// Section B.6 Division resolution to precincts
|
||||||
var precinctWidth = 1 << dimensions.PPx;
|
var precinctWidth = 1 << dimensions.PPx;
|
||||||
var precinctHeight = 1 << dimensions.PPy;
|
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 ?
|
var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
|
||||||
Math.ceil(resolution.trx1 / precinctWidth) -
|
Math.ceil(resolution.trx1 / precinctWidth) -
|
||||||
Math.floor(resolution.trx0 / precinctWidth) : 0);
|
Math.floor(resolution.trx0 / precinctWidth) : 0);
|
||||||
@ -487,18 +504,15 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
Math.ceil(resolution.try1 / precinctHeight) -
|
Math.ceil(resolution.try1 / precinctHeight) -
|
||||||
Math.floor(resolution.try0 / precinctHeight) : 0);
|
Math.floor(resolution.try0 / precinctHeight) : 0);
|
||||||
var numprecincts = numprecinctswide * numprecinctshigh;
|
var numprecincts = numprecinctswide * numprecinctshigh;
|
||||||
var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
|
|
||||||
precinctWidth;
|
|
||||||
var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
|
|
||||||
precinctHeight;
|
|
||||||
resolution.precinctParameters = {
|
resolution.precinctParameters = {
|
||||||
precinctXOffset: precinctXOffset,
|
|
||||||
precinctYOffset: precinctYOffset,
|
|
||||||
precinctWidth: precinctWidth,
|
precinctWidth: precinctWidth,
|
||||||
precinctHeight: precinctHeight,
|
precinctHeight: precinctHeight,
|
||||||
numprecinctswide: numprecinctswide,
|
numprecinctswide: numprecinctswide,
|
||||||
numprecinctshigh: numprecinctshigh,
|
numprecinctshigh: numprecinctshigh,
|
||||||
numprecincts: numprecincts
|
numprecincts: numprecincts,
|
||||||
|
precinctWidthInSubband: precinctWidthInSubband,
|
||||||
|
precinctHeightInSubband: precinctHeightInSubband
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function buildCodeblocks(context, subband, dimensions) {
|
function buildCodeblocks(context, subband, dimensions) {
|
||||||
@ -525,18 +539,21 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
tbx1: codeblockWidth * (i + 1),
|
tbx1: codeblockWidth * (i + 1),
|
||||||
tby1: codeblockHeight * (j + 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.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
|
||||||
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
|
codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
|
||||||
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
|
codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
|
||||||
codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
|
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.precinctNumber = precinctNumber;
|
||||||
codeblock.subbandType = subband.type;
|
codeblock.subbandType = subband.type;
|
||||||
codeblock.Lblock = 3;
|
codeblock.Lblock = 3;
|
||||||
@ -701,6 +718,7 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
resolution.try0 = Math.ceil(component.tcy0 / scale);
|
resolution.try0 = Math.ceil(component.tcy0 / scale);
|
||||||
resolution.trx1 = Math.ceil(component.tcx1 / scale);
|
resolution.trx1 = Math.ceil(component.tcx1 / scale);
|
||||||
resolution.try1 = Math.ceil(component.tcy1 / scale);
|
resolution.try1 = Math.ceil(component.tcy1 / scale);
|
||||||
|
resolution.resLevel = r;
|
||||||
buildPrecincts(context, resolution, blocksDimensions);
|
buildPrecincts(context, resolution, blocksDimensions);
|
||||||
resolutions.push(resolution);
|
resolutions.push(resolution);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user