Commit f92d255c authored by Ryan LeFevre's avatar Ryan LeFevre

More work towards channel images

parent 860aea39
var PSD = require('../../');
var file = process.argv[2] || './examples/images/example.psd';
var start = new Date();
PSD.open(file).then(function (psd) {
return psd.tree().descendants().forEach(function (node) {
if (node.isGroup()) return true;
return node.layer.image.saveAsPng("./output/#{node.name}.png");
});
}).then(function () {
console.log("Finished in " + ((new Date()) - start) + "ms");
});;
_ = require 'lodash' _ = require 'lodash'
Image = require './image.coffee' Image = require './image.coffee'
ImageFormat = require './image_format.coffee'
module.exports = class ChannelImage extends Image module.exports = class ChannelImage extends Image
@includes ImageFormat.LayerRAW
@includes ImageFormat.LayerRLE
constructor: (file, header, @layer) -> constructor: (file, header, @layer) ->
@width = @layer.width
@height = @layer.height
super(file, header) super(file, header)
@channelsInfo = @layer.channelsInfo @channelsInfo = @layer.channelsInfo
...@@ -18,6 +18,8 @@ module.exports = class ChannelImage extends Image ...@@ -18,6 +18,8 @@ module.exports = class ChannelImage extends Image
for chan in @channelsInfo for chan in @channelsInfo
@file.seek chan.length, true @file.seek chan.length, true
width: -> @layer.width
height: -> @layer.height
channels: -> @layer.channels channels: -> @layer.channels
parse: -> parse: ->
......
module.exports = module.exports =
RAW: require('./image_formats/raw.coffee') RAW: require('./image_formats/raw.coffee')
RLE: require('./image_formats/rle.coffee') RLE: require('./image_formats/rle.coffee')
LayerRLE: require('./image_formats/layer_rle.coffee')
LayerRAW: require('./image_formats/layer_raw.coffee')
module.exports =
parseRaw: ->
for i in [@chanPos...(@chanPos + @chan.length - 2)]
@channelData[i] = @file.readByte()
@chanPos += (@chan.length - 2)
module.exports =
parseByteCounts: ->
@file.readShort() for i in [0...@height()]
parseChannelData: ->
@lineIndex = 0
@decodeRLEChannel()
ChannelImage = require '../channel_image.coffee' ChannelImage = require '../channel_image.coffee'
LazyExecute = require '../lazy_execute.coffee'
module.exports = module.exports =
parseChannelImage: -> parseChannelImage: ->
......
...@@ -4,6 +4,7 @@ _ = require 'lodash' ...@@ -4,6 +4,7 @@ _ = require 'lodash'
module.exports = class Node extends Module module.exports = class Node extends Module
@includes require('./nodes/ancestry.coffee') @includes require('./nodes/ancestry.coffee')
@includes require('./nodes/search.coffee') @includes require('./nodes/search.coffee')
# @includes require('./nodes/build_preview.coffee')
@PROPERTIES: ['name', 'left', 'right', 'top', 'bottom', 'height', 'width'] @PROPERTIES: ['name', 'left', 'right', 'top', 'bottom', 'height', 'width']
......
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