Commit 545c754f authored by Ryan LeFevre's avatar Ryan LeFevre

Finish PNG exporting

parent 4c8ab8d6
{Module} = require 'coffeescript-module' {Module} = require 'coffeescript-module'
ImageFormat = require './image_format.coffee' ImageFormat = require './image_format.coffee'
ImageMode = require './image_mode.coffee' ImageMode = require './image_mode.coffee'
Export = require './image_export.coffee'
module.exports = class Image extends Module module.exports = class Image extends Module
@includes ImageFormat.RAW @includes ImageFormat.RAW
@includes ImageFormat.RLE @includes ImageFormat.RLE
@includes ImageMode.RGB @includes ImageMode.RGB
@includes Export.PNG
COMPRESSIONS = [ COMPRESSIONS = [
'Raw' 'Raw'
......
module.exports =
PNG: require('./image_exports/png.coffee')
\ No newline at end of file
fs = require 'fs'
{Png} = require 'png'
RSVP = require 'rsvp'
module.exports =
toPng: ->
return @png if @png
@png = new Png(new Buffer(@pixelData), @width(), @height(), 'rgba')
new RSVP.Promise (resolve, reject) =>
console.log "Encoding!"
@png.encode(resolve)
saveAsPng: (output) ->
new RSVP.Promise (resolve, reject) =>
@toPng()
.then (image) ->
console.log "Writing!"
fs.writeFile output, image.toString('binary'), 'binary', resolve
...@@ -5,14 +5,13 @@ module.exports = ...@@ -5,14 +5,13 @@ module.exports =
.filter (ch) -> ch >= -1 .filter (ch) -> ch >= -1
for i in [0...@numPixels] for i in [0...@numPixels]
r = g = b = 0 r = g = b = a = 0
a = 255
for chan, index in rgbChannels for chan, index in rgbChannels
val = @channelData[i + (@channelLength * index)] val = @channelData[i + (@channelLength * index)]
switch chan switch chan
when -1 then a = val when -1 then a = 255 - val
when 0 then r = val when 0 then r = val
when 1 then g = val when 1 then g = val
when 2 then b = val when 2 then b = val
......
...@@ -20,7 +20,7 @@ module.exports = class LazyExecute ...@@ -20,7 +20,7 @@ module.exports = class LazyExecute
return @ return @
get: -> get: ->
for own key, val of @obj then do (key, val) => for key, val of @obj then do (key, val) =>
return if @[key]? return if @[key]?
Object.defineProperty @, key, Object.defineProperty @, key,
get: -> get: ->
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
"dependencies": { "dependencies": {
"coffee-script": "~ 1.7.1", "coffee-script": "~ 1.7.1",
"jspack": "~ 0.0.3", "jspack": "~ 0.0.3",
"coffeescript-module": "~ 0.0.2" "coffeescript-module": "~ 0.0.2",
"png": "~ 3.0.3",
"rsvp": "~ 3.0.6"
}, },
"devDependencies": { "devDependencies": {
"coffeeify": "~ 0.6.0" "coffeeify": "~ 0.6.0"
......
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