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'
Image = require './image.coffee'
_ = require 'lodash'
Image = require './image.coffee'
ImageFormat = require './image_format.coffee'
module.exports = class ChannelImage extends Image
constructor: (file, header, @layer) ->
@width = @layer.width
@height = @layer.height
@includes ImageFormat.LayerRAW
@includes ImageFormat.LayerRLE
constructor: (file, header, @layer) ->
super(file, header)
@channelsInfo = @layer.channelsInfo
......@@ -18,6 +18,8 @@ module.exports = class ChannelImage extends Image
for chan in @channelsInfo
@file.seek chan.length, true
width: -> @layer.width
height: -> @layer.height
channels: -> @layer.channels
parse: ->
......
......@@ -77,4 +77,4 @@ module.exports = class Image extends Module
when 3 then @combineRgbChannel()
when 4 then @combineCmykChannel()
@channelData = null
\ No newline at end of file
@channelData = null
module.exports =
RAW: require('./image_formats/raw.coffee')
RLE: require('./image_formats/rle.coffee')
\ No newline at end of file
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'
LazyExecute = require '../lazy_execute.coffee'
module.exports =
parseChannelImage: ->
......
......@@ -4,6 +4,7 @@ _ = require 'lodash'
module.exports = class Node extends Module
@includes require('./nodes/ancestry.coffee')
@includes require('./nodes/search.coffee')
# @includes require('./nodes/build_preview.coffee')
@PROPERTIES: ['name', 'left', 'right', 'top', 'bottom', 'height', 'width']
......@@ -93,4 +94,4 @@ module.exports = class Node extends Module
@left = _.min(nonEmptyChildren.map((c) -> c.left)) or 0
@top = _.min(nonEmptyChildren.map((c) -> c.top)) or 0
@bottom = _.max(nonEmptyChildren.map((c) -> c.bottom)) or 0
@right = _.max(nonEmptyChildren.map((c) -> c.right)) or 0
\ No newline at end of file
@right = _.max(nonEmptyChildren.map((c) -> c.right)) or 0
......@@ -13,4 +13,4 @@ module.exports = class Group extends Node
export: ->
_.merge super(),
type: 'group'
children: @_children.map((c) -> c.export())
\ No newline at end of file
children: @_children.map((c) -> c.export())
......@@ -10,4 +10,4 @@ module.exports = class Layer extends Node
_.merge super,
type: 'layer'
mask: @layer.mask.export()
image: {}
\ No newline at end of file
image: {}
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