Commit c895ffd7 authored by Ryan LeFevre's avatar Ryan LeFevre

Start on channel image parsing

parent 7998c9a7
_ = require 'lodash'
Image = require './image.coffee'
module.exports = class ChannelImage extends Image
constructor: (file, header, @layer) ->
@width = @layer.width
@height = @layer.height
super(file, header)
@channelsInfo = @layer.channelsInfo
@hasMask = _.any @channelsInfo, (c) -> c.id < -1
@opacity = @layer.opacity / 255.0
@maskData = []
skip: ->
for chan in @channelsInfo
@file.seek chan.length, true
channels: -> @layer.channels
parse: ->
@chanPos = 0
for chan in @channelsInfo
if chan.length <= 0
@parseCompression()
continue
@chan = chan
if chan.id < -1
@width = @layer.mask.width
@height = @layer.mask.height
else
@width = @layer.width
@height = @layer.height
@length = @width * @height
start = @file.tell()
@parseImageData()
finish = @file.tell()
if finish isnt start + @chan.length
@file.seek(start + @chan.length)
@width = @layer.width
@height = @layer.height
@processImageData()
...@@ -8,7 +8,7 @@ module.exports = class Layer extends Module ...@@ -8,7 +8,7 @@ module.exports = class Layer extends Module
@includes require('./layer/name.coffee') @includes require('./layer/name.coffee')
@includes require('./layer/info.coffee') @includes require('./layer/info.coffee')
@includes require('./layer/helpers.coffee') @includes require('./layer/helpers.coffee')
# @includes require('./layer/channel_image.coffee') @includes require('./layer/channel_image.coffee')
constructor: (@file, @header) -> constructor: (@file, @header) ->
@mask = {} @mask = {}
...@@ -53,4 +53,4 @@ module.exports = class Layer extends Module ...@@ -53,4 +53,4 @@ module.exports = class Layer extends Module
opacity: @opacity opacity: @opacity
visible: @visible visible: @visible
clipped: @clipped clipped: @clipped
mask: @mask.export() mask: @mask.export()
\ No newline at end of file
ChannelImage = require '../channel_image.coffee'
module.exports =
parseChannelImage: ->
image = new ChannelImage(@file, @header, @)
@image = new LazyExecute(image, @file)
.now('skip')
.later('parse')
.get()
...@@ -36,6 +36,8 @@ module.exports = class LayerMask ...@@ -36,6 +36,8 @@ module.exports = class LayerMask
for i in [0...layerCount] for i in [0...layerCount]
@layers.push new Layer(@file, @header).parse() @layers.push new Layer(@file, @header).parse()
layer.parseChannelImage() for layer in @layers
parseGlobalMask: -> parseGlobalMask: ->
length = @file.readInt() length = @file.readInt()
return if length <= 0 return if length <= 0
...@@ -56,4 +58,4 @@ module.exports = class LayerMask ...@@ -56,4 +58,4 @@ module.exports = class LayerMask
# 0 = color selected, 1 = color protected, 128 = use value per layer # 0 = color selected, 1 = color protected, 128 = use value per layer
mask.kind = @file.readByte() mask.kind = @file.readByte()
@file.seek maskEnd @file.seek maskEnd
\ No newline at end of file
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