mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
fixes #433
This commit is contained in:
parent
86c94d2c19
commit
d4604b4a74
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user