1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

Merge pull request #19739 from Snuffleupagus/buildPaintImageXObject-fn-OPS

Reduce duplication when specifying the fn-operations in `buildPaintImageXObject`
This commit is contained in:
Tim van der Meij 2025-03-30 11:55:53 +02:00 committed by GitHub
commit 97bf09b795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -595,7 +595,7 @@ class PartialEvaluator {
} }
const imageMask = dict.get("IM", "ImageMask") || false; const imageMask = dict.get("IM", "ImageMask") || false;
let imgData, args; let imgData, fn, args;
if (imageMask) { if (imageMask) {
// This depends on a tmpCanvas being filled with the // This depends on a tmpCanvas being filled with the
// current fillStyle, such that processing the pixel // current fillStyle, such that processing the pixel
@ -618,20 +618,13 @@ class PartialEvaluator {
}); });
imgData.cached = !!cacheKey; imgData.cached = !!cacheKey;
args = [imgData];
operatorList.addImageOps( fn = OPS.paintImageMaskXObject;
OPS.paintImageMaskXObject, args = [imgData];
args, operatorList.addImageOps(fn, args, optionalContent);
optionalContent
);
if (cacheKey) { if (cacheKey) {
const cacheData = { const cacheData = { fn, args, optionalContent };
fn: OPS.paintImageMaskXObject,
args,
optionalContent,
};
localImageCache.set(cacheKey, imageRef, cacheData); localImageCache.set(cacheKey, imageRef, cacheData);
if (imageRef) { if (imageRef) {
@ -658,18 +651,12 @@ class PartialEvaluator {
if (imgData.isSingleOpaquePixel) { if (imgData.isSingleOpaquePixel) {
// Handles special case of mainly LaTeX documents which use image // Handles special case of mainly LaTeX documents which use image
// masks to draw lines with the current fill style. // masks to draw lines with the current fill style.
operatorList.addImageOps( fn = OPS.paintSolidColorImageMask;
OPS.paintSolidColorImageMask, args = [];
[], operatorList.addImageOps(fn, args, optionalContent);
optionalContent
);
if (cacheKey) { if (cacheKey) {
const cacheData = { const cacheData = { fn, args, optionalContent };
fn: OPS.paintSolidColorImageMask,
args: [],
optionalContent,
};
localImageCache.set(cacheKey, imageRef, cacheData); localImageCache.set(cacheKey, imageRef, cacheData);
if (imageRef) { if (imageRef) {
@ -691,6 +678,7 @@ class PartialEvaluator {
: imgData.data.length; : imgData.data.length;
this._sendImgData(objId, imgData); this._sendImgData(objId, imgData);
fn = OPS.paintImageMaskXObject;
args = [ args = [
{ {
data: objId, data: objId,
@ -700,19 +688,10 @@ class PartialEvaluator {
count: 1, count: 1,
}, },
]; ];
operatorList.addImageOps( operatorList.addImageOps(fn, args, optionalContent);
OPS.paintImageMaskXObject,
args,
optionalContent
);
if (cacheKey) { if (cacheKey) {
const cacheData = { const cacheData = { objId, fn, args, optionalContent };
objId,
fn: OPS.paintImageMaskXObject,
args,
optionalContent,
};
localImageCache.set(cacheKey, imageRef, cacheData); localImageCache.set(cacheKey, imageRef, cacheData);
if (imageRef) { if (imageRef) {
@ -782,19 +761,16 @@ class PartialEvaluator {
// Ensure that the dependency is added before the image is decoded. // Ensure that the dependency is added before the image is decoded.
operatorList.addDependency(objId); operatorList.addDependency(objId);
fn = OPS.paintImageXObject;
args = [objId, w, h]; args = [objId, w, h];
operatorList.addImageOps( operatorList.addImageOps(fn, args, optionalContent, hasMask);
OPS.paintImageXObject,
args,
optionalContent,
hasMask
);
if (cacheGlobally) { if (cacheGlobally) {
if (this.globalImageCache.hasDecodeFailed(imageRef)) { if (this.globalImageCache.hasDecodeFailed(imageRef)) {
this.globalImageCache.setData(imageRef, { this.globalImageCache.setData(imageRef, {
objId, objId,
fn: OPS.paintImageXObject, fn,
args, args,
optionalContent, optionalContent,
hasMask, hasMask,
@ -818,7 +794,7 @@ class PartialEvaluator {
if (localLength) { if (localLength) {
this.globalImageCache.setData(imageRef, { this.globalImageCache.setData(imageRef, {
objId, objId,
fn: OPS.paintImageXObject, fn,
args, args,
optionalContent, optionalContent,
hasMask, hasMask,
@ -865,13 +841,7 @@ class PartialEvaluator {
}); });
if (cacheKey) { if (cacheKey) {
const cacheData = { const cacheData = { objId, fn, args, optionalContent, hasMask };
objId,
fn: OPS.paintImageXObject,
args,
optionalContent,
hasMask,
};
localImageCache.set(cacheKey, imageRef, cacheData); localImageCache.set(cacheKey, imageRef, cacheData);
if (imageRef) { if (imageRef) {
@ -880,7 +850,7 @@ class PartialEvaluator {
if (cacheGlobally) { if (cacheGlobally) {
this.globalImageCache.setData(imageRef, { this.globalImageCache.setData(imageRef, {
objId, objId,
fn: OPS.paintImageXObject, fn,
args, args,
optionalContent, optionalContent,
hasMask, hasMask,