Merge pull request #10482 from janpe2/indexed-decode
Implement Decode entry in Indexed images
This commit is contained in:
commit
e2701d5422
@ -492,7 +492,7 @@ class AlternateCS extends ColorSpace {
|
|||||||
alpha01);
|
alpha01);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -565,8 +565,19 @@ class IndexedCS extends ColorSpace {
|
|||||||
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return true; // Indexed color maps shouldn't be changed.
|
if (!Array.isArray(decodeMap)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (decodeMap.length !== 2) {
|
||||||
|
warn('Decode map length is not correct');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Number.isInteger(bpc) || bpc < 1) {
|
||||||
|
warn('Bits per component is not correct');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,7 +620,7 @@ class DeviceGrayCS extends ColorSpace {
|
|||||||
return inputLength * (3 + alpha01);
|
return inputLength * (3 + alpha01);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -661,7 +672,7 @@ class DeviceRgbCS extends ColorSpace {
|
|||||||
return bits === 8;
|
return bits === 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -744,7 +755,7 @@ const DeviceCmykCS = (function DeviceCmykCSClosure() {
|
|||||||
return (inputLength / 4 * (3 + alpha01)) | 0;
|
return (inputLength / 4 * (3 + alpha01)) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -847,7 +858,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||||||
return inputLength * (3 + alpha01);
|
return inputLength * (3 + alpha01);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1129,7 +1140,7 @@ const CalRGBCS = (function CalRGBCSClosure() {
|
|||||||
return (inputLength * (3 + alpha01) / 3) | 0;
|
return (inputLength * (3 + alpha01) / 3) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1280,7 +1291,7 @@ const LabCS = (function LabCSClosure() {
|
|||||||
return (inputLength * (3 + alpha01) / 3) | 0;
|
return (inputLength * (3 + alpha01) / 3) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap) {
|
isDefaultDecode(decodeMap, bpc) {
|
||||||
// XXX: Decoding is handled with the lab conversion because of the strange
|
// XXX: Decoding is handled with the lab conversion because of the strange
|
||||||
// ranges that are used.
|
// ranges that are used.
|
||||||
return true;
|
return true;
|
||||||
|
@ -100,6 +100,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||||
pdfFunctionFactory);
|
pdfFunctionFactory);
|
||||||
|
// isDefaultDecode() of DeviceGray and DeviceRGB needs no `bpc` argument.
|
||||||
return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
|
return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
|
||||||
cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
||||||
};
|
};
|
||||||
@ -114,8 +115,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||||
pdfFunctionFactory);
|
pdfFunctionFactory);
|
||||||
|
const bpc = dict.get('BitsPerComponent', 'BPC') || 1;
|
||||||
return (cs.numComps === 1 || cs.numComps === 3) &&
|
return (cs.numComps === 1 || cs.numComps === 3) &&
|
||||||
cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
cs.isDefaultDecode(dict.getArray('Decode', 'D'), bpc);
|
||||||
};
|
};
|
||||||
|
|
||||||
function PartialEvaluator({ pdfManager, xref, handler, pageIndex, idFactory,
|
function PartialEvaluator({ pdfManager, xref, handler, pageIndex, idFactory,
|
||||||
|
@ -169,18 +169,21 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
this.decode = dict.getArray('Decode', 'D');
|
this.decode = dict.getArray('Decode', 'D');
|
||||||
this.needsDecode = false;
|
this.needsDecode = false;
|
||||||
if (this.decode &&
|
if (this.decode &&
|
||||||
((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
|
((this.colorSpace &&
|
||||||
|
!this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent)) ||
|
||||||
(isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
|
(isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
|
||||||
this.needsDecode = true;
|
this.needsDecode = true;
|
||||||
// Do some preprocessing to avoid more math.
|
// Do some preprocessing to avoid more math.
|
||||||
var max = (1 << bitsPerComponent) - 1;
|
var max = (1 << bitsPerComponent) - 1;
|
||||||
this.decodeCoefficients = [];
|
this.decodeCoefficients = [];
|
||||||
this.decodeAddends = [];
|
this.decodeAddends = [];
|
||||||
|
const isIndexed = this.colorSpace && this.colorSpace.name === 'Indexed';
|
||||||
for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
||||||
var dmin = this.decode[i];
|
var dmin = this.decode[i];
|
||||||
var dmax = this.decode[i + 1];
|
var dmax = this.decode[i + 1];
|
||||||
this.decodeCoefficients[j] = dmax - dmin;
|
this.decodeCoefficients[j] = isIndexed ? ((dmax - dmin) / max) :
|
||||||
this.decodeAddends[j] = max * dmin;
|
(dmax - dmin);
|
||||||
|
this.decodeAddends[j] = isIndexed ? dmin : (max * dmin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -251,6 +251,7 @@
|
|||||||
!bug878026.pdf
|
!bug878026.pdf
|
||||||
!issue1045.pdf
|
!issue1045.pdf
|
||||||
!issue5010.pdf
|
!issue5010.pdf
|
||||||
|
!issue10339_reduced.pdf
|
||||||
!issue4934.pdf
|
!issue4934.pdf
|
||||||
!issue4650.pdf
|
!issue4650.pdf
|
||||||
!issue6721_reduced.pdf
|
!issue6721_reduced.pdf
|
||||||
|
BIN
test/pdfs/issue10339_reduced.pdf
Normal file
BIN
test/pdfs/issue10339_reduced.pdf
Normal file
Binary file not shown.
@ -2651,6 +2651,12 @@
|
|||||||
"link": false,
|
"link": false,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue10339",
|
||||||
|
"file": "pdfs/issue10339_reduced.pdf",
|
||||||
|
"md5": "e34ef74f188080f8194c7d8e8b68c562",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue1721",
|
{ "id": "issue1721",
|
||||||
"file": "pdfs/issue1721.pdf",
|
"file": "pdfs/issue1721.pdf",
|
||||||
"md5": "b47177f9e5197a76ec498733ecab60e6",
|
"md5": "b47177f9e5197a76ec498733ecab60e6",
|
||||||
|
@ -496,7 +496,7 @@ describe('colorspace', function () {
|
|||||||
expect(colorSpace.getRgb([2], 0)).toEqual(
|
expect(colorSpace.getRgb([2], 0)).toEqual(
|
||||||
new Uint8ClampedArray([255, 109, 70]));
|
new Uint8ClampedArray([255, 109, 70]));
|
||||||
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
expect(colorSpace.isPassthrough(8)).toBeFalsy();
|
||||||
expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();
|
expect(colorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();
|
||||||
expect(testDest).toEqual(expectedDest);
|
expect(testDest).toEqual(expectedDest);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user