From 6ad217e1e9acf2cc30ee8a9425b8727818ed9c71 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 16 May 2022 00:31:09 +0600 Subject: [PATCH] Don't paint the background if the PDF has transparency --- libvips/foreign/pdfiumload.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libvips/foreign/pdfiumload.c b/libvips/foreign/pdfiumload.c index b389cf69ee..001e304710 100644 --- a/libvips/foreign/pdfiumload.c +++ b/libvips/foreign/pdfiumload.c @@ -104,6 +104,7 @@ EOF #include #include +#include typedef struct _VipsForeignLoadPdf { VipsForeignLoad parent_object; @@ -151,9 +152,9 @@ typedef struct _VipsForeignLoadPdf { VipsRect image; VipsRect *pages; - /* The [double] background converted to the image format. + /* The [double] background converted to the PDFium format. */ - VipsPel *ink; + FPDF_DWORD ink; } VipsForeignLoadPdf; @@ -437,6 +438,7 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load ) int top; int i; + VipsPel *ink; #ifdef DEBUG printf( "vips_foreign_load_pdf_header: %p\n", pdf ); @@ -518,15 +520,13 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load ) /* Convert the background to the image format. */ - if( !(pdf->ink = vips__vector_to_ink( class->nickname, + if( !(ink = vips__vector_to_ink( class->nickname, load->out, VIPS_AREA( pdf->background )->data, NULL, VIPS_AREA( pdf->background )->n )) ) return( -1 ); - /* Swap B and R. - */ - vips__bgra2rgba( (guint32 *) pdf->ink, 1 ); + pdf->ink = (ink[3] << 24) + (ink[0] << 16) + (ink[1] << 8) + ink[2]; return( 0 ); } @@ -554,10 +554,6 @@ vips_foreign_load_pdf_generate( VipsRegion *or, r->left, r->top, r->width, r->height ); */ - /* PDFium won't always paint the background. - */ - vips_region_paint_pel( or, r, pdf->ink ); - /* Search through the pages we are drawing for the first containing * this rect. This could be quicker, perhaps a binary search, but who * cares. @@ -584,6 +580,11 @@ vips_foreign_load_pdf_generate( VipsRegion *or, VIPS_REGION_ADDR( or, rect.left, rect.top ), VIPS_REGION_LSKIP( or ) ); + /* PDFium won't always paint the background. + */ + if ( !FPDFPage_HasTransparency(pdf->page) ) + FPDFBitmap_FillRect(bitmap, 0, 0, rect.width, rect.height, pdf->ink); + FPDF_RenderPageBitmap( bitmap, pdf->page, 0, 0, rect.width, rect.height, 0, 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