| 1 | /*****************************************************************************/ |
| 2 | // Copyright 2006-2012 Adobe Systems Incorporated |
| 3 | // All Rights Reserved. |
| 4 | // |
| 5 | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 | // accordance with the terms of the Adobe license agreement accompanying it. |
| 7 | /*****************************************************************************/ |
| 8 | |
| 9 | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_image_writer.h#3 $ */ |
| 10 | /* $DateTime: 2012/07/31 22:04:34 $ */ |
| 11 | /* $Change: 840853 $ */ |
| 12 | /* $Author: tknoll $ */ |
| 13 | |
| 14 | /** \file |
| 15 | * Support for writing DNG images to files. |
| 16 | */ |
| 17 | |
| 18 | /*****************************************************************************/ |
| 19 | |
| 20 | #ifndef __dng_image_writer__ |
| 21 | #define __dng_image_writer__ |
| 22 | |
| 23 | /*****************************************************************************/ |
| 24 | |
| 25 | #include "dng_auto_ptr.h" |
| 26 | #include "dng_classes.h" |
| 27 | #include "dng_fingerprint.h" |
| 28 | #include "dng_memory.h" |
| 29 | #include "dng_point.h" |
| 30 | #include "dng_rational.h" |
| 31 | #include "dng_sdk_limits.h" |
| 32 | #include "dng_string.h" |
| 33 | #include "dng_tag_types.h" |
| 34 | #include "dng_tag_values.h" |
| 35 | #include "dng_types.h" |
| 36 | |
| 37 | /*****************************************************************************/ |
| 38 | |
| 39 | /// \brief Image resolution. |
| 40 | |
| 41 | class dng_resolution |
| 42 | { |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | dng_urational fXResolution; |
| 47 | dng_urational fYResolution; |
| 48 | |
| 49 | uint16 fResolutionUnit; |
| 50 | |
| 51 | public: |
| 52 | |
| 53 | dng_resolution (); |
| 54 | |
| 55 | }; |
| 56 | |
| 57 | /*****************************************************************************/ |
| 58 | |
| 59 | class tiff_tag |
| 60 | { |
| 61 | |
| 62 | protected: |
| 63 | |
| 64 | uint16 fCode; |
| 65 | |
| 66 | uint16 fType; |
| 67 | |
| 68 | uint32 fCount; |
| 69 | |
| 70 | protected: |
| 71 | |
| 72 | tiff_tag (uint16 code, |
| 73 | uint16 type, |
| 74 | uint32 count) |
| 75 | |
| 76 | : fCode (code) |
| 77 | , fType (type) |
| 78 | , fCount (count) |
| 79 | |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | public: |
| 84 | |
| 85 | virtual ~tiff_tag () |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | uint16 Code () const |
| 90 | { |
| 91 | return fCode; |
| 92 | } |
| 93 | |
| 94 | uint16 Type () const |
| 95 | { |
| 96 | return fType; |
| 97 | } |
| 98 | |
| 99 | uint32 Count () const |
| 100 | { |
| 101 | return fCount; |
| 102 | } |
| 103 | |
| 104 | void SetCount (uint32 count) |
| 105 | { |
| 106 | fCount = count; |
| 107 | } |
| 108 | |
| 109 | uint32 Size () const |
| 110 | { |
| 111 | return TagTypeSize (Type ()) * Count (); |
| 112 | } |
| 113 | |
| 114 | virtual void Put (dng_stream &stream) const = 0; |
| 115 | |
| 116 | private: |
| 117 | |
| 118 | // Hidden copy constructor and assignment operator. |
| 119 | |
| 120 | tiff_tag (const tiff_tag &tag); |
| 121 | |
| 122 | tiff_tag & operator= (const tiff_tag &tag); |
| 123 | |
| 124 | }; |
| 125 | |
| 126 | /******************************************************************************/ |
| 127 | |
| 128 | class tag_data_ptr: public tiff_tag |
| 129 | { |
| 130 | |
| 131 | protected: |
| 132 | |
| 133 | const void *fData; |
| 134 | |
| 135 | public: |
| 136 | |
| 137 | tag_data_ptr (uint16 code, |
| 138 | uint16 type, |
| 139 | uint32 count, |
| 140 | const void *data) |
| 141 | |
| 142 | : tiff_tag (code, type, count) |
| 143 | |
| 144 | , fData (data) |
| 145 | |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | void SetData (const void *data) |
| 150 | { |
| 151 | fData = data; |
| 152 | } |
| 153 | |
| 154 | virtual void Put (dng_stream &stream) const; |
| 155 | |
| 156 | private: |
| 157 | |
| 158 | // Hidden copy constructor and assignment operator. |
| 159 | |
| 160 | tag_data_ptr (const tag_data_ptr &tag); |
| 161 | |
| 162 | tag_data_ptr & operator= (const tag_data_ptr &tag); |
| 163 | |
| 164 | }; |
| 165 | |
| 166 | /******************************************************************************/ |
| 167 | |
| 168 | class tag_string: public tiff_tag |
| 169 | { |
| 170 | |
| 171 | protected: |
| 172 | |
| 173 | dng_string fString; |
| 174 | |
| 175 | public: |
| 176 | |
| 177 | tag_string (uint16 code, |
| 178 | const dng_string &s, |
| 179 | bool forceASCII = true); |
| 180 | |
| 181 | virtual void Put (dng_stream &stream) const; |
| 182 | |
| 183 | }; |
| 184 | |
| 185 | /******************************************************************************/ |
| 186 | |
| 187 | class tag_encoded_text: public tiff_tag |
| 188 | { |
| 189 | |
| 190 | private: |
| 191 | |
| 192 | dng_string fText; |
| 193 | |
| 194 | dng_memory_data fUTF16; |
| 195 | |
| 196 | public: |
| 197 | |
| 198 | tag_encoded_text (uint16 code, |
| 199 | const dng_string &text); |
| 200 | |
| 201 | virtual void Put (dng_stream &stream) const; |
| 202 | |
| 203 | }; |
| 204 | |
| 205 | /******************************************************************************/ |
| 206 | |
| 207 | class tag_uint8: public tag_data_ptr |
| 208 | { |
| 209 | |
| 210 | private: |
| 211 | |
| 212 | uint8 fValue; |
| 213 | |
| 214 | public: |
| 215 | |
| 216 | tag_uint8 (uint16 code, |
| 217 | uint8 value = 0) |
| 218 | |
| 219 | : tag_data_ptr (code, ttByte, 1, &fValue) |
| 220 | |
| 221 | , fValue (value) |
| 222 | |
| 223 | { |
| 224 | } |
| 225 | |
| 226 | void Set (uint8 value) |
| 227 | { |
| 228 | fValue = value; |
| 229 | } |
| 230 | |
| 231 | }; |
| 232 | |
| 233 | /******************************************************************************/ |
| 234 | |
| 235 | class tag_uint8_ptr: public tag_data_ptr |
| 236 | { |
| 237 | |
| 238 | public: |
| 239 | |
| 240 | tag_uint8_ptr (uint16 code, |
| 241 | const uint8 *data, |
| 242 | uint32 count = 1) |
| 243 | |
| 244 | : tag_data_ptr (code, ttByte, count, data) |
| 245 | |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | }; |
| 250 | |
| 251 | /******************************************************************************/ |
| 252 | |
| 253 | class tag_uint16: public tag_data_ptr |
| 254 | { |
| 255 | |
| 256 | private: |
| 257 | |
| 258 | uint16 fValue; |
| 259 | |
| 260 | public: |
| 261 | |
| 262 | tag_uint16 (uint16 code, |
| 263 | uint16 value = 0) |
| 264 | |
| 265 | : tag_data_ptr (code, ttShort, 1, &fValue) |
| 266 | |
| 267 | , fValue (value) |
| 268 | |
| 269 | { |
| 270 | } |
| 271 | |
| 272 | void Set (uint16 value) |
| 273 | { |
| 274 | fValue = value; |
| 275 | } |
| 276 | |
| 277 | }; |
| 278 | |
| 279 | /******************************************************************************/ |
| 280 | |
| 281 | class tag_int16_ptr: public tag_data_ptr |
| 282 | { |
| 283 | |
| 284 | public: |
| 285 | |
| 286 | tag_int16_ptr (uint16 code, |
| 287 | const int16 *data, |
| 288 | uint32 count = 1) |
| 289 | |
| 290 | : tag_data_ptr (code, ttSShort, count, data) |
| 291 | |
| 292 | { |
| 293 | } |
| 294 | |
| 295 | }; |
| 296 | |
| 297 | /******************************************************************************/ |
| 298 | |
| 299 | class tag_uint16_ptr: public tag_data_ptr |
| 300 | { |
| 301 | |
| 302 | public: |
| 303 | |
| 304 | tag_uint16_ptr (uint16 code, |
| 305 | const uint16 *data, |
| 306 | uint32 count = 1) |
| 307 | |
| 308 | : tag_data_ptr (code, ttShort, count, data) |
| 309 | |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | }; |
| 314 | |
| 315 | /******************************************************************************/ |
| 316 | |
| 317 | class tag_uint32: public tag_data_ptr |
| 318 | { |
| 319 | |
| 320 | private: |
| 321 | |
| 322 | uint32 fValue; |
| 323 | |
| 324 | public: |
| 325 | |
| 326 | tag_uint32 (uint16 code, |
| 327 | uint32 value = 0) |
| 328 | |
| 329 | : tag_data_ptr (code, ttLong, 1, &fValue) |
| 330 | |
| 331 | , fValue (value) |
| 332 | |
| 333 | { |
| 334 | } |
| 335 | |
| 336 | void Set (uint32 value) |
| 337 | { |
| 338 | fValue = value; |
| 339 | } |
| 340 | |
| 341 | }; |
| 342 | |
| 343 | /******************************************************************************/ |
| 344 | |
| 345 | class tag_uint32_ptr: public tag_data_ptr |
| 346 | { |
| 347 | |
| 348 | public: |
| 349 | |
| 350 | tag_uint32_ptr (uint16 code, |
| 351 | const uint32 *data, |
| 352 | uint32 count = 1) |
| 353 | |
| 354 | : tag_data_ptr (code, ttLong, count, data) |
| 355 | |
| 356 | { |
| 357 | } |
| 358 | |
| 359 | }; |
| 360 | |
| 361 | /******************************************************************************/ |
| 362 | |
| 363 | class tag_urational: public tag_data_ptr |
| 364 | { |
| 365 | |
| 366 | private: |
| 367 | |
| 368 | const dng_urational fValue; |
| 369 | |
| 370 | public: |
| 371 | |
| 372 | tag_urational (uint16 code, |
| 373 | const dng_urational &value) |
| 374 | |
| 375 | : tag_data_ptr (code, ttRational, 1, &fValue) |
| 376 | |
| 377 | , fValue (value) |
| 378 | |
| 379 | { |
| 380 | } |
| 381 | |
| 382 | }; |
| 383 | |
| 384 | /******************************************************************************/ |
| 385 | |
| 386 | class tag_urational_ptr: public tag_data_ptr |
| 387 | { |
| 388 | |
| 389 | public: |
| 390 | |
| 391 | tag_urational_ptr (uint16 code, |
| 392 | const dng_urational *data = NULL, |
| 393 | uint32 count = 1) |
| 394 | |
| 395 | : tag_data_ptr (code, ttRational, count, data) |
| 396 | |
| 397 | { |
| 398 | } |
| 399 | |
| 400 | }; |
| 401 | |
| 402 | /******************************************************************************/ |
| 403 | |
| 404 | class tag_srational: public tag_data_ptr |
| 405 | { |
| 406 | |
| 407 | private: |
| 408 | |
| 409 | const dng_srational fValue; |
| 410 | |
| 411 | public: |
| 412 | |
| 413 | tag_srational (uint16 code, |
| 414 | const dng_srational &value) |
| 415 | |
| 416 | : tag_data_ptr (code, ttSRational, 1, &fValue) |
| 417 | |
| 418 | , fValue (value) |
| 419 | |
| 420 | { |
| 421 | } |
| 422 | |
| 423 | }; |
| 424 | |
| 425 | /******************************************************************************/ |
| 426 | |
| 427 | class tag_srational_ptr: public tag_data_ptr |
| 428 | { |
| 429 | |
| 430 | public: |
| 431 | |
| 432 | tag_srational_ptr (uint16 code, |
| 433 | const dng_srational *data = NULL, |
| 434 | uint32 count = 1) |
| 435 | |
| 436 | : tag_data_ptr (code, ttSRational, count, data) |
| 437 | |
| 438 | { |
| 439 | } |
| 440 | |
| 441 | }; |
| 442 | |
| 443 | /******************************************************************************/ |
| 444 | |
| 445 | class tag_real64: public tag_data_ptr |
| 446 | { |
| 447 | |
| 448 | private: |
| 449 | |
| 450 | real64 fValue; |
| 451 | |
| 452 | public: |
| 453 | |
| 454 | tag_real64 (uint16 code, |
| 455 | real64 value = 0.0) |
| 456 | |
| 457 | : tag_data_ptr (code, ttDouble, 1, &fValue) |
| 458 | |
| 459 | , fValue (value) |
| 460 | |
| 461 | { |
| 462 | } |
| 463 | |
| 464 | void Set (real64 value) |
| 465 | { |
| 466 | fValue = value; |
| 467 | } |
| 468 | |
| 469 | }; |
| 470 | |
| 471 | /******************************************************************************/ |
| 472 | |
| 473 | class tag_matrix: public tag_srational_ptr |
| 474 | { |
| 475 | |
| 476 | private: |
| 477 | |
| 478 | dng_srational fEntry [kMaxColorPlanes * |
| 479 | kMaxColorPlanes]; |
| 480 | |
| 481 | public: |
| 482 | |
| 483 | tag_matrix (uint16 code, |
| 484 | const dng_matrix &m); |
| 485 | |
| 486 | }; |
| 487 | |
| 488 | /******************************************************************************/ |
| 489 | |
| 490 | class tag_icc_profile: public tag_data_ptr |
| 491 | { |
| 492 | |
| 493 | public: |
| 494 | |
| 495 | tag_icc_profile (const void *profileData, uint32 profileSize); |
| 496 | |
| 497 | }; |
| 498 | |
| 499 | /******************************************************************************/ |
| 500 | |
| 501 | class tag_cfa_pattern: public tiff_tag |
| 502 | { |
| 503 | |
| 504 | private: |
| 505 | |
| 506 | uint32 fRows; |
| 507 | uint32 fCols; |
| 508 | |
| 509 | const uint8 *fPattern; |
| 510 | |
| 511 | public: |
| 512 | |
| 513 | tag_cfa_pattern (uint16 code, |
| 514 | uint32 rows, |
| 515 | uint32 cols, |
| 516 | const uint8 *pattern) |
| 517 | |
| 518 | : tiff_tag (code, ttUndefined, 4 + rows * cols) |
| 519 | |
| 520 | , fRows (rows ) |
| 521 | , fCols (cols ) |
| 522 | , fPattern (pattern) |
| 523 | |
| 524 | { |
| 525 | } |
| 526 | |
| 527 | virtual void Put (dng_stream &stream) const; |
| 528 | |
| 529 | private: |
| 530 | |
| 531 | // Hidden copy constructor and assignment operator. |
| 532 | |
| 533 | tag_cfa_pattern (const tag_cfa_pattern &tag); |
| 534 | |
| 535 | tag_cfa_pattern & operator= (const tag_cfa_pattern &tag); |
| 536 | |
| 537 | }; |
| 538 | |
| 539 | /******************************************************************************/ |
| 540 | |
| 541 | class tag_exif_date_time: public tag_data_ptr |
| 542 | { |
| 543 | |
| 544 | private: |
| 545 | |
| 546 | char fData [20]; |
| 547 | |
| 548 | public: |
| 549 | |
| 550 | tag_exif_date_time (uint16 code, |
| 551 | const dng_date_time &dt); |
| 552 | |
| 553 | }; |
| 554 | |
| 555 | /******************************************************************************/ |
| 556 | |
| 557 | class tag_iptc: public tiff_tag |
| 558 | { |
| 559 | |
| 560 | private: |
| 561 | |
| 562 | const void *fData; |
| 563 | |
| 564 | uint32 fLength; |
| 565 | |
| 566 | public: |
| 567 | |
| 568 | tag_iptc (const void *data, |
| 569 | uint32 length); |
| 570 | |
| 571 | virtual void Put (dng_stream &stream) const; |
| 572 | |
| 573 | private: |
| 574 | |
| 575 | // Hidden copy constructor and assignment operator. |
| 576 | |
| 577 | tag_iptc (const tag_iptc &tag); |
| 578 | |
| 579 | tag_iptc & operator= (const tag_iptc &tag); |
| 580 | |
| 581 | }; |
| 582 | |
| 583 | /******************************************************************************/ |
| 584 | |
| 585 | class tag_xmp: public tag_uint8_ptr |
| 586 | { |
| 587 | |
| 588 | private: |
| 589 | |
| 590 | AutoPtr<dng_memory_block> fBuffer; |
| 591 | |
| 592 | public: |
| 593 | |
| 594 | tag_xmp (const dng_xmp *xmp); |
| 595 | |
| 596 | private: |
| 597 | |
| 598 | // Hidden copy constructor and assignment operator. |
| 599 | |
| 600 | tag_xmp (const tag_xmp &tag); |
| 601 | |
| 602 | tag_xmp & operator= (const tag_xmp &tag); |
| 603 | |
| 604 | }; |
| 605 | |
| 606 | /******************************************************************************/ |
| 607 | |
| 608 | class dng_tiff_directory |
| 609 | { |
| 610 | |
| 611 | private: |
| 612 | |
| 613 | enum |
| 614 | { |
| 615 | kMaxEntries = 100 |
| 616 | }; |
| 617 | |
| 618 | uint32 fEntries; |
| 619 | |
| 620 | const tiff_tag *fTag [kMaxEntries]; |
| 621 | |
| 622 | uint32 fChained; |
| 623 | |
| 624 | public: |
| 625 | |
| 626 | dng_tiff_directory () |
| 627 | |
| 628 | : fEntries (0) |
| 629 | , fChained (0) |
| 630 | |
| 631 | { |
| 632 | } |
| 633 | |
| 634 | virtual ~dng_tiff_directory () |
| 635 | { |
| 636 | } |
| 637 | |
| 638 | void Add (const tiff_tag *tag); |
| 639 | |
| 640 | void SetChained (uint32 offset) |
| 641 | { |
| 642 | fChained = offset; |
| 643 | } |
| 644 | |
| 645 | uint32 Size () const; |
| 646 | |
| 647 | enum OffsetsBase |
| 648 | { |
| 649 | offsetsRelativeToStream = 0, |
| 650 | offsetsRelativeToExplicitBase = 1, |
| 651 | offsetsRelativeToIFD = 2 |
| 652 | }; |
| 653 | |
| 654 | void Put (dng_stream &stream, |
| 655 | OffsetsBase offsetsBase = offsetsRelativeToStream, |
| 656 | uint32 explicitBase = 0) const; |
| 657 | |
| 658 | private: |
| 659 | |
| 660 | // Hidden copy constructor and assignment operator. |
| 661 | |
| 662 | dng_tiff_directory (const dng_tiff_directory &dir); |
| 663 | |
| 664 | dng_tiff_directory & operator= (const dng_tiff_directory &dir); |
| 665 | |
| 666 | }; |
| 667 | |
| 668 | /******************************************************************************/ |
| 669 | |
| 670 | class dng_basic_tag_set |
| 671 | { |
| 672 | |
| 673 | private: |
| 674 | |
| 675 | tag_uint32 fNewSubFileType; |
| 676 | |
| 677 | tag_uint32 fImageWidth; |
| 678 | tag_uint32 fImageLength; |
| 679 | |
| 680 | tag_uint16 fPhotoInterpretation; |
| 681 | |
| 682 | tag_uint16 fFillOrder; |
| 683 | |
| 684 | tag_uint16 fSamplesPerPixel; |
| 685 | |
| 686 | uint16 fBitsPerSampleData [kMaxSamplesPerPixel]; |
| 687 | |
| 688 | tag_uint16_ptr fBitsPerSample; |
| 689 | |
| 690 | bool fStrips; |
| 691 | |
| 692 | tag_uint32 fTileWidth; |
| 693 | tag_uint32 fTileLength; |
| 694 | |
| 695 | dng_memory_data fTileInfoBuffer; |
| 696 | |
| 697 | uint32 *fTileOffsetData; |
| 698 | |
| 699 | tag_uint32_ptr fTileOffsets; |
| 700 | |
| 701 | uint32 *fTileByteCountData; |
| 702 | |
| 703 | tag_uint32_ptr fTileByteCounts; |
| 704 | |
| 705 | tag_uint16 fPlanarConfiguration; |
| 706 | |
| 707 | tag_uint16 fCompression; |
| 708 | |
| 709 | tag_uint16 fPredictor; |
| 710 | |
| 711 | uint16 [kMaxSamplesPerPixel]; |
| 712 | |
| 713 | tag_uint16_ptr ; |
| 714 | |
| 715 | uint16 fSampleFormatData [kMaxSamplesPerPixel]; |
| 716 | |
| 717 | tag_uint16_ptr fSampleFormat; |
| 718 | |
| 719 | tag_uint16 fRowInterleaveFactor; |
| 720 | |
| 721 | uint16 fSubTileBlockSizeData [2]; |
| 722 | |
| 723 | tag_uint16_ptr fSubTileBlockSize; |
| 724 | |
| 725 | public: |
| 726 | |
| 727 | dng_basic_tag_set (dng_tiff_directory &directory, |
| 728 | const dng_ifd &info); |
| 729 | |
| 730 | virtual ~dng_basic_tag_set () |
| 731 | { |
| 732 | } |
| 733 | |
| 734 | void SetTileOffset (uint32 index, |
| 735 | uint32 offset) |
| 736 | { |
| 737 | fTileOffsetData [index] = offset; |
| 738 | } |
| 739 | |
| 740 | void SetTileByteCount (uint32 index, |
| 741 | uint32 count) |
| 742 | { |
| 743 | fTileByteCountData [index] = count; |
| 744 | } |
| 745 | |
| 746 | bool WritingStrips () const |
| 747 | { |
| 748 | return fStrips; |
| 749 | } |
| 750 | |
| 751 | private: |
| 752 | |
| 753 | // Hidden copy constructor and assignment operator. |
| 754 | |
| 755 | dng_basic_tag_set (const dng_basic_tag_set &set); |
| 756 | |
| 757 | dng_basic_tag_set & operator= (const dng_basic_tag_set &set); |
| 758 | |
| 759 | }; |
| 760 | |
| 761 | /******************************************************************************/ |
| 762 | |
| 763 | class exif_tag_set |
| 764 | { |
| 765 | |
| 766 | protected: |
| 767 | |
| 768 | dng_tiff_directory fExifIFD; |
| 769 | dng_tiff_directory fGPSIFD; |
| 770 | |
| 771 | private: |
| 772 | |
| 773 | tag_uint32 fExifLink; |
| 774 | tag_uint32 fGPSLink; |
| 775 | |
| 776 | bool fAddedExifLink; |
| 777 | bool fAddedGPSLink; |
| 778 | |
| 779 | uint8 fExifVersionData [4]; |
| 780 | |
| 781 | tag_data_ptr fExifVersion; |
| 782 | |
| 783 | tag_urational fExposureTime; |
| 784 | tag_srational fShutterSpeedValue; |
| 785 | |
| 786 | tag_urational fFNumber; |
| 787 | tag_urational fApertureValue; |
| 788 | |
| 789 | tag_srational fBrightnessValue; |
| 790 | |
| 791 | tag_srational fExposureBiasValue; |
| 792 | |
| 793 | tag_urational fMaxApertureValue; |
| 794 | |
| 795 | tag_urational fSubjectDistance; |
| 796 | |
| 797 | tag_urational fFocalLength; |
| 798 | |
| 799 | tag_uint16 fISOSpeedRatings; |
| 800 | |
| 801 | tag_uint16 fSensitivityType; |
| 802 | tag_uint32 fStandardOutputSensitivity; |
| 803 | tag_uint32 fRecommendedExposureIndex; |
| 804 | tag_uint32 fISOSpeed; |
| 805 | tag_uint32 fISOSpeedLatitudeyyy; |
| 806 | tag_uint32 fISOSpeedLatitudezzz; |
| 807 | |
| 808 | tag_uint16 fFlash; |
| 809 | |
| 810 | tag_uint16 fExposureProgram; |
| 811 | |
| 812 | tag_uint16 fMeteringMode; |
| 813 | |
| 814 | tag_uint16 fLightSource; |
| 815 | |
| 816 | tag_uint16 fSensingMethod; |
| 817 | |
| 818 | tag_uint16 fFocalLength35mm; |
| 819 | |
| 820 | uint8 fFileSourceData; |
| 821 | tag_data_ptr fFileSource; |
| 822 | |
| 823 | uint8 fSceneTypeData; |
| 824 | tag_data_ptr fSceneType; |
| 825 | |
| 826 | tag_cfa_pattern fCFAPattern; |
| 827 | |
| 828 | tag_uint16 fCustomRendered; |
| 829 | tag_uint16 fExposureMode; |
| 830 | tag_uint16 fWhiteBalance; |
| 831 | tag_uint16 fSceneCaptureType; |
| 832 | tag_uint16 fGainControl; |
| 833 | tag_uint16 fContrast; |
| 834 | tag_uint16 fSaturation; |
| 835 | tag_uint16 fSharpness; |
| 836 | tag_uint16 fSubjectDistanceRange; |
| 837 | |
| 838 | tag_urational fDigitalZoomRatio; |
| 839 | |
| 840 | tag_urational fExposureIndex; |
| 841 | |
| 842 | tag_uint32 fImageNumber; |
| 843 | |
| 844 | tag_uint16 fSelfTimerMode; |
| 845 | |
| 846 | tag_string fBatteryLevelA; |
| 847 | tag_urational fBatteryLevelR; |
| 848 | |
| 849 | tag_urational fFocalPlaneXResolution; |
| 850 | tag_urational fFocalPlaneYResolution; |
| 851 | |
| 852 | tag_uint16 fFocalPlaneResolutionUnit; |
| 853 | |
| 854 | uint16 fSubjectAreaData [4]; |
| 855 | |
| 856 | tag_uint16_ptr fSubjectArea; |
| 857 | |
| 858 | dng_urational fLensInfoData [4]; |
| 859 | |
| 860 | tag_urational_ptr fLensInfo; |
| 861 | |
| 862 | tag_exif_date_time fDateTime; |
| 863 | tag_exif_date_time fDateTimeOriginal; |
| 864 | tag_exif_date_time fDateTimeDigitized; |
| 865 | |
| 866 | tag_string fSubsecTime; |
| 867 | tag_string fSubsecTimeOriginal; |
| 868 | tag_string fSubsecTimeDigitized; |
| 869 | |
| 870 | tag_string fMake; |
| 871 | tag_string fModel; |
| 872 | tag_string fArtist; |
| 873 | tag_string fSoftware; |
| 874 | tag_string fCopyright; |
| 875 | tag_string fImageDescription; |
| 876 | |
| 877 | tag_string fSerialNumber; |
| 878 | |
| 879 | tag_uint16 fMakerNoteSafety; |
| 880 | |
| 881 | tag_data_ptr fMakerNote; |
| 882 | |
| 883 | tag_encoded_text ; |
| 884 | |
| 885 | char fImageUniqueIDData [33]; |
| 886 | |
| 887 | tag_data_ptr fImageUniqueID; |
| 888 | |
| 889 | // EXIF 2.3 tags. |
| 890 | |
| 891 | tag_string fCameraOwnerName; |
| 892 | tag_string fBodySerialNumber; |
| 893 | tag_urational_ptr fLensSpecification; |
| 894 | tag_string fLensMake; |
| 895 | tag_string fLensModel; |
| 896 | tag_string fLensSerialNumber; |
| 897 | |
| 898 | uint8 fGPSVersionData [4]; |
| 899 | |
| 900 | tag_uint8_ptr fGPSVersionID; |
| 901 | |
| 902 | tag_string fGPSLatitudeRef; |
| 903 | tag_urational_ptr fGPSLatitude; |
| 904 | |
| 905 | tag_string fGPSLongitudeRef; |
| 906 | tag_urational_ptr fGPSLongitude; |
| 907 | |
| 908 | tag_uint8 fGPSAltitudeRef; |
| 909 | tag_urational fGPSAltitude; |
| 910 | |
| 911 | tag_urational_ptr fGPSTimeStamp; |
| 912 | |
| 913 | tag_string fGPSSatellites; |
| 914 | tag_string fGPSStatus; |
| 915 | tag_string fGPSMeasureMode; |
| 916 | |
| 917 | tag_urational fGPSDOP; |
| 918 | |
| 919 | tag_string fGPSSpeedRef; |
| 920 | tag_urational fGPSSpeed; |
| 921 | |
| 922 | tag_string fGPSTrackRef; |
| 923 | tag_urational fGPSTrack; |
| 924 | |
| 925 | tag_string fGPSImgDirectionRef; |
| 926 | tag_urational fGPSImgDirection; |
| 927 | |
| 928 | tag_string fGPSMapDatum; |
| 929 | |
| 930 | tag_string fGPSDestLatitudeRef; |
| 931 | tag_urational_ptr fGPSDestLatitude; |
| 932 | |
| 933 | tag_string fGPSDestLongitudeRef; |
| 934 | tag_urational_ptr fGPSDestLongitude; |
| 935 | |
| 936 | tag_string fGPSDestBearingRef; |
| 937 | tag_urational fGPSDestBearing; |
| 938 | |
| 939 | tag_string fGPSDestDistanceRef; |
| 940 | tag_urational fGPSDestDistance; |
| 941 | |
| 942 | tag_encoded_text fGPSProcessingMethod; |
| 943 | tag_encoded_text fGPSAreaInformation; |
| 944 | |
| 945 | tag_string fGPSDateStamp; |
| 946 | |
| 947 | tag_uint16 fGPSDifferential; |
| 948 | |
| 949 | tag_urational fGPSHPositioningError; |
| 950 | |
| 951 | public: |
| 952 | |
| 953 | exif_tag_set (dng_tiff_directory &directory, |
| 954 | const dng_exif &exif, |
| 955 | bool makerNoteSafe = false, |
| 956 | const void *makerNoteData = NULL, |
| 957 | uint32 makerNoteLength = 0, |
| 958 | bool insideDNG = false); |
| 959 | |
| 960 | void Locate (uint32 offset) |
| 961 | { |
| 962 | fExifLink.Set (offset); |
| 963 | fGPSLink .Set (offset + fExifIFD.Size ()); |
| 964 | } |
| 965 | |
| 966 | uint32 Size () const |
| 967 | { |
| 968 | return fExifIFD.Size () + |
| 969 | fGPSIFD .Size (); |
| 970 | } |
| 971 | |
| 972 | void Put (dng_stream &stream) const |
| 973 | { |
| 974 | fExifIFD.Put (stream); |
| 975 | fGPSIFD .Put (stream); |
| 976 | } |
| 977 | |
| 978 | protected: |
| 979 | |
| 980 | void AddLinks (dng_tiff_directory &directory); |
| 981 | |
| 982 | private: |
| 983 | |
| 984 | // Hidden copy constructor and assignment operator. |
| 985 | |
| 986 | exif_tag_set (const exif_tag_set &set); |
| 987 | |
| 988 | exif_tag_set & operator= (const exif_tag_set &set); |
| 989 | |
| 990 | }; |
| 991 | |
| 992 | /******************************************************************************/ |
| 993 | |
| 994 | class tiff_dng_extended_color_profile: private dng_tiff_directory |
| 995 | { |
| 996 | |
| 997 | protected: |
| 998 | |
| 999 | const dng_camera_profile &fProfile; |
| 1000 | |
| 1001 | public: |
| 1002 | |
| 1003 | tiff_dng_extended_color_profile (const dng_camera_profile &profile); |
| 1004 | |
| 1005 | void Put (dng_stream &stream, |
| 1006 | bool includeModelRestriction = true); |
| 1007 | |
| 1008 | }; |
| 1009 | |
| 1010 | /*****************************************************************************/ |
| 1011 | |
| 1012 | class tag_dng_noise_profile: public tag_data_ptr |
| 1013 | { |
| 1014 | |
| 1015 | protected: |
| 1016 | |
| 1017 | real64 fValues [2 * kMaxColorPlanes]; |
| 1018 | |
| 1019 | public: |
| 1020 | |
| 1021 | explicit tag_dng_noise_profile (const dng_noise_profile &profile); |
| 1022 | |
| 1023 | }; |
| 1024 | |
| 1025 | /*****************************************************************************/ |
| 1026 | |
| 1027 | // Enum to control the subset of metadata to save to a file. |
| 1028 | |
| 1029 | enum dng_metadata_subset |
| 1030 | { |
| 1031 | |
| 1032 | kMetadataSubset_CopyrightOnly = 0, |
| 1033 | kMetadataSubset_CopyrightAndContact, |
| 1034 | kMetadataSubset_AllExceptCameraInfo, |
| 1035 | kMetadataSubset_All, |
| 1036 | kMetadataSubset_AllExceptLocationInfo, |
| 1037 | kMetadataSubset_AllExceptCameraAndLocation, |
| 1038 | |
| 1039 | kMetadataSubset_Last = kMetadataSubset_AllExceptCameraAndLocation |
| 1040 | |
| 1041 | }; |
| 1042 | |
| 1043 | /*****************************************************************************/ |
| 1044 | |
| 1045 | /// \brief Support for writing dng_image or dng_negative instances to a |
| 1046 | /// dng_stream in TIFF or DNG format. |
| 1047 | |
| 1048 | class dng_image_writer |
| 1049 | { |
| 1050 | |
| 1051 | friend class dng_jpeg_image; |
| 1052 | friend class dng_jpeg_image_encode_task; |
| 1053 | friend class dng_write_tiles_task; |
| 1054 | |
| 1055 | protected: |
| 1056 | |
| 1057 | enum |
| 1058 | { |
| 1059 | |
| 1060 | // Target size for buffer used to copy data to the image. |
| 1061 | |
| 1062 | kImageBufferSize = 128 * 1024 |
| 1063 | |
| 1064 | }; |
| 1065 | |
| 1066 | public: |
| 1067 | |
| 1068 | dng_image_writer (); |
| 1069 | |
| 1070 | virtual ~dng_image_writer (); |
| 1071 | |
| 1072 | virtual void EncodeJPEGPreview (dng_host &host, |
| 1073 | const dng_image &image, |
| 1074 | dng_jpeg_preview &preview, |
| 1075 | int32 quality = -1); |
| 1076 | |
| 1077 | virtual void WriteImage (dng_host &host, |
| 1078 | const dng_ifd &ifd, |
| 1079 | dng_basic_tag_set &basic, |
| 1080 | dng_stream &stream, |
| 1081 | const dng_image &image, |
| 1082 | uint32 fakeChannels = 1); |
| 1083 | |
| 1084 | /// Write a dng_image to a dng_stream in TIFF format. |
| 1085 | /// \param host Host interface used for progress updates, abort testing, buffer allocation, etc. |
| 1086 | /// \param stream The dng_stream on which to write the TIFF. |
| 1087 | /// \param image The actual image data to be written. |
| 1088 | /// \param photometricInterpretation Either piBlackIsZero for monochrome or piRGB for RGB images. |
| 1089 | /// \param compression Must be ccUncompressed. |
| 1090 | /// \param negative or metadata If non-NULL, EXIF, IPTC, and XMP metadata from this negative is written to TIFF. |
| 1091 | /// \param space If non-null and color space has an ICC profile, TIFF will be tagged with this |
| 1092 | /// profile. No color space conversion of image data occurs. |
| 1093 | /// \param resolution If non-NULL, TIFF will be tagged with this resolution. |
| 1094 | /// \param thumbnail If non-NULL, will be stored in TIFF as preview image. |
| 1095 | /// \param imageResources If non-NULL, will image resources be stored in TIFF as well. |
| 1096 | /// \param metadataSubset The subset of metadata (e.g., copyright only) to include in the TIFF. |
| 1097 | |
| 1098 | void WriteTIFF (dng_host &host, |
| 1099 | dng_stream &stream, |
| 1100 | const dng_image &image, |
| 1101 | uint32 photometricInterpretation, |
| 1102 | uint32 compression, |
| 1103 | dng_negative *negative, |
| 1104 | const dng_color_space *space = NULL, |
| 1105 | const dng_resolution *resolution = NULL, |
| 1106 | const dng_jpeg_preview *thumbnail = NULL, |
| 1107 | const dng_memory_block *imageResources = NULL, |
| 1108 | dng_metadata_subset metadataSubset = kMetadataSubset_All); |
| 1109 | |
| 1110 | void WriteTIFF (dng_host &host, |
| 1111 | dng_stream &stream, |
| 1112 | const dng_image &image, |
| 1113 | uint32 photometricInterpretation = piBlackIsZero, |
| 1114 | uint32 compression = ccUncompressed, |
| 1115 | const dng_metadata *metadata = NULL, |
| 1116 | const dng_color_space *space = NULL, |
| 1117 | const dng_resolution *resolution = NULL, |
| 1118 | const dng_jpeg_preview *thumbnail = NULL, |
| 1119 | const dng_memory_block *imageResources = NULL, |
| 1120 | dng_metadata_subset metadataSubset = kMetadataSubset_All); |
| 1121 | |
| 1122 | /// Write a dng_image to a dng_stream in TIFF format. |
| 1123 | /// \param host Host interface used for progress updates, abort testing, buffer allocation, etc. |
| 1124 | /// \param stream The dng_stream on which to write the TIFF. |
| 1125 | /// \param image The actual image data to be written. |
| 1126 | /// \param photometricInterpretation Either piBlackIsZero for monochrome or piRGB for RGB images. |
| 1127 | /// \param compression Must be ccUncompressed. |
| 1128 | /// \param negative or metadata If non-NULL, EXIF, IPTC, and XMP metadata from this negative is written to TIFF. |
| 1129 | /// \param profileData If non-null, TIFF will be tagged with this profile. No color space conversion |
| 1130 | /// of image data occurs. |
| 1131 | /// \param profileSize The size for the profile data. |
| 1132 | /// \param resolution If non-NULL, TIFF will be tagged with this resolution. |
| 1133 | /// \param thumbnail If non-NULL, will be stored in TIFF as preview image. |
| 1134 | /// \param imageResources If non-NULL, will image resources be stored in TIFF as well. |
| 1135 | /// \param metadataSubset The subset of metadata (e.g., copyright only) to include in the TIFF. |
| 1136 | |
| 1137 | void WriteTIFFWithProfile (dng_host &host, |
| 1138 | dng_stream &stream, |
| 1139 | const dng_image &image, |
| 1140 | uint32 photometricInterpretation, |
| 1141 | uint32 compression, |
| 1142 | dng_negative *negative, |
| 1143 | const void *profileData = NULL, |
| 1144 | uint32 profileSize = 0, |
| 1145 | const dng_resolution *resolution = NULL, |
| 1146 | const dng_jpeg_preview *thumbnail = NULL, |
| 1147 | const dng_memory_block *imageResources = NULL, |
| 1148 | dng_metadata_subset metadataSubset = kMetadataSubset_All); |
| 1149 | |
| 1150 | virtual void WriteTIFFWithProfile (dng_host &host, |
| 1151 | dng_stream &stream, |
| 1152 | const dng_image &image, |
| 1153 | uint32 photometricInterpretation = piBlackIsZero, |
| 1154 | uint32 compression = ccUncompressed, |
| 1155 | const dng_metadata *metadata = NULL, |
| 1156 | const void *profileData = NULL, |
| 1157 | uint32 profileSize = 0, |
| 1158 | const dng_resolution *resolution = NULL, |
| 1159 | const dng_jpeg_preview *thumbnail = NULL, |
| 1160 | const dng_memory_block *imageResources = NULL, |
| 1161 | dng_metadata_subset metadataSubset = kMetadataSubset_All); |
| 1162 | |
| 1163 | /// Write a dng_image to a dng_stream in DNG format. |
| 1164 | /// \param host Host interface used for progress updates, abort testing, buffer allocation, etc. |
| 1165 | /// \param stream The dng_stream on which to write the TIFF. |
| 1166 | /// \param negative The image data and metadata (EXIF, IPTC, XMP) to be written. |
| 1167 | /// \param previewList List of previews (not counting thumbnail) to write to the file. Defaults to empty. |
| 1168 | /// \param maxBackwardVersion The DNG file should be readable by readers at least back to this version. |
| 1169 | /// \param uncompressed True to force uncompressed images. Otherwise use normal compression. |
| 1170 | |
| 1171 | void WriteDNG (dng_host &host, |
| 1172 | dng_stream &stream, |
| 1173 | dng_negative &negative, |
| 1174 | const dng_preview_list *previewList = NULL, |
| 1175 | uint32 maxBackwardVersion = dngVersion_SaveDefault, |
| 1176 | bool uncompressed = false); |
| 1177 | |
| 1178 | /// Write a dng_image to a dng_stream in DNG format. |
| 1179 | /// \param host Host interface used for progress updates, abort testing, buffer allocation, etc. |
| 1180 | /// \param stream The dng_stream on which to write the TIFF. |
| 1181 | /// \param negative The image data to be written. |
| 1182 | /// \param metadata The metadata (EXIF, IPTC, XMP) to be written. |
| 1183 | /// \param previewList List of previews (not counting thumbnail) to write to the file. Defaults to empty. |
| 1184 | /// \param maxBackwardVersion The DNG file should be readable by readers at least back to this version. |
| 1185 | /// \param uncompressed True to force uncompressed images. Otherwise use normal compression. |
| 1186 | |
| 1187 | virtual void WriteDNG (dng_host &host, |
| 1188 | dng_stream &stream, |
| 1189 | const dng_negative &negative, |
| 1190 | const dng_metadata &metadata, |
| 1191 | const dng_preview_list *previewList = NULL, |
| 1192 | uint32 maxBackwardVersion = dngVersion_SaveDefault, |
| 1193 | bool uncompressed = false); |
| 1194 | |
| 1195 | /// Resolve metadata conflicts and apply metadata policies in keeping |
| 1196 | /// with Metadata Working Group (MWG) guidelines. |
| 1197 | |
| 1198 | virtual void CleanUpMetadata (dng_host &host, |
| 1199 | dng_metadata &metadata, |
| 1200 | dng_metadata_subset metadataSubset, |
| 1201 | const char *dstMIMI, |
| 1202 | const char *software = NULL); |
| 1203 | |
| 1204 | protected: |
| 1205 | |
| 1206 | virtual uint32 CompressedBufferSize (const dng_ifd &ifd, |
| 1207 | uint32 uncompressedSize); |
| 1208 | |
| 1209 | virtual void EncodePredictor (dng_host &host, |
| 1210 | const dng_ifd &ifd, |
| 1211 | dng_pixel_buffer &buffer, |
| 1212 | AutoPtr<dng_memory_block> &tempBuffer); |
| 1213 | |
| 1214 | virtual void ByteSwapBuffer (dng_host &host, |
| 1215 | dng_pixel_buffer &buffer); |
| 1216 | |
| 1217 | void ReorderSubTileBlocks (const dng_ifd &ifd, |
| 1218 | dng_pixel_buffer &buffer, |
| 1219 | AutoPtr<dng_memory_block> &uncompressedBuffer, |
| 1220 | AutoPtr<dng_memory_block> &subTileBlockBuffer); |
| 1221 | |
| 1222 | virtual void WriteData (dng_host &host, |
| 1223 | const dng_ifd &ifd, |
| 1224 | dng_stream &stream, |
| 1225 | dng_pixel_buffer &buffer, |
| 1226 | AutoPtr<dng_memory_block> &compressedBuffer); |
| 1227 | |
| 1228 | virtual void WriteTile (dng_host &host, |
| 1229 | const dng_ifd &ifd, |
| 1230 | dng_stream &stream, |
| 1231 | const dng_image &image, |
| 1232 | const dng_rect &tileArea, |
| 1233 | uint32 fakeChannels, |
| 1234 | AutoPtr<dng_memory_block> &compressedBuffer, |
| 1235 | AutoPtr<dng_memory_block> &uncompressedBuffer, |
| 1236 | AutoPtr<dng_memory_block> &subTileBlockBuffer, |
| 1237 | AutoPtr<dng_memory_block> &tempBuffer); |
| 1238 | |
| 1239 | }; |
| 1240 | |
| 1241 | /*****************************************************************************/ |
| 1242 | |
| 1243 | #endif |
| 1244 | |
| 1245 | /*****************************************************************************/ |
| 1246 | |