@@ -119,7 +119,7 @@ class PDFImage {
119119 this . jpxDecoderOptions = {
120120 numComponents : 0 ,
121121 isIndexedColormap : false ,
122- smaskInData : dict . has ( "SMaskInData" ) ,
122+ smaskInData : dict . get ( "SMaskInData" ) >= 1 ,
123123 reducePower,
124124 } ;
125125 if ( reducePower ) {
@@ -196,6 +196,25 @@ class PDFImage {
196196 if ( ! this . imageMask ) {
197197 let colorSpace = dict . getRaw ( "CS" ) || dict . getRaw ( "ColorSpace" ) ;
198198 const hasColorSpace = ! ! colorSpace ;
199+
200+ if (
201+ this . jpxDecoderOptions ?. smaskInData &&
202+ dict . get ( "SMaskInData" ) === 2
203+ ) {
204+ this . jpxPremultiplied = true ;
205+ if ( this . matte ) {
206+ const matteColorSpace = ColorSpaceUtils . parse ( {
207+ cs : hasColorSpace ? colorSpace : Name . get ( "DeviceRGB" ) ,
208+ xref,
209+ resources : isInline ? res : null ,
210+ pdfFunctionFactory,
211+ globalColorSpaceCache,
212+ localColorSpaceCache,
213+ } ) ;
214+ this . preblendMatte = matteColorSpace . getRgb ( this . matte , 0 ) ;
215+ }
216+ }
217+
199218 if ( ! hasColorSpace ) {
200219 if ( this . jpxDecoderOptions ) {
201220 colorSpace = Name . get ( "DeviceRGBA" ) ;
@@ -654,22 +673,7 @@ class PDFImage {
654673 } ) ;
655674 }
656675
657- undoPreblend ( buffer , width , height ) {
658- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) {
659- assert (
660- buffer instanceof Uint8ClampedArray ,
661- 'PDFImage.undoPreblend: Unsupported "buffer" type.'
662- ) ;
663- }
664- const matte = this . smask ?. matte ;
665- if ( ! matte ) {
666- return ;
667- }
668- const matteRgb = this . colorSpace . getRgb ( matte , 0 ) ;
669- const matteR = matteRgb [ 0 ] ;
670- const matteG = matteRgb [ 1 ] ;
671- const matteB = matteRgb [ 2 ] ;
672- const length = width * height * 4 ;
676+ static #undoPreblend( buffer , length , matteR , matteG , matteB ) {
673677 for ( let i = 0 ; i < length ; i += 4 ) {
674678 const alpha = buffer [ i + 3 ] ;
675679 if ( alpha === 0 ) {
@@ -687,6 +691,27 @@ class PDFImage {
687691 }
688692 }
689693
694+ undoPreblend ( buffer , width , height ) {
695+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) {
696+ assert (
697+ buffer instanceof Uint8ClampedArray ,
698+ 'PDFImage.undoPreblend: Unsupported "buffer" type.'
699+ ) ;
700+ }
701+ const matte = this . smask ?. matte ;
702+ if ( ! matte ) {
703+ return ;
704+ }
705+ const matteRgb = this . colorSpace . getRgb ( matte , 0 ) ;
706+ PDFImage . #undoPreblend(
707+ buffer ,
708+ width * height * 4 ,
709+ matteRgb [ 0 ] ,
710+ matteRgb [ 1 ] ,
711+ matteRgb [ 2 ]
712+ ) ;
713+ }
714+
690715 async createImageData ( forceRGBA = false , isOffscreenCanvasSupported = false ) {
691716 const drawWidth = this . drawWidth ;
692717 const drawHeight = this . drawHeight ;
@@ -717,6 +742,17 @@ class PDFImage {
717742 { internal : isOffscreenCanvasSupported && mustBeResized }
718743 ) ) ;
719744
745+ if ( this . jpxPremultiplied ) {
746+ const matteRgb = this . preblendMatte ;
747+ PDFImage . #undoPreblend(
748+ imgArray ,
749+ imgArray . length ,
750+ matteRgb ?. [ 0 ] ?? 0 ,
751+ matteRgb ?. [ 1 ] ?? 0 ,
752+ matteRgb ?. [ 2 ] ?? 0
753+ ) ;
754+ }
755+
720756 if ( isOffscreenCanvasSupported ) {
721757 if ( ! mustBeResized ) {
722758 return this . createBitmap (
0 commit comments