| 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.PStringB2; |
|---|
| 27 |
import com.voidelement.images.psd.resources.*; |
|---|
| 28 |
|
|---|
| 29 |
import flash.utils.ByteArray; |
|---|
| 30 |
import flash.utils.Dictionary; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
public class PSDImageResources { |
|---|
| 34 |
private var resources:Dictionary = new Dictionary(); |
|---|
| 35 |
|
|---|
| 36 |
public function PSDImageResources( stream:ByteArray ) { |
|---|
| 37 |
var size:uint = stream.readUnsignedInt(); |
|---|
| 38 |
var readed:uint = 0; |
|---|
| 39 |
|
|---|
| 40 |
PSDParser.log("\n\n---- PSD Image Resources Block ----"); |
|---|
| 41 |
PSDParser.log("size: " + size ); |
|---|
| 42 |
|
|---|
| 43 |
while ( readed < size ) { |
|---|
| 44 |
var type:String = stream.readUTFBytes( 4 ); |
|---|
| 45 |
if ( type != "8BIM") { |
|---|
| 46 |
throw new Error("invalid osType: " + type ); |
|---|
| 47 |
} |
|---|
| 48 |
readed += 4; |
|---|
| 49 |
|
|---|
| 50 |
var id:int = stream.readUnsignedShort(); |
|---|
| 51 |
PSDParser.log("\nid: " + ("000" + id.toString( 16 ) ).substr( -4 ) ); |
|---|
| 52 |
readed += 2; |
|---|
| 53 |
|
|---|
| 54 |
var name:PStringB2 = new PStringB2( stream ); |
|---|
| 55 |
readed += name.length; |
|---|
| 56 |
PSDParser.log("name: " + name.value ); |
|---|
| 57 |
|
|---|
| 58 |
var sizeResource:uint = stream.readUnsignedInt(); |
|---|
| 59 |
readed += 4; |
|---|
| 60 |
PSDParser.log("size: " + sizeResource ); |
|---|
| 61 |
|
|---|
| 62 |
readResource( sizeResource, id, stream ); |
|---|
| 63 |
readed += sizeResource; |
|---|
| 64 |
|
|---|
| 65 |
if ( sizeResource % 2 == 1 ) { |
|---|
| 66 |
stream.readByte(); |
|---|
| 67 |
readed++; |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
private function readResource( size:int, id:int, stream:ByteArray ):void { |
|---|
| 73 |
var current:uint = stream.position; |
|---|
| 74 |
|
|---|
| 75 |
switch ( id ) { |
|---|
| 76 |
case 0x03e8: |
|---|
| 77 |
// Photoshop v2.0 |
|---|
| 78 |
PSDParser.log("channels, rows, columns, depth, and mode"); |
|---|
| 79 |
stream.position += size; |
|---|
| 80 |
break; |
|---|
| 81 |
case 0x03e9: |
|---|
| 82 |
PSDParser.log("Optional. Macintosh print manager information"); |
|---|
| 83 |
stream.position += size; |
|---|
| 84 |
break; |
|---|
| 85 |
case 0x03eb: |
|---|
| 86 |
// Photoshop v2.0 |
|---|
| 87 |
PSDParser.log("Indexed color table"); |
|---|
| 88 |
stream.position += size; |
|---|
| 89 |
break; |
|---|
| 90 |
case 0x03ed: |
|---|
| 91 |
PSDParser.log("Resolution information"); |
|---|
| 92 |
resources[ id ] = new ResolutionInfo( stream ); |
|---|
| 93 |
// stream.position += size; |
|---|
| 94 |
break; |
|---|
| 95 |
case 0x03ee: |
|---|
| 96 |
PSDParser.log("Alpha channel names"); |
|---|
| 97 |
stream.position += size; |
|---|
| 98 |
break; |
|---|
| 99 |
case 0x03ef: |
|---|
| 100 |
PSDParser.log("Display information for each channel"); |
|---|
| 101 |
stream.position += size; |
|---|
| 102 |
break; |
|---|
| 103 |
case 0x03f0: |
|---|
| 104 |
PSDParser.log("Optional. Pascal-format caption string"); |
|---|
| 105 |
stream.position += size; |
|---|
| 106 |
break; |
|---|
| 107 |
case 0x03f1: |
|---|
| 108 |
PSDParser.log("Fixed-point border width, border units"); |
|---|
| 109 |
stream.position += size; |
|---|
| 110 |
break; |
|---|
| 111 |
case 0x03f2: |
|---|
| 112 |
// not documented |
|---|
| 113 |
PSDParser.log("Background color"); |
|---|
| 114 |
stream.position += size; |
|---|
| 115 |
break; |
|---|
| 116 |
case 0x03f3: |
|---|
| 117 |
// Print Flags |
|---|
| 118 |
PSDParser.log("Print Flags"); |
|---|
| 119 |
resources[ id ] = new PrintFlags( stream ); |
|---|
| 120 |
// stream.position += size; |
|---|
| 121 |
break; |
|---|
| 122 |
case 0x03f4: |
|---|
| 123 |
// not documented |
|---|
| 124 |
PSDParser.log("Gray-scale and halftoning information"); |
|---|
| 125 |
stream.position += size; |
|---|
| 126 |
break; |
|---|
| 127 |
case 0x03f5: |
|---|
| 128 |
// not documented |
|---|
| 129 |
PSDParser.log("Color halftoning information"); |
|---|
| 130 |
stream.position += size; |
|---|
| 131 |
break; |
|---|
| 132 |
case 0x03f6: |
|---|
| 133 |
// not documented |
|---|
| 134 |
PSDParser.log("Duotone halftoning information"); |
|---|
| 135 |
stream.position += size; |
|---|
| 136 |
break; |
|---|
| 137 |
case 0x03f7: |
|---|
| 138 |
// not documented |
|---|
| 139 |
PSDParser.log("Gray-scale and multichannel transfer function"); |
|---|
| 140 |
stream.position += size; |
|---|
| 141 |
break; |
|---|
| 142 |
case 0x03f8: |
|---|
| 143 |
// not documented |
|---|
| 144 |
PSDParser.log("Color transfer functions"); |
|---|
| 145 |
stream.position += size; |
|---|
| 146 |
break; |
|---|
| 147 |
case 0x03f9: |
|---|
| 148 |
// not documented |
|---|
| 149 |
PSDParser.log("Duotone transfer functions"); |
|---|
| 150 |
stream.position += size; |
|---|
| 151 |
break; |
|---|
| 152 |
case 0x03fa: |
|---|
| 153 |
// not documented |
|---|
| 154 |
PSDParser.log("Duotone image information"); |
|---|
| 155 |
stream.position += size; |
|---|
| 156 |
break; |
|---|
| 157 |
case 0x03fb: |
|---|
| 158 |
PSDParser.log("Effective black and white value for dot range"); |
|---|
| 159 |
stream.position += size; |
|---|
| 160 |
break; |
|---|
| 161 |
case 0x03fc: |
|---|
| 162 |
// not documented |
|---|
| 163 |
PSDParser.log("Obsolete Photoshop Tag1"); |
|---|
| 164 |
stream.position += size; |
|---|
| 165 |
break; |
|---|
| 166 |
case 0x03fd: |
|---|
| 167 |
// not documented |
|---|
| 168 |
PSDParser.log("EPS options"); |
|---|
| 169 |
stream.position += size; |
|---|
| 170 |
break; |
|---|
| 171 |
case 0x03fe: |
|---|
| 172 |
PSDParser.log("Quick Mask channel ID, flag for mask initially empty"); |
|---|
| 173 |
stream.position += size; |
|---|
| 174 |
break; |
|---|
| 175 |
case 0x03ff: |
|---|
| 176 |
PSDParser.log("Obsolete Photoshop Tag2"); |
|---|
| 177 |
stream.position += size; |
|---|
| 178 |
break; |
|---|
| 179 |
case 0x0400: |
|---|
| 180 |
PSDParser.log("Index of target layer"); |
|---|
| 181 |
PSDParser.log(" index: " + stream.readUnsignedShort() ); |
|---|
| 182 |
// stream.position += size; |
|---|
| 183 |
break; |
|---|
| 184 |
case 0x0401: |
|---|
| 185 |
PSDParser.log("Working path"); |
|---|
| 186 |
stream.position += size; |
|---|
| 187 |
break; |
|---|
| 188 |
case 0x0402: |
|---|
| 189 |
PSDParser.log("Layers group info, group ID for dragging groups"); |
|---|
| 190 |
stream.position += size; |
|---|
| 191 |
break; |
|---|
| 192 |
case 0x0403: |
|---|
| 193 |
PSDParser.log("Obsolete Photoshop Tag3"); |
|---|
| 194 |
stream.position += size; |
|---|
| 195 |
break; |
|---|
| 196 |
case 0x0404: |
|---|
| 197 |
PSDParser.log("IPTC-NAA record"); |
|---|
| 198 |
resources[ id ] = new IPTCData( stream ); |
|---|
| 199 |
// stream.position += size; |
|---|
| 200 |
break; |
|---|
| 201 |
case 0x0405: |
|---|
| 202 |
// not documented |
|---|
| 203 |
PSDParser.log("Image mode for raw-format files"); |
|---|
| 204 |
stream.position += size; |
|---|
| 205 |
break; |
|---|
| 206 |
case 0x0406: |
|---|
| 207 |
// not documented |
|---|
| 208 |
PSDParser.log("JPEG quality"); |
|---|
| 209 |
stream.position += size; |
|---|
| 210 |
break; |
|---|
| 211 |
case 0x0408: |
|---|
| 212 |
// Grid and Guides Info |
|---|
| 213 |
PSDParser.log("Grid and Guides Info"); |
|---|
| 214 |
stream.position += size; |
|---|
| 215 |
break; |
|---|
| 216 |
case 0x0409: |
|---|
| 217 |
// Photoshop BGR Thumbnail |
|---|
| 218 |
PSDParser.log("Photoshop BGR Thumbnail"); |
|---|
| 219 |
stream.position += size; |
|---|
| 220 |
break; |
|---|
| 221 |
case 0x040a: |
|---|
| 222 |
// Copyright Flag |
|---|
| 223 |
PSDParser.log("Copyright Flag"); |
|---|
| 224 |
resources[ id ] = new CopyrightFlag( stream ); |
|---|
| 225 |
// stream.position += size; |
|---|
| 226 |
break; |
|---|
| 227 |
case 0x040b: |
|---|
| 228 |
// URL |
|---|
| 229 |
PSDParser.log("URL"); |
|---|
| 230 |
stream.position += size; |
|---|
| 231 |
break; |
|---|
| 232 |
case 0x040c: |
|---|
| 233 |
// Thumbnail Resource |
|---|
| 234 |
PSDParser.log("Thumbnail Resource"); |
|---|
| 235 |
PSDParser.log(" signature: " + stream.readUnsignedInt().toString( 16 ) ); |
|---|
| 236 |
// stream.position += size; |
|---|
| 237 |
break; |
|---|
| 238 |
case 0x040d: |
|---|
| 239 |
// Global Angle |
|---|
| 240 |
PSDParser.log("Global Angle"); |
|---|
| 241 |
stream.position += size; |
|---|
| 242 |
break; |
|---|
| 243 |
case 0x040e: |
|---|
| 244 |
// Color Samplers Resource |
|---|
| 245 |
PSDParser.log("Color Samplers Resource"); |
|---|
| 246 |
stream.position += size; |
|---|
| 247 |
break; |
|---|
| 248 |
case 0x040f: |
|---|
| 249 |
// ICC Profile |
|---|
| 250 |
PSDParser.log("ICC Profile"); |
|---|
| 251 |
resources[ id ] = new ICCProfile( stream ); |
|---|
| 252 |
// stream.position += size; |
|---|
| 253 |
break; |
|---|
| 254 |
case 0x0410: |
|---|
| 255 |
// Watermark |
|---|
| 256 |
PSDParser.log("Watermark"); |
|---|
| 257 |
stream.position += size; |
|---|
| 258 |
break; |
|---|
| 259 |
case 0x0411: |
|---|
| 260 |
// ICC Untagged |
|---|
| 261 |
PSDParser.log("ICC Untagged"); |
|---|
| 262 |
stream.position += size; |
|---|
| 263 |
break; |
|---|
| 264 |
case 0x0412: |
|---|
| 265 |
// Effects Visible |
|---|
| 266 |
PSDParser.log("Effects Visible"); |
|---|
| 267 |
stream.position += size; |
|---|
| 268 |
break; |
|---|
| 269 |
case 0x0413: |
|---|
| 270 |
// Spot Halftone |
|---|
| 271 |
PSDParser.log("Spot Halftone"); |
|---|
| 272 |
stream.position += size; |
|---|
| 273 |
break; |
|---|
| 274 |
case 0x0414: |
|---|
| 275 |
// Document specific IDs |
|---|
| 276 |
PSDParser.log("Document specific IDs"); |
|---|
| 277 |
stream.position += size; |
|---|
| 278 |
break; |
|---|
| 279 |
case 0x0415: |
|---|
| 280 |
// Unicode Alpha Names |
|---|
| 281 |
PSDParser.log("Unicode Alpha Names"); |
|---|
| 282 |
stream.position += size; |
|---|
| 283 |
break; |
|---|
| 284 |
case 0x0416: |
|---|
| 285 |
// Indexed Color Table Count |
|---|
| 286 |
PSDParser.log("Indexed Color Table count"); |
|---|
| 287 |
stream.position += size; |
|---|
| 288 |
break; |
|---|
| 289 |
case 0x0417: |
|---|
| 290 |
// Transparent Index |
|---|
| 291 |
PSDParser.log("Transparent Index"); |
|---|
| 292 |
stream.position += size; |
|---|
| 293 |
break; |
|---|
| 294 |
case 0x0419: |
|---|
| 295 |
// Global Altitude |
|---|
| 296 |
PSDParser.log("Global Altitude"); |
|---|
| 297 |
stream.position += size; |
|---|
| 298 |
break; |
|---|
| 299 |
case 0x041a: |
|---|
| 300 |
PSDParser.log("Slices"); |
|---|
| 301 |
resources[ id ] = new Slices( stream ); |
|---|
| 302 |
break; |
|---|
| 303 |
case 0x041b: |
|---|
| 304 |
// Workflow URL |
|---|
| 305 |
PSDParser.log("Workflow URL"); |
|---|
| 306 |
stream.position += size; |
|---|
| 307 |
break; |
|---|
| 308 |
case 0x041c: |
|---|
| 309 |
// Jump To XPEP |
|---|
| 310 |
PSDParser.log("Jump To XPEP"); |
|---|
| 311 |
stream.position += size; |
|---|
| 312 |
break; |
|---|
| 313 |
case 0x041d: |
|---|
| 314 |
// Alpha IDs |
|---|
| 315 |
PSDParser.log("Alpha IDs"); |
|---|
| 316 |
stream.position += size; |
|---|
| 317 |
break; |
|---|
| 318 |
case 0x041e: |
|---|
| 319 |
// URL List |
|---|
| 320 |
PSDParser.log("URL List"); |
|---|
| 321 |
stream.position += size; |
|---|
| 322 |
break; |
|---|
| 323 |
case 0x0421: |
|---|
| 324 |
// Version Info |
|---|
| 325 |
PSDParser.log("Version Info"); |
|---|
| 326 |
stream.position += size; |
|---|
| 327 |
break; |
|---|
| 328 |
case 0x0422: |
|---|
| 329 |
// EXIF Info |
|---|
| 330 |
PSDParser.log("EXIF Info"); |
|---|
| 331 |
stream.position += size; |
|---|
| 332 |
break; |
|---|
| 333 |
case 0x0424: |
|---|
| 334 |
// XMP |
|---|
| 335 |
PSDParser.log("XMP"); |
|---|
| 336 |
stream.position += size; |
|---|
| 337 |
break; |
|---|
| 338 |
case 0x0bb7: |
|---|
| 339 |
// not documented |
|---|
| 340 |
PSDParser.log("Clipping pathname"); |
|---|
| 341 |
stream.position += size; |
|---|
| 342 |
break; |
|---|
| 343 |
case 0x2710: |
|---|
| 344 |
// Print Flags Info |
|---|
| 345 |
PSDParser.log("Print flags Info"); |
|---|
| 346 |
resources[ id ] = new PrintFlagsInfo( stream ); |
|---|
| 347 |
// stream.position += size; |
|---|
| 348 |
break; |
|---|
| 349 |
default: |
|---|
| 350 |
if ( ( 0x07d0 <= id ) && ( id <= 0x0bb6 ) ) { |
|---|
| 351 |
PSDParser.log("Saved path information: " + ("000" + id.toString( 16 ) ).substr( -4 ) ); |
|---|
| 352 |
resources[ id ] = new PathInfo( stream ); |
|---|
| 353 |
} else { |
|---|
| 354 |
PSDParser.log("Unknown: " + ("000" + id.toString( 16 ) ).substr( -4 ) ); |
|---|
| 355 |
stream.position += size; |
|---|
| 356 |
} |
|---|
| 357 |
} |
|---|
| 358 |
|
|---|
| 359 |
stream.position += current + size - stream.position; |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
public function getResource( type:int ):Object { |
|---|
| 363 |
return resources[ type ]; |
|---|
| 364 |
} |
|---|
| 365 |
} |
|---|
| 366 |
} |
|---|