Merge pull request #347 from notmasteryet/stencil
Implements ImageMask: using image as a stencil mask
This commit is contained in:
commit
bf9718feaf
44
pdf.js
44
pdf.js
@ -4889,7 +4889,10 @@ var CanvasGraphics = (function() {
|
|||||||
var imgData = tmpCtx.getImageData(0, 0, w, h);
|
var imgData = tmpCtx.getImageData(0, 0, w, h);
|
||||||
var pixels = imgData.data;
|
var pixels = imgData.data;
|
||||||
|
|
||||||
imageObj.fillRgbaBuffer(pixels);
|
if (imageObj.imageMask)
|
||||||
|
imageObj.fillUsingStencilMask(pixels, this.current.fillColor);
|
||||||
|
else
|
||||||
|
imageObj.fillRgbaBuffer(pixels);
|
||||||
|
|
||||||
tmpCtx.putImageData(imgData, 0, 0);
|
tmpCtx.putImageData(imgData, 0, 0);
|
||||||
ctx.drawImage(tmpCanvas, 0, -h);
|
ctx.drawImage(tmpCanvas, 0, -h);
|
||||||
@ -5660,14 +5663,16 @@ var PDFImage = (function() {
|
|||||||
}
|
}
|
||||||
this.bpc = bitsPerComponent;
|
this.bpc = bitsPerComponent;
|
||||||
|
|
||||||
var colorSpace = dict.get('ColorSpace', 'CS');
|
if (!this.imageMask) {
|
||||||
if (!colorSpace) {
|
var colorSpace = dict.get('ColorSpace', 'CS');
|
||||||
TODO('JPX images (which don"t require color spaces');
|
if (!colorSpace) {
|
||||||
colorSpace = new Name('DeviceRGB');
|
TODO('JPX images (which don"t require color spaces');
|
||||||
|
colorSpace = new Name('DeviceRGB');
|
||||||
|
}
|
||||||
|
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
|
||||||
|
this.numComps = this.colorSpace.numComps;
|
||||||
}
|
}
|
||||||
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
|
|
||||||
|
|
||||||
this.numComps = this.colorSpace.numComps;
|
|
||||||
this.decode = dict.get('Decode', 'D');
|
this.decode = dict.get('Decode', 'D');
|
||||||
|
|
||||||
var mask = xref.fetchIfRef(image.dict.get('Mask'));
|
var mask = xref.fetchIfRef(image.dict.get('Mask'));
|
||||||
@ -5763,6 +5768,31 @@ var PDFImage = (function() {
|
|||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
},
|
},
|
||||||
|
fillUsingStencilMask: function fillUsingStencilMask(buffer, cssRgb) {
|
||||||
|
var m = /rgb\((\d+),(\d+),(\d+)\)/.exec(cssRgb); // parse CSS color
|
||||||
|
var r = m[1] | 0, g = m[2] | 0, b = m[3] | 0;
|
||||||
|
var width = this.width;
|
||||||
|
var height = this.height;
|
||||||
|
var imgArray = this.image.getBytes((height * width + 7) >> 3);
|
||||||
|
var i, j, mask;
|
||||||
|
var bufferPos = 0, imgArrayPos = 0;
|
||||||
|
for (i = 0; i < height; i++) {
|
||||||
|
for (j = 0; j < width; j++) {
|
||||||
|
var buf = imgArray[imgArrayPos++];
|
||||||
|
for (mask = 128; mask > 0; mask >>= 1) {
|
||||||
|
if (buf & mask) {
|
||||||
|
buffer[bufferPos++] = r;
|
||||||
|
buffer[bufferPos++] = g;
|
||||||
|
buffer[bufferPos++] = b;
|
||||||
|
buffer[bufferPos++] = 255;
|
||||||
|
} else {
|
||||||
|
buffer[bufferPos + 3] = 0;
|
||||||
|
bufferPos += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
fillRgbaBuffer: function fillRgbaBuffer(buffer) {
|
fillRgbaBuffer: function fillRgbaBuffer(buffer) {
|
||||||
var numComps = this.numComps;
|
var numComps = this.numComps;
|
||||||
var width = this.width;
|
var width = this.width;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user