root/as3/PSDParser/src/com/voidelement/images/psd/section/PSDLayerAndMask.as

リビジョン 97, 3.4 kB (コミッタ: munegon, コミット時期: 5 年 前)

--

Line 
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.section {
25         import com.voidelement.images.psd.PSDParser;
26         import com.voidelement.images.psd.core.Rect;
27         import com.voidelement.images.psd.layer.LayerPixelData;
28         import com.voidelement.images.psd.layer.LayerStructure;
29        
30         import flash.utils.ByteArray;
31        
32         public class PSDLayerAndMask {
33                 private var _layers:Array;
34                 public function get layers():Array { return _layers; }
35                
36                 private var _pixels:Array;
37                 public function get pixels():Array { return _pixels; }
38                
39                
40                 public function PSDLayerAndMask( stream:ByteArray ) {
41                         var size:uint = stream.readUnsignedInt();
42                         PSDParser.log("\n\n---- PSD Layer and Mask Information Block ----");
43                         PSDParser.log("size: " + size );
44                        
45                         if ( size > 0 ) {
46                                 var pos:uint = stream.position;
47                                
48                                 parseLayerInfo( stream );
49                                 parseMaskInfo( stream );
50                                
51                                 stream.position += pos + size - stream.position;
52                         }                       
53                 }
54                
55                 private function parseLayerInfo( stream:ByteArray ):void {
56                         var i:int;
57                         var size:uint = stream.readUnsignedInt();
58                         PSDParser.log("Layer Info size: " + size );
59                        
60                         var pos:int = stream.position;
61                        
62                         if ( size > 0 ) {
63                                 var numLayers:int = Math.abs( stream.readShort() );
64                                 PSDParser.log("Layer Records num: " + numLayers );
65                                
66                                 _layers = new Array( numLayers );
67                                 _pixels = new Array( numLayers );
68                                
69                                 for ( i = 0; i < numLayers; ++i ) {
70                                         PSDParser.log("\n-- layer" + i + " --");
71                                         _layers[i] = new LayerStructure( stream );
72                                 }
73                                
74                                 for ( i = 0; i < numLayers; ++i ) {
75                                         _pixels[i] = new LayerPixelData( layers[i], stream );
76                                 }
77                         } else {
78                                 _layers = [];
79                                 _pixels = [];
80                         }
81                        
82 //                      PSDParser.trace( size + " <-> " + ( stream.position - pos ) );
83                         stream.position += pos + size - stream.position;
84                 }
85                
86                 private function parseMaskInfo( stream:ByteArray ):void {
87                         PSDParser.log("\nMask Info");
88                        
89                         var size:uint = stream.readUnsignedInt();
90                         PSDParser.log("Mask Data size: " + size );
91                        
92                         var overlay:uint = stream.readUnsignedShort();
93                         var color1:uint = stream.readUnsignedInt();
94                         var color2:uint = stream.readUnsignedInt();
95                         var opacity:uint = stream.readUnsignedShort();
96                         var kind:uint = stream.readUnsignedByte();
97                        
98                         stream.position += 1; // padding
99                        
100                         PSDParser.log("overlay: " + overlay );
101                         PSDParser.log("color1: " + ("0000000" + color1.toString( 16 ) ).substr( -8 ) );
102                         PSDParser.log("color2: " + ("0000000" + color2.toString( 16 ) ).substr( -8 ) );
103                         PSDParser.log("opacity: " + opacity );
104                         PSDParser.log("kind: " + kind );
105                 }
106         }
107 }
108
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。