Commit 5eda9ee0 authored by Ryan LeFevre's avatar Ryan LeFevre

Remove node-png dependency #7

parent 7998c9a7
fs = require 'fs'
{Png} = require 'png'
{PNG} = require 'pngjs'
RSVP = require 'rsvp'
module.exports =
toPng: ->
new RSVP.Promise (resolve, reject) =>
png = new Png(new Buffer(@pixelData), @width(), @height(), 'rgba')
png.encode(resolve)
png = new PNG(filterType: 4, width: @width(), height: @height())
png.data[i] = p for p, i in @pixelData
resolve(png)
saveAsPng: (output) ->
new RSVP.Promise (resolve, reject) =>
@toPng()
.then (image) ->
fs.writeFile output, image.toString('binary'), 'binary', resolve
image.pack().pipe(fs.createWriteStream(output))
resolve()
......@@ -5,13 +5,14 @@ module.exports =
.filter (ch) -> ch >= -1
for i in [0...@numPixels]
r = g = b = a = 0
r = g = b = 0
a = 255
for chan, index in rgbChannels
val = @channelData[i + (@channelLength * index)]
switch chan
when -1 then a = 255 - val
when -1 then a = val
when 0 then r = val
when 1 then g = val
when 2 then b = val
......
......@@ -12,7 +12,7 @@
"coffee-script": "~ 1.7.1",
"jspack": "~ 0.0.3",
"coffeescript-module": "~ 0.2.1",
"png": "~ 3.0.3",
"pngjs": "~ 0.4.0",
"rsvp": "~ 3.0.6",
"lodash": "~ 2.4"
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment