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

リビジョン 97, 3.0 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        
27         import flash.utils.ByteArray;
28        
29         public class PSDFileHeader {
30                 private static const FILE_ID:String = "8BPS";
31                
32                 private static const MODE_BITMAP:int = 0;
33                 private static const MODE_GRAYSCALE:int = 1;
34                 private static const MODE_INDEXED:int = 2;
35                 private static const MODE_RGB:int = 3;
36                 private static const MODE_CMYK:int = 4;
37                 private static const MODE_MULTICHANNEL:int = 5;
38                 private static const MODE_DUOTONE:int = 6;
39                 private static const MODE_LAB:int = 7;
40                
41                                
42                 // File ID "8BPS"
43                 private var _signature:String;
44                 public function get signature():String { return _signature; }
45                
46                 // Version number, always 1
47                 private var _version:int;
48                 public function get version():int { return _version; }
49                
50                 // Number of color channels ( 1 - 24 )
51                 private var _channel:int;
52                 public function get channel():int { return _channel; }
53                
54                 // Height of image in pixels ( 1 - 30000 )
55                 private var _rows:int;
56                 public function get rows():int { return _rows; }
57                
58                 // Width of image in pixels ( 1 - 30000 )
59                 private var _columns:int;
60                 public function get columns():int { return _columns; }
61                
62                 // Number of bits per channel
63                 private var _depth:int;
64                 public function get depth():int { return _depth; }
65                
66                 // Color mode
67                 private var _mode:int;
68                 public function get mode():int { return _mode; }
69                
70                
71                 public function PSDFileHeader( stream:ByteArray ) {
72                         _signature = stream.readUTFBytes( 4 );
73                        
74                         if ( signature != FILE_ID ) {
75                                 throw new Error("invalid signature: " + signature );
76                         }
77                        
78                         _version = stream.readUnsignedShort();
79                        
80                         // Reserved, must be zeroed
81                         stream.position += 6;
82                        
83                         _channel = stream.readUnsignedShort();
84                         _rows = stream.readInt();
85                         _columns = stream.readInt();
86                         _depth = stream.readUnsignedShort();
87                         _mode = stream.readUnsignedShort();
88                        
89                         PSDParser.log("---- PSD HEADER ----");
90                         PSDParser.log("version: " + version );
91                         PSDParser.log("channnel: " + channel );
92                         PSDParser.log("rows: " + rows );
93                         PSDParser.log("columns: " + columns );
94                         PSDParser.log("depth: " + depth );
95                         PSDParser.log("mode: " + mode );
96                 }
97         }
98 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。