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