Newer
Older
Import / applications / MakePDF / 3rdParty / libharu / pr-patches / 0001-If-document-compression-is-requested-and-a-png-image.patch
From e68711c1419b611c8cac736fdf306cd280544523 Mon Sep 17 00:00:00 2001
From: User <user@tor.localdomain>
Date: Sat, 22 Jun 2013 07:57:00 -0400
Subject: [PATCH] If document compression is requested and a png image with an
 alpha channel is embedded; compress the mask.

---
 src/hpdf_doc_png.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/hpdf_doc_png.c b/src/hpdf_doc_png.c
index bad87c6..f1daf26 100644
--- a/src/hpdf_doc_png.c
+++ b/src/hpdf_doc_png.c
@@ -155,15 +155,21 @@ LoadPngImageFromStream (HPDF_Doc      pdf,
                         HPDF_BOOL     delayed_loading)
 {
     HPDF_Image image;
+    HPDF_Dict smask;
 
     HPDF_PTRACE ((" HPDF_LoadPngImageFromStream\n"));
 
     image = HPDF_Image_LoadPngImage (pdf->mmgr, imagedata, pdf->xref,
                 delayed_loading);
 
-    if (image && (pdf->compression_mode & HPDF_COMP_IMAGE))
+    if (image && (pdf->compression_mode & HPDF_COMP_IMAGE)) {
         image->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
 
+	// is there an alpha layer? then compress it also
+	smask = HPDF_Dict_GetItem(image, "SMask", HPDF_OCLASS_DICT);
+	if (smask) smask->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
+    }
+
     return image;
 }
 
-- 
2.21.1 (Apple Git-122.3)