Merge pull request #4406 from nnethercote/fix-and-transfer-masks
Improve image mask handling again
This commit is contained in:
commit
57e896d29e
@ -14,10 +14,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals assert, assertWellFormed, ColorSpace, Dict, Encodings, error,
|
/* globals assert, assertWellFormed, ColorSpace, DecodeStream, Dict, Encodings,
|
||||||
ErrorFont, Font, FONT_IDENTITY_MATRIX, fontCharsToUnicode, FontFlags,
|
error, ErrorFont, Font, FONT_IDENTITY_MATRIX, fontCharsToUnicode,
|
||||||
ImageKind, info, isArray, isCmd, isDict, isEOF, isName, isNum,
|
FontFlags, ImageKind, info, isArray, isCmd, isDict, isEOF, isName,
|
||||||
isStream, isString, JpegStream, Lexer, Metrics, Name, Parser,
|
isNum, isStream, isString, JpegStream, Lexer, Metrics, Name, Parser,
|
||||||
Pattern, PDFImage, PDFJS, serifFonts, stdFontMap, symbolsFonts,
|
Pattern, PDFImage, PDFJS, serifFonts, stdFontMap, symbolsFonts,
|
||||||
getTilingPatternIR, warn, Util, Promise, LegacyPromise,
|
getTilingPatternIR, warn, Util, Promise, LegacyPromise,
|
||||||
RefSetCache, isRef, TextRenderingMode, CMapFactory, OPS,
|
RefSetCache, isRef, TextRenderingMode, CMapFactory, OPS,
|
||||||
@ -146,10 +146,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var bitStrideLength = (width + 7) >> 3;
|
var bitStrideLength = (width + 7) >> 3;
|
||||||
var imgArray = image.getBytes(bitStrideLength * height);
|
var imgArray = image.getBytes(bitStrideLength * height);
|
||||||
var decode = dict.get('Decode', 'D');
|
var decode = dict.get('Decode', 'D');
|
||||||
|
var canTransfer = image instanceof DecodeStream;
|
||||||
var inverseDecode = !!decode && decode[0] > 0;
|
var inverseDecode = !!decode && decode[0] > 0;
|
||||||
|
|
||||||
operatorList.addOp(OPS.paintImageMaskXObject,
|
operatorList.addOp(OPS.paintImageMaskXObject,
|
||||||
[PDFImage.createMask(imgArray, width, height, inverseDecode)]
|
[PDFImage.createMask(imgArray, width, height, canTransfer,
|
||||||
|
inverseDecode)]
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -209,19 +209,25 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
return temp;
|
return temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFImage.createMask = function PDFImage_createMask(imgArray, width, height,
|
PDFImage.createMask =
|
||||||
|
function PDFImage_createMask(imgArray, width, height, canTransfer,
|
||||||
inverseDecode) {
|
inverseDecode) {
|
||||||
// Copy imgArray into a typed array (inverting if necessary) so it can be
|
// If imgArray came from a DecodeStream, we're safe to transfer it.
|
||||||
// transferred to the main thread.
|
// Otherwise, copy it.
|
||||||
var length = ((width + 7) >> 3) * height;
|
var actualLength = imgArray.byteLength;
|
||||||
var data = new Uint8Array(length);
|
var data;
|
||||||
if (inverseDecode) {
|
if (canTransfer) {
|
||||||
for (var i = 0; i < length; i++) {
|
data = imgArray;
|
||||||
data[i] = ~imgArray[i];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < length; i++) {
|
data = new Uint8Array(actualLength);
|
||||||
data[i] = imgArray[i];
|
data.set(imgArray);
|
||||||
|
}
|
||||||
|
// Invert if necessary. It's safe to modify the array -- whether it's the
|
||||||
|
// original or a copy, we're about to transfer it anyway, so nothing else
|
||||||
|
// in this thread can be relying on its contents.
|
||||||
|
if (inverseDecode) {
|
||||||
|
for (var i = 0; i < actualLength; i++) {
|
||||||
|
data[i] = ~data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user