-
-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't paint the background if the PDF has transparency #2804
Don't paint the background if the PDF has transparency #2804
Conversation
(poppler |
I'm not sure this change is a good idea. Try this with the master branch and pdfium enabled:
To make: (it should be a red background, we should fix this) Or like this:
To make: (try opening that in an image viewer to see the transparent background) With this patch, the first example breaks since the transparent blue background is never applied. Could you solve your user's problem by converting with |
... I pushed something to master to fix the byte ordering of |
the `background` param was BGRA rather than vips-style RGBA see #2804
851e454
to
d10eb45
Compare
d10eb45
to
6ad217e
Compare
I tried adding: if( !(pdf->page = FPDF_LoadPage( pdf->doc, page_no )) ) {
g_mutex_unlock( vips_pdfium_mutex );
vips_pdfium_error();
vips_error( class->nickname,
_( "unable to load page %d" ), page_no );
return( -1 );
}
pdf->current_page = page_no;
printf( "HasTransparency = %d\n",
FPDFPage_HasTransparency(pdf->page) ) ; to
Even though that image obviously has a transparent background. I searched my collection of PDFs and I found one which does report transparency: http://www.rollthepotato.net/~john/bizz_2176220.pdf There's a single pixel at the bottom right where the alpha is 254 rather than 255. I don't think |
It is, but Most raw-text PDFs don't defy their background yet should not be rendered transparent. For example https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf. |
Ah I understand, thanks for the explanation. Yes, OK, let's merge, and thank you for pushing for this improvement! |
I changed it to use I suppose this means that the poppler PDF loader is wrong. I'll look for something like |
Great, thanks!
Ink in |
Yes, |
... and ARGB is BGRA but written LSB first. |
Hey again!
Some PDF pages require the background to be transparent to be rendered properly. Luckily,
FPDFPage_HasTransparency
returnsTRUE
for such pages so we can easily determine if we should fill the canvas before rendering. PDFium sample tool does the same check BTW: https://pdfium.googlesource.com/pdfium/+/refs/heads/main/samples/pdfium_test.cc#864.Also, I used
FPDFBitmap_FillRect
to fill the background of a single page instead of a whole canvas. And I changedpdf->ink
type so it can be used withFPDFBitmap_FillRect
, hope it's ok.Unfortunately, I can't share a sample I have as it was provided by a customer of our customer so I definitely have no right to share it anywhere.