summaryrefslogtreecommitdiff
path: root/src/pdf_bridge.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-16 14:46:16 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit717afaf3177a2e0925b18ae3445119efe808b129 (patch)
tree45a2196711de78d8d1e2db6cb5e5c51271676c2f /src/pdf_bridge.c
parent7cbd44dd1cfe97126e7fc996214e458525d2980c (diff)
downloadpardes-717afaf3177a2e0925b18ae3445119efe808b129.tar.gz
pardes-717afaf3177a2e0925b18ae3445119efe808b129.zip
Add macOS backdrop blur and preserve PDF ink opacity
Diffstat (limited to 'src/pdf_bridge.c')
-rw-r--r--src/pdf_bridge.c21
1 files changed, 19 insertions, 2 deletions
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;