Skip to content

Commit 985fb1d

Browse files
authored
Don't paint the background if the PDF has transparency (#2804)
1 parent 7d4cba1 commit 985fb1d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

libvips/foreign/pdfiumload.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ EOF
104104

105105
#include <fpdfview.h>
106106
#include <fpdf_doc.h>
107+
#include <fpdf_edit.h>
107108

108109
typedef struct _VipsForeignLoadPdf {
109110
VipsForeignLoad parent_object;
@@ -151,9 +152,9 @@ typedef struct _VipsForeignLoadPdf {
151152
VipsRect image;
152153
VipsRect *pages;
153154

154-
/* The [double] background converted to the image format.
155+
/* The [double] background converted to the PDFium format.
155156
*/
156-
VipsPel *ink;
157+
FPDF_DWORD ink;
157158

158159
} VipsForeignLoadPdf;
159160

@@ -437,6 +438,7 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
437438

438439
int top;
439440
int i;
441+
VipsPel *ink;
440442

441443
#ifdef DEBUG
442444
printf( "vips_foreign_load_pdf_header: %p\n", pdf );
@@ -518,15 +520,13 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
518520

519521
/* Convert the background to the image format.
520522
*/
521-
if( !(pdf->ink = vips__vector_to_ink( class->nickname,
523+
if( !(ink = vips__vector_to_ink( class->nickname,
522524
load->out,
523525
VIPS_AREA( pdf->background )->data, NULL,
524526
VIPS_AREA( pdf->background )->n )) )
525527
return( -1 );
526528

527-
/* Swap B and R.
528-
*/
529-
vips__bgra2rgba( (guint32 *) pdf->ink, 1 );
529+
pdf->ink = (ink[3] << 24) + (ink[0] << 16) + (ink[1] << 8) + ink[2];
530530

531531
return( 0 );
532532
}
@@ -554,10 +554,6 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
554554
r->left, r->top, r->width, r->height );
555555
*/
556556

557-
/* PDFium won't always paint the background.
558-
*/
559-
vips_region_paint_pel( or, r, pdf->ink );
560-
561557
/* Search through the pages we are drawing for the first containing
562558
* this rect. This could be quicker, perhaps a binary search, but who
563559
* cares.
@@ -584,6 +580,11 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
584580
VIPS_REGION_ADDR( or, rect.left, rect.top ),
585581
VIPS_REGION_LSKIP( or ) );
586582

583+
/* PDFium won't always paint the background.
584+
*/
585+
if ( !FPDFPage_HasTransparency(pdf->page) )
586+
FPDFBitmap_FillRect(bitmap, 0, 0, rect.width, rect.height, pdf->ink);
587+
587588
FPDF_RenderPageBitmap( bitmap, pdf->page,
588589
0, 0, rect.width, rect.height,
589590
0, 0 );

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy