Skip to content

Commit 851e454

Browse files
committed
Don't paint the background if the PDF has transparency
1 parent 982cbe5 commit 851e454

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

libvips/foreign/pdfiumload.c

Lines changed: 12 additions & 7 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,12 +520,14 @@ 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

529+
pdf->ink = (ink[0] << 24) + (ink[1] << 16) + (ink[2] << 8) + ink[3];
530+
527531
return( 0 );
528532
}
529533

@@ -550,10 +554,6 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
550554
r->left, r->top, r->width, r->height );
551555
*/
552556

553-
/* PDFium won't always paint the background.
554-
*/
555-
vips_region_paint_pel( or, r, pdf->ink );
556-
557557
/* Search through the pages we are drawing for the first containing
558558
* this rect. This could be quicker, perhaps a binary search, but who
559559
* cares.
@@ -580,6 +580,11 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
580580
VIPS_REGION_ADDR( or, rect.left, rect.top ),
581581
VIPS_REGION_LSKIP( or ) );
582582

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+
583588
FPDF_RenderPageBitmap( bitmap, pdf->page,
584589
0, 0, rect.width, rect.height,
585590
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