mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Merge pull request #19791 from Snuffleupagus/IndexedCS-round-clamp
Handle non-integer and out-of-range values correctly in Indexed color spaces
This commit is contained in:
commit
220a28933c
4 changed files with 105 additions and 7 deletions
|
@ -429,6 +429,7 @@ class IndexedCS extends ColorSpace {
|
||||||
constructor(base, highVal, lookup) {
|
constructor(base, highVal, lookup) {
|
||||||
super("Indexed", 1);
|
super("Indexed", 1);
|
||||||
this.base = base;
|
this.base = base;
|
||||||
|
this.highVal = highVal;
|
||||||
|
|
||||||
const length = base.numComps * (highVal + 1);
|
const length = base.numComps * (highVal + 1);
|
||||||
this.lookup = new Uint8Array(length);
|
this.lookup = new Uint8Array(length);
|
||||||
|
@ -452,9 +453,10 @@ class IndexedCS extends ColorSpace {
|
||||||
'IndexedCS.getRgbItem: Unsupported "dest" type.'
|
'IndexedCS.getRgbItem: Unsupported "dest" type.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const numComps = this.base.numComps;
|
const { base, highVal, lookup } = this;
|
||||||
const start = src[srcOffset] * numComps;
|
const start =
|
||||||
this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
|
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) {
|
getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
|
||||||
|
@ -464,13 +466,13 @@ class IndexedCS extends ColorSpace {
|
||||||
'IndexedCS.getRgbBuffer: Unsupported "dest" type.'
|
'IndexedCS.getRgbBuffer: Unsupported "dest" type.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const base = this.base;
|
const { base, highVal, lookup } = this;
|
||||||
const numComps = base.numComps;
|
const { numComps } = base;
|
||||||
const outputDelta = base.getOutputLength(numComps, alpha01);
|
const outputDelta = base.getOutputLength(numComps, alpha01);
|
||||||
const lookup = this.lookup;
|
|
||||||
|
|
||||||
for (let i = 0; i < count; ++i) {
|
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);
|
base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
|
||||||
destOffset += outputDelta;
|
destOffset += outputDelta;
|
||||||
}
|
}
|
||||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -191,6 +191,7 @@
|
||||||
!rotation.pdf
|
!rotation.pdf
|
||||||
!simpletype3font.pdf
|
!simpletype3font.pdf
|
||||||
!Type3WordSpacing.pdf
|
!Type3WordSpacing.pdf
|
||||||
|
!IndexedCS_negative_and_high.pdf
|
||||||
!sizes.pdf
|
!sizes.pdf
|
||||||
!javauninstall-7r.pdf
|
!javauninstall-7r.pdf
|
||||||
!file_url_link.pdf
|
!file_url_link.pdf
|
||||||
|
|
87
test/pdfs/IndexedCS_negative_and_high.pdf
Normal file
87
test/pdfs/IndexedCS_negative_and_high.pdf
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
%PDF-1.7
|
||||||
|
%âãÏÓ
|
||||||
|
|
||||||
|
1 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Catalog
|
||||||
|
/Pages 2 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
2 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Pages
|
||||||
|
/Kids [ 3 0 R ]
|
||||||
|
/Count 1
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
3 0 obj
|
||||||
|
<<
|
||||||
|
/Type /Page
|
||||||
|
/Parent 2 0 R
|
||||||
|
/MediaBox [ 0 0 500 100 ]
|
||||||
|
/Contents 5 0 R
|
||||||
|
/Resources <<
|
||||||
|
/ColorSpace << /Cs1 4 0 R >>
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
|
||||||
|
4 0 obj
|
||||||
|
[
|
||||||
|
/Indexed /DeviceRGB
|
||||||
|
7 % "hival"
|
||||||
|
< 008000 FF0000 00FF00 0000FF 00FFFF FF00FF FFFF00 F380FF > % indices 0-7 inclusive
|
||||||
|
]
|
||||||
|
endobj
|
||||||
|
|
||||||
|
5 0 obj
|
||||||
|
<<
|
||||||
|
/Length 1037
|
||||||
|
>>
|
||||||
|
stream
|
||||||
|
% Reference
|
||||||
|
0 0.5 0 rg 5 10 20 20 re f % 008000
|
||||||
|
0 0.5 0 rg 30 10 20 20 re f % 008000
|
||||||
|
1 0 0 rg 55 10 20 20 re f % FF0000
|
||||||
|
0 1 0 rg 80 10 20 20 re f % 00FF00
|
||||||
|
0 0 1 rg 105 10 20 20 re f % 0000FF
|
||||||
|
0 1 1 rg 130 10 20 20 re f % 00FFFF
|
||||||
|
1 0 1 rg 155 10 20 20 re f % FF00FF
|
||||||
|
1 1 0 rg 180 10 20 20 re f % FFFF00
|
||||||
|
0.95 0.5 1 rg 205 10 20 20 re f % F380FF
|
||||||
|
0.95 0.5 1 rg 230 10 20 20 re f % F380FF
|
||||||
|
0.95 0.5 1 rg 255 10 20 20 re f % F380FF
|
||||||
|
|
||||||
|
% Test patches
|
||||||
|
/Cs1 cs
|
||||||
|
-17 sc 5 50 20 20 re f % Below 0 --> snap to 0
|
||||||
|
0 sc 30 50 20 20 re f
|
||||||
|
1 sc 55 50 20 20 re f
|
||||||
|
2 sc 80 50 20 20 re f
|
||||||
|
3 sc 105 50 20 20 re f
|
||||||
|
4 sc 130 50 20 20 re f
|
||||||
|
5 sc 155 50 20 20 re f
|
||||||
|
6 sc 180 50 20 20 re f
|
||||||
|
7 sc 205 50 20 20 re f % Same as "Hival" = OK
|
||||||
|
6.5 sc 230 50 20 20 re f % Needs to round up --> snap to "hival"
|
||||||
|
17 sc 255 50 20 20 re f % Clearly out of range! --> snap to "hival"
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
xref
|
||||||
|
0 6
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000019 00000 n
|
||||||
|
0000000083 00000 n
|
||||||
|
0000000162 00000 n
|
||||||
|
0000000332 00000 n
|
||||||
|
0000000503 00000 n
|
||||||
|
trailer
|
||||||
|
<<
|
||||||
|
/Root 1 0 R
|
||||||
|
/Size 6
|
||||||
|
>>
|
||||||
|
startxref
|
||||||
|
1600
|
||||||
|
%%EOF
|
|
@ -2851,6 +2851,14 @@
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "IndexedCS_negative_and_high",
|
||||||
|
"file": "pdfs/IndexedCS_negative_and_high.pdf",
|
||||||
|
"md5": "3bbf5e6f1cf49acb075fabb0726b5fe4",
|
||||||
|
"link": false,
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "issue13372",
|
"id": "issue13372",
|
||||||
"file": "pdfs/issue13372.pdf",
|
"file": "pdfs/issue13372.pdf",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue