mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge pull request #10482 from janpe2/indexed-decode
Implement Decode entry in Indexed images
This commit is contained in:
commit
e2701d5422
7 changed files with 37 additions and 14 deletions
|
@ -492,7 +492,7 @@ class AlternateCS extends ColorSpace {
|
|||
alpha01);
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -565,8 +565,19 @@ class IndexedCS extends ColorSpace {
|
|||
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
return true; // Indexed color maps shouldn't be changed.
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
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);
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -661,7 +672,7 @@ class DeviceRgbCS extends ColorSpace {
|
|||
return bits === 8;
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -744,7 +755,7 @@ const DeviceCmykCS = (function DeviceCmykCSClosure() {
|
|||
return (inputLength / 4 * (3 + alpha01)) | 0;
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -847,7 +858,7 @@ const CalGrayCS = (function CalGrayCSClosure() {
|
|||
return inputLength * (3 + alpha01);
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -1129,7 +1140,7 @@ const CalRGBCS = (function CalRGBCSClosure() {
|
|||
return (inputLength * (3 + alpha01) / 3) | 0;
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
||||
}
|
||||
}
|
||||
|
@ -1280,7 +1291,7 @@ const LabCS = (function LabCSClosure() {
|
|||
return (inputLength * (3 + alpha01) / 3) | 0;
|
||||
}
|
||||
|
||||
isDefaultDecode(decodeMap) {
|
||||
isDefaultDecode(decodeMap, bpc) {
|
||||
// XXX: Decoding is handled with the lab conversion because of the strange
|
||||
// ranges that are used.
|
||||
return true;
|
||||
|
|
|
@ -100,6 +100,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
}
|
||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||
pdfFunctionFactory);
|
||||
// isDefaultDecode() of DeviceGray and DeviceRGB needs no `bpc` argument.
|
||||
return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
|
||||
cs.isDefaultDecode(dict.getArray('Decode', 'D'));
|
||||
};
|
||||
|
@ -114,8 +115,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
}
|
||||
var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res,
|
||||
pdfFunctionFactory);
|
||||
const bpc = dict.get('BitsPerComponent', 'BPC') || 1;
|
||||
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,
|
||||
|
|
|
@ -169,18 +169,21 @@ var PDFImage = (function PDFImageClosure() {
|
|||
this.decode = dict.getArray('Decode', 'D');
|
||||
this.needsDecode = false;
|
||||
if (this.decode &&
|
||||
((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
|
||||
((this.colorSpace &&
|
||||
!this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent)) ||
|
||||
(isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
|
||||
this.needsDecode = true;
|
||||
// Do some preprocessing to avoid more math.
|
||||
var max = (1 << bitsPerComponent) - 1;
|
||||
this.decodeCoefficients = [];
|
||||
this.decodeAddends = [];
|
||||
const isIndexed = this.colorSpace && this.colorSpace.name === 'Indexed';
|
||||
for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
||||
var dmin = this.decode[i];
|
||||
var dmax = this.decode[i + 1];
|
||||
this.decodeCoefficients[j] = dmax - dmin;
|
||||
this.decodeAddends[j] = max * dmin;
|
||||
this.decodeCoefficients[j] = isIndexed ? ((dmax - dmin) / max) :
|
||||
(dmax - dmin);
|
||||
this.decodeAddends[j] = isIndexed ? dmin : (max * dmin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue