Takes SMask's preblending in account
This commit is contained in:
parent
81fa4a0d93
commit
419bee1314
31
src/image.js
31
src/image.js
@ -70,6 +70,7 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
|
|
||||||
this.interpolate = dict.get('Interpolate', 'I') || false;
|
this.interpolate = dict.get('Interpolate', 'I') || false;
|
||||||
this.imageMask = dict.get('ImageMask', 'IM') || false;
|
this.imageMask = dict.get('ImageMask', 'IM') || false;
|
||||||
|
this.matte = dict.get('Matte') || false;
|
||||||
|
|
||||||
var bitsPerComponent = image.bitsPerComponent;
|
var bitsPerComponent = image.bitsPerComponent;
|
||||||
if (!bitsPerComponent) {
|
if (!bitsPerComponent) {
|
||||||
@ -386,6 +387,34 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
},
|
},
|
||||||
|
undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
|
||||||
|
var matte = this.smask && this.smask.matte;
|
||||||
|
if (!matte) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clamp(value) {
|
||||||
|
return (value < 0 ? 0 : value > 255 ? 255 : value) | 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matteRgb = this.colorSpace.getRgb(matte, 0);
|
||||||
|
var length = width * height * 4;
|
||||||
|
for (var i = 0; i < length; i += 4) {
|
||||||
|
var alpha = buffer[i + 3];
|
||||||
|
if (alpha === 0) {
|
||||||
|
// according formula we have to get Infinity in all components
|
||||||
|
// making it as white (tipical paper color) should be okay
|
||||||
|
buffer[i] = 255;
|
||||||
|
buffer[i + 1] = 255;
|
||||||
|
buffer[i + 2] = 255;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var k = 255 / alpha;
|
||||||
|
buffer[i] = clamp((buffer[i] - matteRgb[0]) * k + matteRgb[0]);
|
||||||
|
buffer[i + 1] = clamp((buffer[i + 1] - matteRgb[1]) * k + matteRgb[1]);
|
||||||
|
buffer[i + 2] = clamp((buffer[i + 2] - matteRgb[2]) * k + matteRgb[2]);
|
||||||
|
}
|
||||||
|
},
|
||||||
fillRgbaBuffer: function PDFImage_fillRgbaBuffer(buffer, width, height) {
|
fillRgbaBuffer: function PDFImage_fillRgbaBuffer(buffer, width, height) {
|
||||||
var numComps = this.numComps;
|
var numComps = this.numComps;
|
||||||
var originalWidth = this.width;
|
var originalWidth = this.width;
|
||||||
@ -422,6 +451,8 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
buffer[i + 2] = rgbBuf[compsPos++];
|
buffer[i + 2] = rgbBuf[compsPos++];
|
||||||
buffer[i + 3] = opacity[opacityPos++];
|
buffer[i + 3] = opacity[opacityPos++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.undoPreblend(buffer, width, actualHeight);
|
||||||
},
|
},
|
||||||
fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
|
fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
|
||||||
var numComps = this.numComps;
|
var numComps = this.numComps;
|
||||||
|
1
test/pdfs/bug888437.pdf.link
Normal file
1
test/pdfs/bug888437.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://bug888437.bugzilla.mozilla.org/attachment.cgi?id=770341
|
@ -1015,6 +1015,13 @@
|
|||||||
"link": true,
|
"link": true,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "bug888437",
|
||||||
|
"file": "pdfs/bug888437.pdf",
|
||||||
|
"md5": "93370cd589a08732a05601441c899bcb",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "annotation-tx",
|
{ "id": "annotation-tx",
|
||||||
"file": "pdfs/annotation-tx.pdf",
|
"file": "pdfs/annotation-tx.pdf",
|
||||||
"md5": "56321ea830be9c4f8437ca17ac535b2d",
|
"md5": "56321ea830be9c4f8437ca17ac535b2d",
|
||||||
|
Loading…
Reference in New Issue
Block a user