From 717afaf3177a2e0925b18ae3445119efe808b129 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 16 Sep 2026 14:46:16 -0300 Subject: Add macOS backdrop blur and preserve PDF ink opacity --- src/pdf_bridge.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/pdf_bridge.c') diff --git a/src/pdf_bridge.c b/src/pdf_bridge.c index bdc7b891..976ed838 100644 --- a/src/pdf_bridge.c +++ b/src/pdf_bridge.c @@ -588,7 +588,8 @@ pardes_pdf_render_into( int height, int stride, int band_y, - int band_height) + int band_height, + int transparent_paper) { fz_context *ctx; fz_pixmap *pixmap = NULL; @@ -654,7 +655,8 @@ pardes_pdf_render_into( * paid either way by the glyph spans and the tint pass that walk the * same buffer immediately afterwards. Leave it alone. */ - fz_clear_pixmap_with_value(ctx, pixmap, 0xFF); + if (transparent_paper) fz_clear_pixmap(ctx, pixmap); + else fz_clear_pixmap_with_value(ctx, pixmap, 0xFF); if (document->cached_display_list != NULL || document->display_list_candidate_page_number == page_number) { @@ -719,6 +721,21 @@ pardes_pdf_render_into( return PARDES_PDF_ERROR; } + /* MuPDF draws premultiplied samples. The public RGBA contract and tint + * pass use straight alpha; preserve coverage and undo premultiplication. */ + if (transparent_paper) { + size_t pixel; + for (pixel = 0; pixel < samples_len; pixel += 4) { + unsigned int a = samples[pixel + 3]; + int channel; + if (a == 0 || a == 255) continue; + for (channel = 0; channel < 3; ++channel) { + unsigned int straight = (samples[pixel + channel] * 255u + a / 2) / a; + samples[pixel + channel] = (unsigned char)(straight > 255 ? 255 : straight); + } + } + } + if (document->cached_display_list == NULL) document->display_list_candidate_page_number = page_number; -- cgit v1.3