| 1 |
/** |
|---|
| 2 |
* com.voidelement.images.psd.PSDParser Class for ActionScript 3.0 |
|---|
| 3 |
* |
|---|
| 4 |
* @author Copyright (c) 2007 munegon |
|---|
| 5 |
* @version 0.2 |
|---|
| 6 |
* |
|---|
| 7 |
* @link http://www.voidelement.com/ |
|---|
| 8 |
* @link http://void.heteml.jp/blog/ |
|---|
| 9 |
* |
|---|
| 10 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 11 |
* you may not use this file except in compliance with the License. |
|---|
| 12 |
* You may obtain a copy of the License at |
|---|
| 13 |
* |
|---|
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 15 |
* |
|---|
| 16 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 17 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 18 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|---|
| 19 |
* either express or implied. See the License for the specific language |
|---|
| 20 |
* governing permissions and limitations under the License. |
|---|
| 21 |
*/ |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
package com.voidelement.images.psd.layer { |
|---|
| 25 |
import com.voidelement.images.psd.PSDParser; |
|---|
| 26 |
import com.voidelement.images.psd.core.PStringB4; |
|---|
| 27 |
import com.voidelement.images.psd.core.Rect; |
|---|
| 28 |
|
|---|
| 29 |
import flash.utils.ByteArray; |
|---|
| 30 |
|
|---|
| 31 |
public class LayerStructure { |
|---|
| 32 |
private var _bounds:Rect; |
|---|
| 33 |
public function get bounds():Rect { return _bounds; } |
|---|
| 34 |
|
|---|
| 35 |
private var _numChannels:uint; |
|---|
| 36 |
public function get numChannels():uint { return _numChannels; } |
|---|
| 37 |
|
|---|
| 38 |
private var _info:Array; |
|---|
| 39 |
public function get info():Array { return _info; } |
|---|
| 40 |
|
|---|
| 41 |
private var _signature:String; |
|---|
| 42 |
public function get signature():String { return _signature; } |
|---|
| 43 |
|
|---|
| 44 |
private var _blendModeKey:String; |
|---|
| 45 |
public function get blendModeKey():String { return _blendModeKey; } |
|---|
| 46 |
|
|---|
| 47 |
private var _opacity:uint; |
|---|
| 48 |
public function get opacity():uint { return _opacity; } |
|---|
| 49 |
|
|---|
| 50 |
private var _clipping:uint; |
|---|
| 51 |
public function get clipping():uint { return _clipping; } |
|---|
| 52 |
|
|---|
| 53 |
private var _flags:uint; |
|---|
| 54 |
public function get flags():uint { return _flags; } |
|---|
| 55 |
|
|---|
| 56 |
private var _ranges:Array; |
|---|
| 57 |
public function get ranges():Array { return _ranges; } |
|---|
| 58 |
|
|---|
| 59 |
private var _name:PStringB4; |
|---|
| 60 |
public function get name():PStringB4 { return _name; } |
|---|
| 61 |
|
|---|
| 62 |
private var _extra:ByteArray; |
|---|
| 63 |
public function get extra():ByteArray { return _extra; } |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
public function LayerStructure( stream:ByteArray ) { |
|---|
| 67 |
_bounds = new Rect( stream ); |
|---|
| 68 |
_numChannels = stream.readUnsignedShort(); |
|---|
| 69 |
_info = new Array( numChannels ); |
|---|
| 70 |
|
|---|
| 71 |
for ( var i:uint = 0; i < numChannels; ++i ) { |
|---|
| 72 |
info[i] = new ChannelLengthInfo( stream ); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
_signature = stream.readUTFBytes( 4 ); |
|---|
| 76 |
|
|---|
| 77 |
if ( signature != "8BIM") { |
|---|
| 78 |
throw new Error("invalid signature: " + signature ); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
_blendModeKey = stream.readUTFBytes( 4 ); |
|---|
| 82 |
_opacity = stream.readUnsignedByte(); |
|---|
| 83 |
_clipping = stream.readUnsignedByte(); |
|---|
| 84 |
_flags = stream.readUnsignedByte(); |
|---|
| 85 |
|
|---|
| 86 |
stream.position += 1; // padding |
|---|
| 87 |
|
|---|
| 88 |
PSDParser.log("blendMode: " + blendModeKey ); |
|---|
| 89 |
PSDParser.log("opacity: " + opacity ); |
|---|
| 90 |
PSDParser.log("clipping: " + clipping ); |
|---|
| 91 |
PSDParser.log("flags: " + ("0000000" + flags.toString( 2 ) ).substr( -8 ) ); |
|---|
| 92 |
|
|---|
| 93 |
parseExtraData( stream ); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
private function parseExtraData( stream:ByteArray ):void { |
|---|
| 97 |
var size:uint = stream.readUnsignedInt(); |
|---|
| 98 |
PSDParser.log("Extra Data size: " + size ); |
|---|
| 99 |
|
|---|
| 100 |
if ( size > 0 ) { |
|---|
| 101 |
var pos:uint = stream.position; |
|---|
| 102 |
|
|---|
| 103 |
parseLayerMaskData( stream ); |
|---|
| 104 |
parseLayerBlendingRanges( stream ); |
|---|
| 105 |
|
|---|
| 106 |
_name = new PStringB4( stream ); |
|---|
| 107 |
PSDParser.log("name: " + name ); |
|---|
| 108 |
|
|---|
| 109 |
PSDParser.log("extra available: " + ( pos + size - stream.position ) ); |
|---|
| 110 |
stream.position += pos + size - stream.position; |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
private function parseLayerMaskData( stream:ByteArray ):void { |
|---|
| 115 |
var size:uint = stream.readUnsignedInt(); |
|---|
| 116 |
PSDParser.log("Layer Mask Data size: " + size ); |
|---|
| 117 |
|
|---|
| 118 |
if ( size > 0 ) { |
|---|
| 119 |
var bounds:Rect = new Rect( stream ); |
|---|
| 120 |
var defaultColor:uint = stream.readUnsignedByte(); |
|---|
| 121 |
var flags:uint = stream.readUnsignedByte(); |
|---|
| 122 |
|
|---|
| 123 |
stream.position += 2; // padding |
|---|
| 124 |
|
|---|
| 125 |
PSDParser.log(" bounds: " + bounds.toString() ); |
|---|
| 126 |
PSDParser.log(" defaultColor: " + defaultColor ); |
|---|
| 127 |
PSDParser.log(" flags: " + ("0000000" + flags.toString( 2 ) ).substr( -8 ) ); |
|---|
| 128 |
} |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
private function parseLayerBlendingRanges( stream:ByteArray ):void { |
|---|
| 132 |
var size:uint = stream.readUnsignedInt(); |
|---|
| 133 |
PSDParser.log("Layer Blending Ranges size: " + size ); |
|---|
| 134 |
|
|---|
| 135 |
if ( size > 0 ) { |
|---|
| 136 |
var pos:uint = stream.position; |
|---|
| 137 |
|
|---|
| 138 |
var grayBlendSource:uint = stream.readUnsignedInt(); |
|---|
| 139 |
var grayBlendDest:uint = stream.readUnsignedInt(); |
|---|
| 140 |
|
|---|
| 141 |
PSDParser.log(" grayBlendSource: " + ("0000000" + grayBlendSource.toString( 16 ) ).substr( -8 ) ); |
|---|
| 142 |
PSDParser.log(" grayBlendDest: " + ("0000000" + grayBlendDest.toString( 16 ) ).substr( -8 ) ); |
|---|
| 143 |
|
|---|
| 144 |
_ranges = new Array( numChannels ); |
|---|
| 145 |
|
|---|
| 146 |
for ( var i:uint = 0; i < numChannels; ++i ) { |
|---|
| 147 |
ranges[i] = new ChannelSourceRange( stream ); |
|---|
| 148 |
PSDParser.log(" " + ["red", "green", "blue", "alpha"][i] + "BlendSource: " + ("0000000" + ranges[i].source.toString( 16 ) ).substr( -8 ) ); |
|---|
| 149 |
PSDParser.log(" " + ["red", "green", "blue", "alpha"][i] + "BlendDest: " + ("0000000" + ranges[i].dest.toString( 16 ) ).substr( -8 ) ); |
|---|
| 150 |
} |
|---|
| 151 |
} |
|---|
| 152 |
} |
|---|
| 153 |
} |
|---|
| 154 |
} |
|---|