       zlib.deflate alphaChannel, (err, @alphaChannel) =>
         throw err if err
         @finalize() if ++done is 2
-        
+
   loadIndexedAlphaChannel: (fn) ->
     transparency = @image.transparency.indexed
     @image.decodePixels (pixels) =>

    @height = @image.height
    @imgData = @image.imgData
    @obj = null
    
  embed: (@document) ->
    return if @obj
    
    @obj = document.ref
      Type: 'XObject'
      Subtype: 'Image'
      BitsPerComponent: @image.bits
      Width: @width
      Height: @height
      Filter: 'FlateDecode'
      
    unless @image.hasAlphaChannel
      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

        mask.push x, x

      @obj.data['Mask'] = mask

    else if @image.transparency.indexed
      # 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
