From d4604b4a74cda2a51a6f528fe6de1fbbf01c3e53 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Tue, 20 Oct 2015 09:53:52 +0100 Subject: [PATCH] fixes #433 --- lib/image/png.coffee | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/image/png.coffee b/lib/image/png.coffee index b446e49..ac9f1f0 100644 --- a/lib/image/png.coffee +++ b/lib/image/png.coffee @@ -8,28 +8,28 @@ class PNGImage @height = @image.height @imgData = @image.imgData @obj = null - + embed: (@document) -> return if @obj - - @obj = document.ref + + @obj = @document.ref Type: 'XObject' Subtype: 'Image' BitsPerComponent: @image.bits Width: @width Height: @height Filter: 'FlateDecode' - + unless @image.hasAlphaChannel - params = document.ref + params = @document.ref Predictor: 15 Colors: @image.colors BitsPerComponent: @image.bits Columns: @width - + @obj.data['DecodeParms'] = params params.end() - + if @image.palette.length is 0 @obj.data['ColorSpace'] = @image.colorSpace else @@ -39,7 +39,7 @@ class PNGImage # build the color space array for the image @obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', (@image.palette.length / 3) - 1, palette] - + # For PNG color types 0, 2 and 3, the transparency data is stored in # a dedicated PNG chunk. if @image.transparency.grayscale @@ -57,21 +57,21 @@ class PNGImage mask.push x, x @obj.data['Mask'] = mask - + else if @image.transparency.indexed - # Create a transparency SMask for the image based on the data + # Create a transparency SMask for the image based on the data # in the PLTE and tRNS sections. See below for details on SMasks. @loadIndexedAlphaChannel() - + else if @image.hasAlphaChannel # For PNG color types 4 and 6, the transparency data is stored as a alpha # channel mixed in with the main image data. Separate this data out into an # SMask object and store it separately in the PDF. @splitAlphaChannel() - + else @finalize() - + finalize: -> if @alphaChannel sMask = @document.ref @@ -89,11 +89,11 @@ class PNGImage # add the actual image data @obj.end @imgData - + # free memory @image = null @imgData = null - + splitAlphaChannel: -> @image.decodePixels (pixels) => colorByteSize = @image.colors * @image.bits / 8 @@ -117,7 +117,7 @@ class PNGImage zlib.deflate alphaChannel, (err, @alphaChannel) => throw err if err @finalize() if ++done is 2 - + loadIndexedAlphaChannel: (fn) -> transparency = @image.transparency.indexed @image.decodePixels (pixels) => @@ -130,5 +130,5 @@ class PNGImage zlib.deflate alphaChannel, (err, @alphaChannel) => throw err if err @finalize() - + module.exports = PNGImage