mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 16:48:08 +02:00
Handle non-integer and out-of-range values correctly in Indexed color spaces
In PDF version 2.0 the handling of Indexed color spaces was clarified as follows: > The index value should be an integer in the range 0 to hival. If the value is a real number, it shall be rounded to the nearest integer (0.5 values shall be rounded up); if it is outside the range 0 to hival, it shall be adjusted to the nearest value within that range. Please refer to https://github.com/pdf-association/pdf-differences/tree/main/IndexedColor
This commit is contained in:
parent
22657e2b6e
commit
fbc4f4b12a
4 changed files with 105 additions and 7 deletions
|
@ -429,6 +429,7 @@ class IndexedCS extends ColorSpace {
|
|||
constructor(base, highVal, lookup) {
|
||||
super("Indexed", 1);
|
||||
this.base = base;
|
||||
this.highVal = highVal;
|
||||
|
||||
const length = base.numComps * (highVal + 1);
|
||||
this.lookup = new Uint8Array(length);
|
||||
|
@ -452,9 +453,10 @@ class IndexedCS extends ColorSpace {
|
|||
'IndexedCS.getRgbItem: Unsupported "dest" type.'
|
||||
);
|
||||
}
|
||||
const numComps = this.base.numComps;
|
||||
const start = src[srcOffset] * numComps;
|
||||
this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
|
||||
const { base, highVal, lookup } = this;
|
||||
const start =
|
||||
MathClamp(Math.round(src[srcOffset]), 0, highVal) * base.numComps;
|
||||
base.getRgbBuffer(lookup, start, 1, dest, destOffset, 8, 0);
|
||||
}
|
||||
|
||||
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
||||
|
@ -464,13 +466,13 @@ class IndexedCS extends ColorSpace {
|
|||
'IndexedCS.getRgbBuffer: Unsupported "dest" type.'
|
||||
);
|
||||
}
|
||||
const base = this.base;
|
||||
const numComps = base.numComps;
|
||||
const { base, highVal, lookup } = this;
|
||||
const { numComps } = base;
|
||||
const outputDelta = base.getOutputLength(numComps, alpha01);
|
||||
const lookup = this.lookup;
|
||||
|
||||
for (let i = 0; i < count; ++i) {
|
||||
const lookupPos = src[srcOffset++] * numComps;
|
||||
const lookupPos =
|
||||
MathClamp(Math.round(src[srcOffset++]), 0, highVal) * numComps;
|
||||
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
|
||||
destOffset += outputDelta;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue