Commit c3e53bea authored by Ryan LeFevre's avatar Ryan LeFevre

Add vector mask parsing

parent fea60759
......@@ -54,3 +54,16 @@ module.exports = class File
colorComponent = (@readShort() >> 8) for i in [0...4]
colorSpace: colorSpace, components: colorComponent
# Adobe's lovely signed 32-bit fixed-point number with 8bits.24bits
# http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577409_17587
readPathNumber: ->
a = @readByte()
arr = @read(3)
b1 = arr[0] << 16
b2 = arr[1] << 8
b3 = arr[2]
b = b1 | b2 | b3
parseFloat(a, 10) + parseFloat(b / Math.pow(2, 24), 10)
......@@ -16,6 +16,7 @@ LAYER_INFO = {
objectEffects: require('../layer_info/object_effects.coffee')
sectionDivider: require('../layer_info/section_divider.coffee')
typeTool: require('../layer_info/typetool.coffee')
vectorMask: require('../layer_info/vector_mask.coffee')
}
module.exports =
......@@ -40,6 +41,7 @@ module.exports =
unless @[name]?
do (name) => @[name] = => @adjustments[name]
@infoKeys.push key
keyParseable = true
break
......
LayerInfo = require '../layer_info.coffee'
PathRecord = require '../path_record.coffee'
module.exports = class VectorMask extends LayerInfo
@shouldParse: (key) -> key in ['vmsk', 'vsms']
constructor: (layer, length) ->
super(layer, length)
@invert = null
@notLink = null
@disable = null
@paths = []
parse: ->
@file.seek 4, true # version
tag = @file.readInt()
@invert = (tag & 0x01) > 0
@notLink = (tag & (0x01 << 1)) > 0
@disable = (tag & (0x01 << 2)) > 0
# I haven't figured out yet why this is 10 and not 8.
numRecords = (@length - 10) / 26
for i in [0...numRecords]
record = new PathRecord(@file)
record.parse()
@paths.push record
export: ->
invert: @invert
notLink: @notLink
disable: @disable
paths: @paths.map (p) -> p.export()
_ = require 'lodash'
module.exports = class PathRecord
constructor: (@file) ->
@recordType = null
parse: ->
@recordType = @file.readShort()
switch @recordType
when 0, 3 then @_readPathRecord()
when 1, 2, 4, 5 then @_readBezierPoint()
when 7 then @_readClipboardRecord()
when 8 then @_readInitialFill()
else @file.seek(24, true)
export: ->
_.merge { recordType: @recordType }, switch @recordType
when 0, 3 then { numPoints: @numPoints }
when 1, 2, 4, 5
linked: @linked
closed: (@recordType in [1, 2])
preceding:
vert: @precedingVert
horiz: @precedingHoriz
anchor:
vert: @anchorVert
horiz: @anchorHoriz
leaving:
vert: @leavingVert
horiz: @leavingHoriz
when 7
clipboard:
top: @clipboardTop
left: @clipboardLeft
bottom: @clipboardBottom
right: @clipboardRight
resolution: @clipboardResolution
when 8 then { initialFill: @initialFill }
else {}
isBezierPoint: -> @recordType in [1, 2, 4, 5]
_readPathRecord: ->
@numPoints = @file.readShort()
@file.seek 22, true
_readBezierPoint: ->
@linked = @recordType in [1, 4]
@precedingVert = @file.readPathNumber()
@precedingHoriz = @file.readPathNumber()
@anchorVert = @file.readPathNumber()
@anchorHoriz = @file.readPathNumber()
@leavingVert = @file.readPathNumber()
@leavingHoriz = @file.readPathNumber()
_readClipboardRecord: ->
@clipboardTop = @file.readPathNumber()
@clipboardLeft = @file.readPathNumber()
@clipboardBottom = @file.readPathNumber()
@clipboardRight = @file.readPathNumber()
@clipboardResolution = @file.readPathNumber()
@file.seek 4, true
_readInitialFill: ->
@initialFill = @file.readShort()
@file.seek 22, true
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