1 /** 2 * libpsd - Photoshop file formats (*.psd) decode library 3 * Copyright (C) 2004-2007 Graphest Software. 4 * 5 * libpsd is the legal property of its developers, whose names are too numerous 6 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * source distribution. 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU Library General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * 23 * $Id: libpsd.h, created by Patrick in 2006.05.18, libpsd@graphest.com Exp $ 24 */ 25 module psd; 26 27 public import psd.types; 28 29 extern(C): 30 31 // global status 32 enum psd_status { 33 done = 0, 34 invalid_context = -1, 35 invalid_file = -2, 36 unkown_error = -3, 37 malloc_failed = -4, 38 fread_error = -5, 39 unsupport_yet = -6, 40 file_header_error = -10, 41 color_mode_data_error = -11, 42 image_resource_error = -12, 43 layer_and_mask_error = -13, 44 image_data_error = -14, 45 unsupport_color_space = -15, 46 //donot_support_multichannel = -16, 47 //donot_support_duotone = -17, 48 unsupport_color_depth = -18, 49 unknown_color_mode = -19, 50 unsupport_image_compression = -20, 51 invalid_layer = -21, 52 invalid_adjustment_layer = -22, 53 invalid_layer_effects = -23, 54 invalid_bitmap = -50, 55 bitmap_dismatch_size = -51, 56 invalid_layer_mask_info = -52, 57 invalid_range = -53, 58 invalid_gradient_color = -54, 59 invalid_rect = -55, 60 invalid_blending_channels = -56, 61 blend_empty_rect = -100, 62 unzip_error = -101, 63 file_signature_error = -200, 64 file_version_error = -201, 65 resource_signature_error = -400, 66 thumbnail_decode_error = -401, 67 blend_mode_signature_error = -500, 68 unsupport_blend_mode = -501, 69 additional_layer_signature_error = -502, 70 levels_unsupport_version = -503, 71 unsupport_layer_type = -504, 72 extra_levels_key_error = -505, 73 levels_dismatch_data_length = -506, 74 extra_levels_unsupport_version = -507, 75 curves_unsupport_version = -508, 76 extra_curves_key_error = -509, 77 extra_curves_unsupport_version = -510, 78 hue_saturation_unsupport_version = -511, 79 selective_color_unsupport_version= -512, 80 channel_mixer_unsupport_version = -513, 81 photo_filter_unsupport_version = -514, 82 gradient_map_unsupport_version = -515, 83 effects_unsupport_version = -516, 84 effects_signature_error = -517, 85 unsupport_effects_type = -518, 86 common_state_unsupport_version = -519, 87 shadow_unsupport_version = -520, 88 outer_glow_unsupport_version = -521, 89 inner_glow_unsupport_version = -522, 90 bevel_unsupport_version = -523, 91 solid_fill_unsupport_version = -524, 92 solid_color_unsupport_version = -525, 93 gradient_fill_unsupport_version = -526, 94 layer_information_signature_error= -528, 95 divider_signature_error = -529, 96 pattern_fill_unsupport_version = -530, 97 pattern_unsupport_version = -531, 98 invalid_image_dimension = -532, 99 } 100 101 enum psd_load_tag { 102 all, 103 header, 104 layer, 105 merged, 106 thumbnail, 107 metadata, 108 exif = metadata 109 } 110 111 // color mode 112 enum psd_color_mode { 113 bitmap = 0, 114 grayscale = 1, 115 indexed = 2, 116 rgb = 3, 117 cmyk = 4, 118 multichannel = 7, 119 duotone = 8, 120 lab = 9 121 } 122 123 // color space 124 enum psd_color_space { 125 dummy = -1, 126 rgb, 127 hsb, 128 cmyk, 129 pantone, 130 focoltone, 131 trumatch, 132 toyo, 133 lab, 134 gray, 135 wide_cmyk, 136 hks, 137 dic, 138 total_ink, 139 monitor_rgb, 140 duotone, 141 opacity 142 } 143 144 enum psd_layer_type { 145 normal, 146 hidden, 147 folder, 148 solid_color, 149 gradient_fill, 150 pattern_fill, 151 levels, 152 curves, 153 brightness_contrast, 154 color_balance, 155 hue_saturation, 156 selective_color, 157 threshold, 158 invert, 159 posterize, 160 channel_mixer, 161 gradient_map, 162 photo_filter, 163 } 164 165 // blend mode key 166 enum psd_blend_mode { 167 normal, // 'norm' = normal 168 dissolve, // 'diss' = dissolve 169 darken, // 'dark' = darken 170 multiply, // 'mul ' = multiply 171 color_burn, // 'idiv' = color burn 172 linear_burn, // 'lbrn' = linear burn 173 lighten, // 'lite' = lighten 174 screen, // 'scrn' = screen 175 color_dodge, // 'div ' = color dodge 176 linear_dodge, // 'lddg' = linear dodge 177 overlay, // 'over' = overlay 178 soft_light, // 'sLit' = soft light 179 hard_light, // 'hLit' = hard light 180 vivid_light, // 'vLit' = vivid light 181 linear_light, // 'lLit' = linear light 182 pin_light, // 'pLit' = pin light 183 hard_mix, // 'hMix' = hard mix 184 difference, // 'diff' = difference 185 exclusion, // 'smud' = exclusion 186 hue, // 'hue ' = hue 187 saturation, // 'sat ' = saturation 188 color, // 'colr' = color 189 luminosity, // 'lum ' = luminosity 190 pass_through, // 'pass' = pass 191 darker_color, // 'dkCl' = darker color 192 lighter_color, // 'lgCl' = lighter color 193 subtract, // 'fsub' = subtract 194 divide, // 'fdiv' = divide 195 } 196 197 // There are several types of layer information that have been added in Photoshop 4.0 198 // and later. These exist at the end of the layer records structure 199 enum psd_layer_info_type { 200 normal, 201 levels, // 'levl' = Levels 202 curves, // 'curv' = Curves 203 brightness_contrast,// 'brit' = Brightness/contrast 204 color_balance, // 'blnc' = Color balance 205 //old_hue_saturation,// 'hue ' = Old Hue/saturation, Photoshop 4.0 206 new_hue_saturation, // 'hue2' = New Hue/saturation, Photoshop 5.0 207 selective_color, // 'selc' = Selective color 208 threshold, // 'thrs' = Threshold 209 invert, // 'nvrt' = Invert 210 posterize, // 'post' = Posterize 211 channel_mixer, // Key is 'mixr'. 212 gradient_map, // Key is 'grdm'. 213 photo_filter, // Key is 'phfl'. 214 type_tool, // 'tySh'. Type Tool Info (Photoshop 5.0 and 5.5 only) 215 type_tool_object, // 'TySh'. Type tool object setting (Photoshop 6.0) 216 effects, // Effects Layer (Photoshop 5.0). The key for the effects layer is 'lrFX'. 217 effects2, // 'lfx2', Photoshop 6.0 218 solid_color, // Key is 'SoCo' 219 gradient_fill, // Key is 'GdFl' 220 pattern_fill, // Key is 'PtFl' 221 } 222 enum psd_layer_info_type_count = psd_layer_info_type.max + 1; 223 224 enum psd_gradient_style { 225 linear, // 'Lnr ' 226 radial, // 'Rdl ' 227 angle, // 'Angl' 228 reflected, // 'Rflc' 229 diamond // 'Dmnd' 230 } 231 232 enum psd_color_stop_type { 233 foreground_color, // 'FrgC' 234 background_Color, // 'BckC' 235 user_stop // 'UsrS' 236 } 237 238 enum psd_layer_effects_type { 239 drop_shadow, 240 inner_shadow, 241 outer_glow, 242 inner_glow, 243 satin, 244 color_overlay, 245 gradient_overlay, 246 pattern_overlay, 247 stroke, 248 bevel_emboss, 249 } 250 enum psd_layer_effects_type_count = psd_layer_effects_type.max + 1; 251 252 enum psd_layer_effects_bevel_emboss_type { 253 outer_shadow = cast(int)psd_layer_effects_type.bevel_emboss, 254 outer_light, 255 inner_shadow, 256 inner_light, 257 texture 258 } 259 enum psd_layer_effects_image_count = psd_layer_effects_bevel_emboss_type.max + 1; 260 261 enum psd_technique_type { 262 softer, 263 precise, 264 slope_limit, 265 } 266 267 enum psd_stroke_position { 268 outside, 269 inside, 270 center 271 } 272 273 enum psd_fill_type { 274 solid_color, 275 gradient, 276 pattern, 277 } 278 279 enum psd_glow_source { 280 center, 281 edge, 282 } 283 284 enum psd_bevel_style { 285 outer_bevel, 286 inner_bevel, 287 emboss, 288 pillow_emboss, 289 stroke_emboss, 290 } 291 292 enum psd_direction { 293 up, 294 down 295 } 296 297 enum psd_units { 298 inches = 1, 299 cm = 2, 300 points = 3, 301 picas = 4, 302 columns = 5, 303 } 304 305 enum psd_print_style { 306 centered = 0, 307 size_to_fit = 1, 308 user_defined = 2, 309 } 310 311 struct psd_stream { 312 psd_uchar * buffer; 313 long read_in_length; 314 long read_out_length; 315 long file_length; 316 long current_pos; 317 } 318 319 320 /*********************************************************************************/ 321 /*********************************************************************************/ 322 // image resources section 323 324 // This structure contains information about the resolution of an image. It is 325 // written as an image resource. See the Document file formats chapter for more 326 // details. 327 struct psd_resolution_info { 328 psd_float hres; // Horizontal resolution in pixels per inch. 329 psd_short hres_unit; // 1=display horitzontal resolution in pixels per inch; 2=display horitzontal resolution in pixels per cm. 330 psd_short width_unit; // Display width as 1=inches; 2=cm; 3=points; 4=picas; 5=columns. 331 psd_float vres; // Vertial resolution in pixels per inch. 332 psd_short vres_unit; // 1=display vertical resolution in pixels per inch; 2=display vertical resolution in pixels per cm. 333 psd_short height_unit; // Display height as 1=inches; 2=cm; 3=points; 4=picas; 5=columns. 334 } 335 336 // This structure contains display information about each channel. It is written 337 // as an image resource. 338 struct psd_display_info { 339 psd_argb_color color; 340 psd_short opacity; // 0..100 341 psd_uchar kind; // selected = 0, protected = 1 342 } 343 344 struct psd_alpha_channel_info { 345 psd_char[256] name; 346 psd_int unicode_name_length; 347 psd_ushort * unicode_name; 348 psd_int identifier; 349 psd_uchar * channel_data; 350 } 351 352 // Grid and guides information 353 // Photoshop stores grid and guides information for an image in an image resource 354 // block. Each of these resource blocks consists of an initial 16-byte grid and guide 355 // header, which is always present, followed by 5-byte blocks of specific guide 356 // information for guide direction and location, which are present if there are guides 357 struct psd_grid_guides { 358 psd_int horz_grid; // Future implementation of document-specific grids (4 bytes horizontal, 4 bytes vertical). 359 psd_int vert_grid; 360 psd_int guide_count; // Number of guide resource blocks (can be 0). 361 psd_int * guide_coordinate;//Location of guide in document coordinates. Since the guide is either vertical or horizontal, this only has to be one component of the coordinate. 362 psd_uchar * guide_direction;// Direction of guide. VHSelect is a system type of psd_uchar where 0 = vertical, 1 = horizontal. 363 } 364 365 // Thumbnail resource format 366 // Adobe Photoshop (version 5.0 and later) stores thumbnail information for preview 367 // display in an image resource block that consists of an initial 28-byte header, followed 368 // by a JFIF thumbnail in RGB (red, green, blue) order for both Macintosh and Windows. 369 struct psd_thumbnail_resource { 370 psd_int format; // 1 = kJpegRGB . Also supports kRawRGB (0). 371 psd_int width; // Width of thumbnail in pixels. 372 psd_int height; // Height of thumbnail in pixels. 373 psd_int width_bytes; // Padded row bytes = (width * bits per pixel + 31) / 32 * 4. 374 psd_int total_size; // Total size = widthbytes * height * planes 375 psd_int size_after_compression;// Used for consistency check. 376 psd_short bits_per_pixel; // 24 377 psd_short number_of_planes;// 1 378 psd_uchar * jfif_data; 379 psd_argb_color * thumbnail_data; 380 } 381 382 // (Photoshop 6.0) Version Info 383 // 4 bytes version, 1 byte hasRealMergedData, Unicode string: writer 384 // name, Unicode string: reader name, 4 bytes file version. 385 struct psd_version_info { 386 psd_uint version_; 387 psd_bool has_real_merged_data; 388 psd_int writer_name_length; 389 psd_ushort * writer_name; 390 psd_int reader_name_length; 391 psd_ushort * reader_name; 392 psd_uint file_version; 393 } 394 395 // Slices resource block 396 struct psd_slices_resource_block { 397 psd_int id; 398 psd_int group_id; 399 psd_int origin; 400 psd_int associated_layer_id;// NOTE: Only present if Origin = 1 401 psd_int type; 402 psd_int left; 403 psd_int top; 404 psd_int right; 405 psd_int bottom; 406 psd_bool cell_text_is_html; 407 psd_int horizontal_alignment; 408 psd_int veritcal_alignment; 409 psd_argb_color color; 410 } 411 412 // Slices resource format 413 // Adobe Photoshop 6.0 and later stores slices information for an image in an image 414 // resource block. . 415 struct psd_slices_resource { 416 psd_int bounding_top; // Bounding rectangle for all of the slices: top, left, bottom, right of all the slices 417 psd_int bounding_left; 418 psd_int bounding_bottom; 419 psd_int bounding_right; 420 psd_int number_of_slices;// Number of slices to follow. See Slices resource block in the next table. 421 psd_slices_resource_block * slices_resource_block; 422 } 423 424 // Border information 425 // Contains , and 426 struct psd_border_info { 427 psd_float border_width; // fixed number (2 bytes real, 2 bytes fraction) for the border width 428 psd_units border_units; // border units (1 = inches, 2 = cm, 3 = points, 4 = picas, 5 = columns). 429 } 430 431 // Print flags 432 // A series of one-byte boolean values (see Page Setup dialog) 433 struct psd_print_flags { 434 psd_bool labels; 435 psd_bool crop_marks; 436 psd_bool color_bars; 437 psd_bool registration_marks; 438 psd_bool negative; 439 psd_bool flip; 440 psd_bool interpolate; 441 psd_bool caption; 442 psd_bool print_flags; 443 } 444 445 // (Photoshop 7.0) Print scale 446 struct psd_print_scale { 447 psd_print_style style; // style (0 = centered, 1 = size to fit, 2 = user defined). 448 psd_float x_location; // x location (floating point). 449 psd_float y_location; // y location (floating point). 450 psd_float scale; // scale (floating point) 451 } 452 453 // Print flags information 454 struct psd_print_flags_info { 455 psd_bool center_crop; // center crop marks 456 psd_int value; // bleed width value 457 psd_short scale; // bleed width scale 458 } 459 460 461 // (Photoshop 6.0) URL List 462 struct psd_url_list_item { 463 psd_uint tag; 464 psd_uint ID; 465 psd_int name_length; 466 psd_ushort * name; 467 } 468 469 struct psd_url_list { 470 psd_int number_of_urls; // count of URLs 471 psd_url_list_item * items; 472 } 473 474 475 // Color samplers resource format 476 struct psd_color_samplers_resource { 477 psd_int vertical_position; // The vertical position of the point 478 psd_int horizontal_position; // The horizontal position of the point 479 psd_color_space color_space; 480 } 481 482 struct psd_color_samplers { 483 psd_int number_of_color_samplers; // Number of color samplers to follow. 484 psd_color_samplers_resource *resource; 485 } 486 487 488 // Path resource format 489 struct psd_bezier_point { 490 psd_bool linked; 491 psd_float preceding_control_vertical; 492 psd_float preceding_control_horizontal; 493 psd_float anchor_point_vertical; 494 psd_float anchor_point_horizontal; 495 psd_float leaving_control_vertical; 496 psd_float leaving_control_horizontal; 497 } 498 499 struct psd_subpath { 500 psd_bool closed; 501 psd_int number_of_points; 502 psd_bezier_point * bezier_points; 503 } 504 505 struct psd_path { 506 psd_int number_of_subpaths; 507 psd_subpath * subpaths; 508 psd_float clipboard_top; 509 psd_float clipboard_left; 510 psd_float clipboard_bottom; 511 psd_float clipboard_right; 512 psd_float resolution; 513 psd_bool initial_fill; 514 } 515 516 517 // end of image resources section 518 /*********************************************************************************/ 519 /*********************************************************************************/ 520 521 522 /*********************************************************************************/ 523 /*********************************************************************************/ 524 // layer and mask information section 525 526 // Channel information, Six bytes per channel 527 struct psd_channel_info { 528 psd_short channel_id; // 2 bytes for Channel ID: 0 = red, 1 = green, etc.; -1 = transparency mask; -2 = user supplied layer mask 529 long data_length; // 4 bytes for length of corresponding channel data. (**PSB** 8 bytes for length of corresponding channel data.) 530 psd_bool restricted; 531 } 532 533 // Layer mask data. Can be 40 bytes, 24 bytes, or 4 bytes if no layer mask. 534 struct psd_layer_mask_info { 535 psd_int top; // Rectangle enclosing layer mask: Top, left, bottom, right 536 psd_int left; 537 psd_int bottom; 538 psd_int right; 539 psd_int width; 540 psd_int height; 541 psd_color_component default_color; // 0 or 255 542 psd_bool relative; // position relative to layer 543 psd_bool disabled; // layer mask disabled 544 psd_bool invert; // invert layer mask when blending 545 psd_color_component * mask_data; 546 } 547 548 // Layer blending ranges 549 struct psd_layer_blending_ranges { 550 psd_ushort gray_black_src; // Composite gray blend source. Contains 2 black values followed by 2 white values. Present but irrelevant for Lab & Grayscale. 551 psd_ushort gray_white_src; 552 psd_ushort gray_black_dst; // Composite gray blend destination range 553 psd_ushort gray_white_dst; 554 psd_int number_of_blending_channels; 555 psd_ushort * channel_black_src;// channel source range 556 psd_ushort * channel_white_src; 557 psd_ushort * channel_black_dst;// First channel destination range 558 psd_ushort * channel_white_dst; 559 } 560 561 // Vector mask setting (Photoshop 6.0) 562 struct psd_layer_vector_mask { 563 psd_path * path; 564 psd_bool invert; // Flags. bit 1 = invert, bit 2 = not link, bit 3 = disable 565 psd_bool not_link; 566 psd_bool disable; 567 } 568 569 // Information about each layer 570 struct psd_layer_record { 571 psd_layer_type layer_type; 572 psd_int top; // Rectangle containing the contents of the layer. Specified as top, left, bottom, right coordinates 573 psd_int left; 574 psd_int bottom; 575 psd_int right; 576 psd_int width; 577 psd_int height; 578 psd_short number_of_channels; // Number of channels in the layer, including any alpha channels. Supported range is 1 to 56. 579 psd_channel_info * channel_info; //Channel information 580 psd_blend_mode blend_mode; // Blend mode key 581 psd_uchar opacity; // 0 = transparent ... 255 = opaque 582 psd_bool clipping; // 0 = base, 1 = non-base 583 psd_bool transparency_protected; 584 psd_bool visible; 585 psd_bool obsolete; 586 psd_bool pixel_data_irrelevant;// bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful information; bit 4 = pixel data irrelevant to appearance of document 587 psd_layer_mask_info layer_mask_info; // Layer mask data 588 psd_layer_blending_ranges layer_blending_ranges; 589 psd_uchar[256] layer_name; // Pascal string, padded to a multiple of 4 bytes. 590 psd_layer_vector_mask vector_mask; 591 592 psd_argb_color * image_data; 593 594 psd_int layer_info_count; 595 psd_layer_info_type[psd_layer_info_type_count] layer_info_type; 596 void*[psd_layer_info_type_count] layer_info_data; 597 psd_bool adjustment_valid; 598 599 psd_uchar fill_opacity; 600 psd_int unicode_name_length; 601 psd_ushort * unicode_name; 602 psd_uint layer_name_id; 603 psd_int layer_id; 604 psd_int layer_version; 605 psd_bool blend_clipped; 606 psd_bool blend_interior; 607 psd_bool knockout; 608 psd_bool transparency; 609 psd_bool composite; 610 psd_bool position_respectively; 611 psd_argb_color sheet_color; 612 psd_int reference_point_x; 613 psd_int reference_point_y; 614 psd_bool transparency_shapes_layer; 615 psd_bool layer_mask_hides_effects; 616 psd_bool vector_mask_hides_effects; 617 psd_int divider_type; 618 psd_blend_mode divider_blend_mode; 619 620 psd_layer_record * group_layer; 621 } 622 623 // Global layer mask info 624 struct psd_global_layer_mask { 625 psd_argb_color color; 626 psd_short opacity; 627 psd_uchar kind; 628 } 629 630 // end of layer and mask information section 631 /*********************************************************************************/ 632 /*********************************************************************************/ 633 634 635 /*********************************************************************************/ 636 /*********************************************************************************/ 637 // additional layer information 638 639 // LEVELS 640 // Level record 641 struct psd_layer_level_record { 642 psd_ushort input_floor; // (0...253) 643 psd_ushort input_ceiling; // (2...255) 644 psd_ushort output_floor; // 255). Matched to input floor. 645 psd_ushort output_ceiling; // (0...255) 646 psd_float gamma; // Short integer from 10...999 representing 0.1...9.99. Applied to all image data. 647 } 648 649 // Levels settings files are loaded and saved in the Levels dialog. 650 struct psd_layer_levels { 651 psd_layer_level_record[29] record; // 29 sets of level records, each level containing 5 psd_short integers 652 // Photoshop CS (8.0) Additional information 653 // At the end of the Version 2 file is the following information: 654 psd_ushort extra_level_count; // Count of total level record structures. Subtract the legacy number of level record structures, 29, to determine how many are remaining in the file for reading. 655 psd_layer_level_record * extra_record; // Additianol level records according to count 656 psd_uchar[256][3] lookup_table; 657 } 658 659 660 // CURVES 661 // The following is the data for each curve specified by count above 662 struct psd_layer_curves_data { 663 psd_ushort channel_index; // Before each curve is a channel index. 664 psd_ushort point_count; // Count of points in the curve (psd_short integer from 2...19) 665 psd_ushort[19] output_value; // All coordinates have range 0 to 255 666 psd_ushort[19] input_value; 667 } 668 669 // Curves file format 670 struct psd_layer_curves { 671 psd_ushort curve_count; // Count of curves in the file. 672 psd_layer_curves_data * curve; 673 psd_uchar[256][3] lookup_table; 674 } 675 676 677 // BRIGHTNESS AND CONTRAST 678 struct psd_layer_brightness_contrast { 679 psd_short brightness; 680 psd_short contrast; 681 psd_short mean_value; // for brightness and contrast 682 psd_char Lab_color; 683 psd_uchar[256] lookup_table; 684 } 685 686 687 // COLOR BALANCE 688 struct psd_layer_color_balance { 689 psd_short[3] cyan_red; // (-100...100). shadows, midtones, highlights 690 psd_short[3] magenta_green; 691 psd_short[3] yellow_blue; 692 psd_bool preserve_luminosity; 693 psd_uchar[256][3] lookup_table; 694 } 695 696 697 // HUE/SATURATION 698 // Hue/Saturation settings files are loaded and saved in Photoshop's Hue/Saturation dialog 699 struct psd_layer_hue_saturation { 700 psd_uchar hue_or_colorization; // 0 = Use settings for hue-adjustment; 1 = Use settings for colorization. 701 psd_short colorization_hue; // Photoshop 5.0: The actual values are stored for the new version. Hue is - 180...180, Saturation is 0...100, and Lightness is -100...100. 702 psd_short colorization_saturation;// Photoshop 4.0: Three psd_short integers Hue, Saturation, and Lightness from -100...100. 703 psd_short colorization_lightness; // The user interface represents hue as -180...180, saturation as 0...100, and Lightness as -100...1000, as the traditional HSB color wheel, with red = 0. 704 psd_short master_hue; // Master hue, saturation and lightness values. 705 psd_short master_saturation; 706 psd_short master_lightness; 707 psd_short[4][6] range_values; // For RGB and CMYK, those values apply to each of the six hextants in the HSB color wheel: those image pixels nearest to red, yellow, green, cyan, blue, or magenta. These numbers appear in the user interface from -60...60, however the slider will reflect each of the possible 201 values from -100...100. 708 psd_short[3][6] setting_values; // For Lab, the first four of the six values are applied to image pixels in the four Lab color quadrants, yellow, green, blue, and magenta. The other two values are ignored ( = 0). The values appear in the user interface from -90 to 90. 709 psd_uchar[360] lookup_table; 710 } 711 712 713 // SELECTIVE COLOR 714 // Selective Color settings files are loaded and saved in Photoshop's Selective Color dialog. 715 struct psd_layer_selective_color { 716 psd_ushort correction_method; // 0 = Apply color correction in relative mode; 1 = Apply color correction in absolute mode. 717 psd_short[10] cyan_correction; // Amount of cyan correction. Short integer from -100...100. 718 psd_short[10] magenta_correction; // Amount of magenta correction. Short integer from -100...100. 719 psd_short[10] yellow_correction; // Amount of yellow correction. Short integer from -100...100. 720 psd_short black_correction; // Amount of black correction. Short integer from -100...100. 721 } 722 723 724 // THRESHOLD 725 struct psd_layer_threshold { 726 psd_ushort level; // (1...255) 727 } 728 729 730 // INVERT 731 // no parameter 732 733 734 // POSTERIZE 735 struct psd_layer_posterize { 736 psd_ushort levels; // (2...255) 737 psd_uchar[256] lookup_table; 738 } 739 740 741 // CHANNEL MIXER 742 struct psd_layer_channel_mixer { 743 psd_bool monochrome; 744 psd_short[4] red_cyan; // RGB or CMYK color plus constant for the mixer settings. 4 * 2 bytes of color with 2 bytes of constant. 745 psd_short[4] green_magenta; // (-200...200) 746 psd_short[4] blue_yellow; 747 psd_short[4] black; 748 psd_short[4] constant; 749 } 750 751 752 // GRADIENT MAP 753 // Each color stop 754 struct psd_gradient_color_stop { 755 psd_int location; // Location of color stop 756 psd_int midpoint; // Midpoint of color stop 757 psd_argb_color actual_color; 758 psd_color_stop_type color_stop_type; 759 } 760 761 // Each transparency stop 762 struct psd_gradient_transparency_stop { 763 psd_int location; // Location of transparency stop 764 psd_int midpoint; // Midpoint of transparency stop 765 psd_short opacity; // Opacity of transparency stop 766 } 767 768 // Gradient settings (Photoshop 6.0) 769 struct psd_layer_gradient_map { 770 psd_bool reverse; // Is gradient reverse 771 psd_bool dithered; // Is gradient dithered 772 psd_int name_length; 773 psd_ushort * name; // Name of the gradient: Unicode string, padded 774 psd_short number_color_stops; // Number of color stops to follow 775 psd_gradient_color_stop * color_stop; 776 psd_short number_transparency_stops;// Number of transparency stops to follow 777 psd_gradient_transparency_stop * transparency_stop; 778 psd_short expansion_count; // Expansion count ( = 2 for Photoshop 6.0) 779 psd_short interpolation; // Interpolation if length above is non-zero 780 psd_short length; // Length (= 32 for Photoshop 6.0) 781 psd_short mode; // Mode for this gradient 782 psd_int random_number_seed; // Random number seed 783 psd_short showing_transparency_flag;// Flag for showing transparency 784 psd_short using_vector_color_flag;// Flag for using vector color 785 psd_int roughness_factor; // Roughness factor 786 psd_argb_color min_color; 787 psd_argb_color max_color; 788 psd_argb_color[256] lookup_table; 789 } 790 791 792 // PHOTO FILTER 793 struct psd_layer_photo_filter { 794 psd_int x_color; // 4 bytes each for XYZ color 795 psd_int y_color; 796 psd_int z_color; 797 psd_int density; // (1...100) 798 psd_bool preserve_luminosity; 799 } 800 801 802 // EFFECTS 803 804 struct psd_gradient_color { 805 psd_int smoothness; 806 psd_int name_length; 807 psd_ushort * name; // Name of the gradient: Unicode string, padded 808 psd_short number_color_stops; // Number of color stops to follow 809 psd_gradient_color_stop * color_stop; 810 psd_short number_transparency_stops;// Number of transparency stops to follow 811 psd_gradient_transparency_stop *transparency_stop; 812 } 813 814 struct psd_pattern { 815 psd_color_mode color_mode; // The image mode of the file. 816 psd_short height; // Point: vertical, 2 bytes and horizontal, 2 bytes 817 psd_short width; 818 psd_int name_length; // Name: Unicode string 819 psd_ushort * name; 820 psd_uchar[256] unique_id; // Unique ID for this pattern: Pascal string 821 psd_int version_; 822 psd_short top; // Rectangle: top, left, bottom, right 823 psd_short left; 824 psd_short bottom; 825 psd_short right; 826 psd_int max_channel; // Max channels 827 psd_int channel_number; 828 psd_argb_color * image_data; 829 } 830 831 // Effects layer, drop shadow and inner shadow info 832 struct psd_layer_effects_drop_shadow { 833 psd_bool effect_enable; // Effect enabled 834 835 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 836 psd_argb_color color; 837 psd_argb_color native_color; 838 psd_uchar opacity; // Opacity as a percent 839 psd_int angle; // Angle in degrees 840 psd_bool use_global_light; // Use this angle in all of the layer effects 841 psd_int distance; // Distance in pixels 842 psd_int spread; // Intensity as a percent 843 psd_int size; // Blur value in pixels 844 845 psd_uchar[256] contour_lookup_table; 846 psd_bool anti_aliased; 847 psd_int noise; 848 psd_bool knocks_out; 849 } 850 851 struct psd_layer_effects_inner_shadow { 852 psd_bool effect_enable; // Effect enabled 853 854 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 855 psd_argb_color color; 856 psd_argb_color native_color; 857 psd_uchar opacity; // Opacity as a percent 858 psd_int angle; // Angle in degrees 859 psd_bool use_global_light; // Use this angle in all of the layer effects 860 psd_int distance; // Distance in pixels 861 psd_int choke; // Intensity as a percent 862 psd_int size; // Blur value in pixels 863 864 psd_uchar[256] contour_lookup_table; 865 psd_bool anti_aliased; 866 psd_int noise; 867 } 868 869 // Effects layer, outer glow info 870 struct psd_layer_effects_outer_glow { 871 psd_bool effect_enable; // Effect enabled 872 873 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 874 psd_uchar opacity; // Opacity as a percent 875 psd_int noise; 876 psd_fill_type fill_type; 877 psd_argb_color color; 878 psd_argb_color native_color; 879 psd_gradient_color gradient_color; 880 881 psd_technique_type technique; 882 psd_int spread; 883 psd_int size; 884 885 psd_uchar[256] contour_lookup_table; 886 psd_bool anti_aliased; 887 psd_int range; 888 psd_int jitter; 889 } 890 891 // Effects layer, inner glow info 892 struct psd_layer_effects_inner_glow { 893 psd_bool effect_enable; // Effect enabled 894 895 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 896 psd_uchar opacity; // Opacity as a percent 897 psd_int noise; 898 psd_fill_type fill_type; 899 psd_argb_color color; 900 psd_argb_color native_color; 901 psd_gradient_color gradient_color; 902 903 psd_technique_type technique; 904 psd_glow_source source; 905 psd_int choke; 906 psd_int size; 907 908 psd_uchar[256] contour_lookup_table; 909 psd_bool anti_aliased; 910 psd_int range; 911 psd_int jitter; 912 } 913 914 struct psd_pattern_info { 915 psd_int name_length; 916 psd_ushort * name; 917 psd_uchar[256] identifier; 918 } 919 920 // Effects layer, bevel info 921 struct psd_layer_effects_bevel_emboss { 922 psd_bool effect_enable; // Effect enabled 923 924 psd_bevel_style style; // Bevel style 925 psd_technique_type technique; 926 psd_int depth; 927 psd_direction direction; // Up or down 928 psd_int size; // Strength. Depth in pixels 929 psd_int soften; // Blur value in pixels. 930 931 psd_int angle; // Angle in degrees 932 psd_bool use_global_light; // Use this angle in all of the layer effects 933 psd_int altitude; 934 psd_uchar[256] gloss_contour_lookup_table; 935 psd_bool gloss_anti_aliased; 936 psd_blend_mode highlight_blend_mode; // Highlight blend mode: 4 bytes for signature and 4 bytes for the key 937 psd_argb_color highlight_color; 938 psd_argb_color real_highlight_color; 939 psd_uchar highlight_opacity; // Hightlight opacity as a percent 940 psd_blend_mode shadow_blend_mode; // Shadow blend mode: 4 bytes for signature and 4 bytes for the key 941 psd_argb_color shadow_color; 942 psd_argb_color real_shadow_color; 943 psd_uchar shadow_opacity; // Shadow opacity as a percent 944 945 psd_bool contour_enable; 946 psd_uchar[256] contour_lookup_table; 947 psd_bool contour_anti_aliased; 948 psd_int contour_range; 949 950 psd_bool texture_enable; 951 psd_pattern_info texture_pattern_info; 952 psd_int texture_scale; 953 psd_int texture_depth; 954 psd_bool texture_invert; 955 psd_bool texture_link; 956 psd_int texture_horz_phase; 957 psd_int texture_vert_phase; 958 } 959 960 struct psd_layer_effects_satin { 961 psd_bool effect_enable; // Effect enabled 962 963 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 964 psd_argb_color color; 965 psd_uchar opacity; // Opacity as a percent 966 psd_int angle; // Angle in degrees 967 psd_int distance; 968 psd_int size; 969 psd_uchar[256] contour_lookup_table; 970 psd_bool anti_aliased; 971 psd_bool invert; 972 } 973 974 // Effects layer, solid fill (added in Photoshop 7.0) 975 struct psd_layer_effects_color_overlay { 976 psd_bool effect_enable; // Effect enabled 977 978 psd_blend_mode blend_mode; // Key for blend mode 979 psd_argb_color color; 980 psd_uchar opacity; // Opacity as a percent 981 psd_argb_color native_color; 982 } 983 984 struct psd_layer_effects_gradient_overlay { 985 psd_bool effect_enable; // Effect enabled 986 987 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 988 psd_uchar opacity; // Opacity as a percent 989 psd_gradient_color gradient_color; 990 psd_bool reverse; 991 psd_gradient_style style; 992 psd_bool align_width_layer; 993 psd_int angle; // Angle in degrees 994 psd_int scale; 995 psd_int horz_offset; 996 psd_int vert_offset; 997 } 998 999 struct psd_layer_effects_pattern_overlay { 1000 psd_bool effect_enable; // Effect enabled 1001 1002 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 1003 psd_argb_color color; 1004 psd_uchar opacity; // Opacity as a percent 1005 psd_int scale; 1006 psd_bool link_with_layer; 1007 psd_pattern_info pattern_info; 1008 psd_int horz_phase; 1009 psd_int vert_phase; 1010 } 1011 1012 struct psd_layer_effects_stroke { 1013 psd_bool effect_enable; // Effect enabled 1014 1015 psd_int size; 1016 psd_stroke_position position; 1017 psd_blend_mode blend_mode; // Blend mode: 4 bytes for signature and 4 bytes for key 1018 psd_uchar opacity; // Opacity as a percent 1019 psd_fill_type fill_type; 1020 1021 psd_argb_color fill_color; 1022 1023 psd_gradient_color gradient_color; 1024 psd_bool gradient_reverse; 1025 psd_gradient_style gradient_style; 1026 psd_bool gradient_align; 1027 psd_int gradient_angle; 1028 psd_int gradient_scale; 1029 psd_int gradient_horz_offset; 1030 psd_int gradient_vert_offset; 1031 1032 psd_pattern_info pattern_info; 1033 psd_int pattern_scale; 1034 psd_bool pattern_link; 1035 psd_int pattern_horz_phase; 1036 psd_int pattern_vert_phase; 1037 } 1038 1039 // Effects Layer info 1040 struct psd_layer_effects { 1041 psd_short effects_count; // Effects count: may be 6 (for the 6 effects in Photoshop 5 and 6) or 7 (for Photoshop 7.0) 1042 psd_bool visible; // common state info, visible: always true 1043 psd_layer_effects_drop_shadow drop_shadow; 1044 psd_layer_effects_inner_shadow inner_shadow; 1045 psd_layer_effects_outer_glow outer_glow; 1046 psd_layer_effects_inner_glow inner_glow; 1047 psd_layer_effects_bevel_emboss bevel_emboss; 1048 psd_layer_effects_satin satin; 1049 psd_layer_effects_color_overlay color_overlay; 1050 psd_layer_effects_gradient_overlay gradient_overlay; 1051 psd_layer_effects_pattern_overlay pattern_overlay; 1052 psd_layer_effects_stroke stroke; 1053 1054 psd_bool[psd_layer_effects_type_count] fill; 1055 psd_bool[psd_layer_effects_type_count] valid; 1056 psd_blend_mode[psd_layer_effects_image_count] blend_mode; 1057 psd_uchar[psd_layer_effects_image_count] opacity; 1058 psd_argb_color*[psd_layer_effects_image_count] image_data; 1059 psd_int[psd_layer_effects_image_count] left; 1060 psd_int[psd_layer_effects_image_count] top; 1061 psd_int[psd_layer_effects_image_count] right; 1062 psd_int[psd_layer_effects_image_count] bottom; 1063 psd_int[psd_layer_effects_image_count] width; 1064 psd_int[psd_layer_effects_image_count] height; 1065 } 1066 1067 1068 // SOLID COLOR 1069 struct psd_layer_solid_color { 1070 psd_uint id; 1071 psd_argb_color fill_color; 1072 } 1073 1074 1075 // GRADIENT FILL 1076 struct psd_layer_gradient_fill { 1077 psd_uint id; 1078 psd_double angle; 1079 psd_gradient_style style; 1080 psd_int scale; 1081 psd_bool reverse; // Is gradient reverse 1082 psd_bool dithered; // Is gradient dithered 1083 psd_bool align_with_layer; 1084 psd_gradient_color gradient_color; 1085 } 1086 1087 1088 // PATTERN FILL 1089 struct psd_layer_pattern_fill { 1090 psd_uint id; 1091 psd_pattern_info pattern_info; 1092 psd_int scale; 1093 } 1094 1095 1096 // TYPE TOOL INFO (PHOTOSHOP 5.0 AND 5.5 ONLY) 1097 struct psd_layer_type_face { 1098 psd_short mark; // Mark value 1099 psd_int font_type; // Font type data 1100 psd_char[256] font_name; // Pascal string of font name 1101 psd_char[256] font_family_name; // Pascal string of font family name 1102 psd_char[256] font_style_name; // Pascal string of font style name 1103 psd_short script; // Script value 1104 psd_int number_axes_vector; // Number of design axes vector to follow 1105 psd_int * vector; // Design vector value 1106 } 1107 1108 struct psd_layer_type_style { 1109 psd_short mark; // Mark value 1110 psd_short face_mark; // Face mark value 1111 psd_int size; // Size value 1112 psd_int tracking; // Tracking value 1113 psd_int kerning; // Kerning value 1114 psd_int leading; // Leading value 1115 psd_int base_shift; // Base shift value 1116 psd_bool auto_kern; // Auto kern on/off 1117 psd_bool rotate; // Rotate up/down 1118 } 1119 1120 struct psd_layer_type_line { 1121 psd_int char_count; // Character count value 1122 psd_short orientation; // Orientation value 1123 psd_short alignment; // Alignment value 1124 psd_short actual_char; // Actual character as a double byte character 1125 psd_short style; // Style value 1126 } 1127 1128 struct psd_layer_type_tool { 1129 psd_double[6] transform_info; // 6 * 8 double precision numbers for the transform information 1130 psd_short faces_count; // Count of faces 1131 psd_layer_type_face * face; 1132 psd_short styles_count; // Count of styles 1133 psd_layer_type_style * style; 1134 psd_short type; // Type value 1135 psd_int scaling_factor; // Scaling factor value 1136 psd_int sharacter_count; // Sharacter count value 1137 psd_int horz_place; // Horizontal placement 1138 psd_int vert_place; // Vertical placement 1139 psd_int select_start; // Select start value 1140 psd_int select_end; // Select end value 1141 psd_short lines_count; // Line count 1142 psd_layer_type_line * line; 1143 psd_argb_color color; 1144 psd_bool anti_alias; // Anti alias on/off 1145 } 1146 1147 1148 // end of additional layer information 1149 /*********************************************************************************/ 1150 /*********************************************************************************/ 1151 1152 struct psd_file_stream { 1153 void* data; 1154 extern(C) size_t function(void* ptr, size_t count, void* data) nothrow read; 1155 extern(C) int function(long offset, int origin, void* data) nothrow seek; 1156 extern(C) long function(void* data) nothrow get_size; 1157 extern(C) void function(void* data) nothrow close; 1158 } 1159 1160 struct psd_context { 1161 psd_file_stream file; 1162 psd_stream stream; 1163 psd_uint state; 1164 psd_load_tag load_tag; 1165 1166 psd_ushort version_; 1167 psd_int width; 1168 psd_int height; 1169 psd_ushort channels; 1170 psd_ushort depth; 1171 psd_color_mode color_mode; 1172 1173 psd_int color_map_length; 1174 psd_argb_color * color_map; 1175 1176 psd_uchar[256] caption; 1177 1178 psd_bool fill_resolution_info; 1179 psd_resolution_info resolution_info; 1180 1181 psd_bool fill_display_info; 1182 psd_display_info display_info; 1183 1184 psd_bool fill_alpha_channel_info; 1185 psd_short alpha_channels; 1186 psd_short color_channels; 1187 psd_alpha_channel_info * alpha_channel_info; 1188 1189 psd_short target_layer_index; 1190 1191 psd_bool fill_layer_group; 1192 psd_int layer_group_count; 1193 psd_ushort * layer_group_id; 1194 1195 psd_bool fill_thumbnail_resource; 1196 psd_thumbnail_resource thumbnail_resource; 1197 1198 psd_bool fill_version_info; 1199 psd_version_info version_info; 1200 1201 psd_bool copyright_flag; 1202 psd_int global_angle; 1203 psd_int global_altitude; 1204 psd_bool effects_visible; 1205 psd_short indexed_color_table_count; 1206 psd_short transparency_index; 1207 1208 psd_bool fill_border_info; 1209 psd_border_info border_info; 1210 1211 psd_bool fill_print_flags; 1212 psd_print_flags print_flags; 1213 1214 psd_bool fill_grid_and_guides_info; 1215 psd_grid_guides grid_guides; 1216 1217 psd_bool fill_color_samplers; 1218 psd_color_samplers color_samplers; 1219 1220 psd_bool fill_slices_resource; 1221 psd_slices_resource slices_resource; 1222 1223 psd_bool fill_url_list; 1224 psd_url_list url_list; 1225 1226 psd_bool fill_exif_data; 1227 psd_uchar * exif_data; 1228 psd_int exif_data_length; 1229 1230 psd_bool fill_iptc_data; 1231 psd_uchar * iptc_data; 1232 psd_int iptc_data_length; 1233 1234 psd_bool fill_XMP_metadata; 1235 psd_uchar * XMP_metadata; 1236 psd_int XMP_metadata_length; 1237 1238 psd_bool fill_print_scale; 1239 psd_print_scale print_scale; 1240 1241 psd_double pixel_aspect_ratio; 1242 1243 psd_bool fill_print_flags_info; 1244 psd_print_flags_info print_flags_info; 1245 1246 psd_short layer_count; 1247 psd_layer_record * layer_records; 1248 1249 psd_global_layer_mask global_layer_mask; 1250 1251 psd_int malloc_pattern; 1252 psd_int pattern_count; 1253 psd_pattern * patterns; 1254 1255 psd_int malloc_path; 1256 psd_int path_count; 1257 psd_path * paths; 1258 1259 psd_argb_color * merged_image_data; 1260 psd_argb_color * blending_image_data; 1261 1262 // temporary data 1263 psd_uchar * rand_data; 1264 psd_uchar * temp_image_data; 1265 long temp_image_length; 1266 psd_uchar * temp_channel_data; 1267 long temp_channel_length; 1268 long per_channel_length; 1269 long max_channel_length; 1270 } 1271 1272 1273 psd_status psd_image_load(psd_context ** dst_context, psd_char * file_name); 1274 psd_status psd_image_load_header(psd_context ** dst_context, psd_char * file_name); 1275 psd_status psd_image_load_layer(psd_context ** dst_context, psd_char * file_name); 1276 psd_status psd_image_load_merged(psd_context ** dst_context, psd_char * file_name); 1277 psd_status psd_image_load_thumbnail(psd_context ** dst_context, psd_char * file_name); 1278 psd_status psd_image_load_metadata(psd_context ** dst_context, psd_char * file_name); 1279 psd_status psd_image_load_exif(psd_context ** dst_context, psd_char * file_name); 1280 1281 psd_status psd_image_load_stream(psd_context ** dst_context, psd_file_stream * stream); 1282 psd_status psd_image_load_stream_header(psd_context ** dst_context, psd_file_stream * stream); 1283 psd_status psd_image_load_stream_layer(psd_context ** dst_context, psd_file_stream * stream); 1284 psd_status psd_image_load_stream_merged(psd_context ** dst_context, psd_file_stream * stream); 1285 psd_status psd_image_load_stream_thumbnail(psd_context ** dst_context, psd_file_stream * stream); 1286 psd_status psd_image_load_stream_metadata(psd_context ** dst_context, psd_file_stream * stream); 1287 psd_status psd_image_load_stream_exif(psd_context ** dst_context, psd_file_stream * stream); 1288 1289 psd_status psd_image_free(psd_context * context); 1290 psd_status psd_adjustment_layer_update(psd_layer_record * layer); 1291 psd_status psd_layer_effects_update(psd_layer_record * layer, psd_layer_effects_type type); 1292 psd_status psd_image_blend(psd_context * context, psd_int left, psd_int top, psd_int width, psd_int height);