| 1 |
/*****************************************************************************/ |
| 2 |
// Copyright 2015-2023 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 |
#ifndef __dng_big_table__ |
| 10 |
#define __dng_big_table__ |
| 11 |
|
| 12 |
/*****************************************************************************/ |
| 13 |
|
| 14 |
#include "dng_classes.h" |
| 15 |
#include "dng_camera_profile.h" |
| 16 |
#include "dng_rect.h" |
| 17 |
#include "dng_safe_arithmetic.h" |
| 18 |
#include "dng_semantic_mask.h" |
| 19 |
#include "dng_tag_types.h" |
| 20 |
#include "dng_tag_values.h" |
| 21 |
|
| 22 |
#include <map> |
| 23 |
#include <memory> |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
/*****************************************************************************/ |
| 27 |
|
| 28 |
void dng_big_table_cache_flush (); |
| 29 |
|
| 30 |
void dng_big_table_cache_clear (); |
| 31 |
|
| 32 |
/*****************************************************************************/ |
| 33 |
|
| 34 |
class dng_big_table |
| 35 |
{ |
| 36 |
|
| 37 |
protected: |
| 38 |
|
| 39 |
enum BigTableTypeEnum |
| 40 |
{ |
| 41 |
btt_LookTable = 0, |
| 42 |
btt_RGBTable = 1, |
| 43 |
btt_ImageTable = 2, |
| 44 |
btt_CompressedSettingsTable = 3, |
| 45 |
btt_UncompressedSettingsTable = 4, |
| 46 |
btt_PackedImageTable = 5, |
| 47 |
}; |
| 48 |
|
| 49 |
private: |
| 50 |
|
| 51 |
dng_fingerprint fFingerprint; |
| 52 |
|
| 53 |
dng_big_table_cache * fCache; |
| 54 |
|
| 55 |
bool fIsMissing; |
| 56 |
|
| 57 |
protected: |
| 58 |
|
| 59 |
dng_big_table (dng_big_table_cache *cache); |
| 60 |
|
| 61 |
dng_big_table (const dng_big_table &table); |
| 62 |
|
| 63 |
dng_big_table & operator= (const dng_big_table &table); |
| 64 |
|
| 65 |
public: |
| 66 |
|
| 67 |
virtual ~dng_big_table (); |
| 68 |
|
| 69 |
bool IsMissing () const |
| 70 |
{ |
| 71 |
return fIsMissing; |
| 72 |
} |
| 73 |
|
| 74 |
void SetMissing () |
| 75 |
{ |
| 76 |
fIsMissing = true; |
| 77 |
} |
| 78 |
|
| 79 |
bool IsEmbedNever () const |
| 80 |
{ |
| 81 |
return (GetFlags () & 1) != 0; |
| 82 |
} |
| 83 |
|
| 84 |
void SetEmbedNever () |
| 85 |
{ |
| 86 |
SetFlags (GetFlags () | 1); |
| 87 |
} |
| 88 |
|
| 89 |
virtual bool IsValid () const = 0; |
| 90 |
|
| 91 |
const dng_fingerprint & Fingerprint () const; |
| 92 |
|
| 93 |
bool DecodeFromBinary (dng_host &host, |
| 94 |
const uint8 * compressedData, |
| 95 |
uint32 compressedSize, |
| 96 |
AutoPtr<dng_memory_block> *uncompressedCache = nullptr); |
| 97 |
|
| 98 |
static void ASCIItoBinary (dng_memory_allocator &allocator, |
| 99 |
const char *sPtr, |
| 100 |
uint32 sCount, |
| 101 |
AutoPtr<dng_memory_block> &dBlock, |
| 102 |
uint32 &dCount); |
| 103 |
|
| 104 |
bool DecodeFromString (dng_host &host, |
| 105 |
const dng_string &block1); |
| 106 |
|
| 107 |
dng_memory_block * EncodeAsBinary (dng_memory_allocator &allocator, |
| 108 |
uint32 &compressedSize) const; |
| 109 |
|
| 110 |
dng_memory_block * EncodeAsString (dng_memory_allocator &allocator) const; |
| 111 |
|
| 112 |
bool ExtractFromCache (const dng_fingerprint &fingerprint); |
| 113 |
|
| 114 |
|
| 115 |
#if qDNGUseXMP |
| 116 |
|
| 117 |
bool ReadTableFromXMP (const dng_xmp &xmp, |
| 118 |
const char *ns, |
| 119 |
const dng_fingerprint &fingerprint, |
| 120 |
dng_big_table_storage *storage = nullptr, |
| 121 |
dng_abort_sniffer *sniffer = nullptr); |
| 122 |
|
| 123 |
bool ReadFromXMP (const dng_xmp &xmp, |
| 124 |
const char *ns, |
| 125 |
const char *path, |
| 126 |
dng_big_table_storage &storage, |
| 127 |
dng_abort_sniffer *sniffer = NULL); |
| 128 |
|
| 129 |
void WriteToXMP (dng_xmp &xmp, |
| 130 |
const char *ns, |
| 131 |
const char *path, |
| 132 |
dng_big_table_storage &storage) const; |
| 133 |
|
| 134 |
#endif // qDNGUseXMP |
| 135 |
|
| 136 |
#if qDNGValidate |
| 137 |
|
| 138 |
// Write uncompressed data to stream; intended for debugging. |
| 139 |
|
| 140 |
void WriteUncompressedStream (dng_stream &stream) const; |
| 141 |
|
| 142 |
#endif // qDNGValidate |
| 143 |
|
| 144 |
protected: |
| 145 |
|
| 146 |
virtual dng_fingerprint ComputeFingerprint () const; |
| 147 |
|
| 148 |
void RecomputeFingerprint (); |
| 149 |
|
| 150 |
virtual bool UseCompression () const |
| 151 |
{ |
| 152 |
return true; |
| 153 |
} |
| 154 |
|
| 155 |
virtual bool GetStream (dng_stream &stream) = 0; |
| 156 |
|
| 157 |
virtual void PutStream (dng_stream &stream, |
| 158 |
bool forFingerprint) const = 0; |
| 159 |
|
| 160 |
virtual uint32 GetFlags () const = 0; |
| 161 |
|
| 162 |
virtual void SetFlags (uint32 flags) = 0; |
| 163 |
|
| 164 |
}; |
| 165 |
|
| 166 |
/*****************************************************************************/ |
| 167 |
|
| 168 |
class dng_big_table_accessor |
| 169 |
{ |
| 170 |
|
| 171 |
public: |
| 172 |
|
| 173 |
dng_big_table_accessor () |
| 174 |
{ |
| 175 |
} |
| 176 |
|
| 177 |
virtual ~dng_big_table_accessor () |
| 178 |
{ |
| 179 |
} |
| 180 |
|
| 181 |
virtual bool HasTable (const dng_fingerprint & /* fingerprint */) const |
| 182 |
{ |
| 183 |
return false; |
| 184 |
} |
| 185 |
|
| 186 |
virtual bool GetTable (const dng_fingerprint & /* fingerprint */, |
| 187 |
dng_ref_counted_block & /* block */) const |
| 188 |
{ |
| 189 |
return false; |
| 190 |
} |
| 191 |
|
| 192 |
virtual void AddTable (const dng_fingerprint & /* fingerprint */, |
| 193 |
const dng_ref_counted_block & /* block */) |
| 194 |
{ |
| 195 |
ThrowProgramError ("AddTable not implemented"); |
| 196 |
} |
| 197 |
|
| 198 |
virtual void CopyToDictionary (dng_big_table_dictionary & /* dictionary */) const |
| 199 |
{ |
| 200 |
ThrowProgramError ("CopyToDictionary not implemented"); |
| 201 |
} |
| 202 |
|
| 203 |
virtual bool GroupToInstance (const dng_fingerprint & /* groupDigest */, |
| 204 |
dng_fingerprint & /* instanceDigest */) const |
| 205 |
{ |
| 206 |
return false; |
| 207 |
} |
| 208 |
|
| 209 |
}; |
| 210 |
|
| 211 |
/*****************************************************************************/ |
| 212 |
|
| 213 |
class dng_big_table_dictionary : public dng_big_table_accessor |
| 214 |
{ |
| 215 |
|
| 216 |
private: |
| 217 |
|
| 218 |
std::map<dng_fingerprint, dng_ref_counted_block> fMap; |
| 219 |
|
| 220 |
public: |
| 221 |
|
| 222 |
const std::map<dng_fingerprint, dng_ref_counted_block> & Map () const |
| 223 |
{ |
| 224 |
return fMap; |
| 225 |
} |
| 226 |
|
| 227 |
bool IsEmpty () const |
| 228 |
{ |
| 229 |
return fMap.empty (); |
| 230 |
} |
| 231 |
|
| 232 |
virtual bool HasTable (const dng_fingerprint &fingerprint) const; |
| 233 |
|
| 234 |
virtual bool GetTable (const dng_fingerprint &fingerprint, |
| 235 |
dng_ref_counted_block &block) const; |
| 236 |
|
| 237 |
virtual void AddTable (const dng_fingerprint &fingerprint, |
| 238 |
const dng_ref_counted_block &block); |
| 239 |
|
| 240 |
virtual void CopyToDictionary (dng_big_table_dictionary & /* dictionary */) const; |
| 241 |
|
| 242 |
}; |
| 243 |
|
| 244 |
/*****************************************************************************/ |
| 245 |
|
| 246 |
class dng_big_table_index |
| 247 |
{ |
| 248 |
|
| 249 |
public: |
| 250 |
|
| 251 |
struct IndexEntry |
| 252 |
{ |
| 253 |
uint32 fTableSize; |
| 254 |
uint64 fTableOffset; |
| 255 |
}; |
| 256 |
|
| 257 |
private: |
| 258 |
|
| 259 |
std::map<dng_fingerprint, IndexEntry> fMap; |
| 260 |
|
| 261 |
public: |
| 262 |
|
| 263 |
dng_big_table_index (); |
| 264 |
|
| 265 |
bool IsEmpty () const |
| 266 |
{ |
| 267 |
return fMap.empty (); |
| 268 |
} |
| 269 |
|
| 270 |
const std::map<dng_fingerprint, IndexEntry> & Map () const |
| 271 |
{ |
| 272 |
return fMap; |
| 273 |
} |
| 274 |
|
| 275 |
bool HasEntry (const dng_fingerprint &fingerprint) const; |
| 276 |
|
| 277 |
bool GetEntry (const dng_fingerprint &fingerprint, |
| 278 |
uint32 &tableSize, |
| 279 |
uint64 &tableOffset) const; |
| 280 |
|
| 281 |
void AddEntry (const dng_fingerprint &fingerprint, |
| 282 |
uint32 tableSize, |
| 283 |
uint64 tableOffset); |
| 284 |
|
| 285 |
}; |
| 286 |
|
| 287 |
/*****************************************************************************/ |
| 288 |
|
| 289 |
class dng_big_table_group_index |
| 290 |
{ |
| 291 |
|
| 292 |
private: |
| 293 |
|
| 294 |
std::map<dng_fingerprint, // group digest |
| 295 |
dng_fingerprint> fMap; // instance digest |
| 296 |
|
| 297 |
public: |
| 298 |
|
| 299 |
bool IsEmpty () const |
| 300 |
{ |
| 301 |
return fMap.empty (); |
| 302 |
} |
| 303 |
|
| 304 |
const std::map<dng_fingerprint, |
| 305 |
dng_fingerprint> & Map () const |
| 306 |
{ |
| 307 |
return fMap; |
| 308 |
} |
| 309 |
|
| 310 |
bool HasEntry (const dng_fingerprint &groupDigest) const |
| 311 |
{ |
| 312 |
return fMap.find (groupDigest) != fMap.end (); |
| 313 |
} |
| 314 |
|
| 315 |
bool GetEntry (const dng_fingerprint &groupDigest, |
| 316 |
dng_fingerprint &instanceDigest) const; |
| 317 |
|
| 318 |
void AddEntry (const dng_fingerprint &groupDigest, |
| 319 |
const dng_fingerprint &instanceDigest) |
| 320 |
{ |
| 321 |
if (fMap.find (groupDigest) == fMap.end ()) |
| 322 |
fMap.insert (std::make_pair (groupDigest, |
| 323 |
instanceDigest)); |
| 324 |
} |
| 325 |
|
| 326 |
}; |
| 327 |
|
| 328 |
/*****************************************************************************/ |
| 329 |
|
| 330 |
class dng_big_table_storage |
| 331 |
{ |
| 332 |
|
| 333 |
public: |
| 334 |
|
| 335 |
dng_big_table_storage (); |
| 336 |
|
| 337 |
virtual ~dng_big_table_storage (); |
| 338 |
|
| 339 |
virtual bool ReadTable (dng_big_table &table, |
| 340 |
const dng_fingerprint &fingerprint, |
| 341 |
dng_memory_allocator &allocator); |
| 342 |
|
| 343 |
virtual bool WriteTable (const dng_big_table &table, |
| 344 |
const dng_fingerprint &fingerprint, |
| 345 |
dng_memory_allocator &allocator); |
| 346 |
|
| 347 |
virtual void MissingTable (const dng_fingerprint &fingerprint); |
| 348 |
|
| 349 |
virtual bool GroupToInstance (const dng_fingerprint &groupDigest, |
| 350 |
dng_fingerprint &instanceDigest) const; |
| 351 |
|
| 352 |
}; |
| 353 |
|
| 354 |
/*****************************************************************************/ |
| 355 |
|
| 356 |
class dng_look_table : public dng_big_table |
| 357 |
{ |
| 358 |
|
| 359 |
friend class dng_look_table_cache; |
| 360 |
|
| 361 |
public: |
| 362 |
|
| 363 |
enum |
| 364 |
{ |
| 365 |
|
| 366 |
// Tables are are allowed to trade off resolution |
| 367 |
// between dimensions, but need to keep total |
| 368 |
// samples below this limit. This results in |
| 369 |
// 216K memory footprint (12 byte per sample) |
| 370 |
// which is similar in size to the RGB table |
| 371 |
// size limit. |
| 372 |
|
| 373 |
kMaxTotalSamples = 36 * 32 * 16, |
| 374 |
|
| 375 |
// Also each must be within their own limits. |
| 376 |
|
| 377 |
kMaxHueSamples = 360, |
| 378 |
kMaxSatSamples = 256, |
| 379 |
kMaxValSamples = 256 |
| 380 |
|
| 381 |
}; |
| 382 |
|
| 383 |
private: |
| 384 |
|
| 385 |
enum |
| 386 |
{ |
| 387 |
kLookTableVersion1 = 1, |
| 388 |
kLookTableVersion2 = 2 |
| 389 |
}; |
| 390 |
|
| 391 |
// Table data affecting fingerprint and caching. |
| 392 |
|
| 393 |
struct table_data |
| 394 |
{ |
| 395 |
|
| 396 |
// 3-D hue/sat table to apply a "look". |
| 397 |
|
| 398 |
dng_hue_sat_map fMap; |
| 399 |
|
| 400 |
// Value (V of HSV) encoding for look table. |
| 401 |
|
| 402 |
uint32 fEncoding; |
| 403 |
|
| 404 |
// Minimum and maximum scale amounts supported by table. |
| 405 |
|
| 406 |
real64 fMinAmount; |
| 407 |
real64 fMaxAmount; |
| 408 |
|
| 409 |
// Does this table have only monochrome output (when amount is 1.0)? |
| 410 |
|
| 411 |
bool fMonochrome; |
| 412 |
|
| 413 |
// Flags. |
| 414 |
|
| 415 |
uint32 fFlags; |
| 416 |
|
| 417 |
// Constructor to set defaults. |
| 418 |
|
| 419 |
table_data () |
| 420 |
|
| 421 |
: fMap () |
| 422 |
, fEncoding (encoding_Linear) |
| 423 |
, fMinAmount (1.0) |
| 424 |
, fMaxAmount (1.0) |
| 425 |
, fMonochrome (false) |
| 426 |
, fFlags (0) |
| 427 |
|
| 428 |
{ |
| 429 |
} |
| 430 |
|
| 431 |
// Compute monchrome flag. |
| 432 |
|
| 433 |
void ComputeMonochrome () |
| 434 |
{ |
| 435 |
|
| 436 |
fMonochrome = true; |
| 437 |
|
| 438 |
uint32 count = fMap.DeltasCount (); |
| 439 |
|
| 440 |
dng_hue_sat_map::HSBModify * deltas = fMap.GetDeltas (); |
| 441 |
|
| 442 |
for (uint32 index = 0; index < count; index++) |
| 443 |
{ |
| 444 |
|
| 445 |
if (deltas [index] . fSatScale != 0.0f) |
| 446 |
{ |
| 447 |
|
| 448 |
fMonochrome = false; |
| 449 |
|
| 450 |
return; |
| 451 |
|
| 452 |
} |
| 453 |
|
| 454 |
} |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
}; |
| 459 |
|
| 460 |
table_data fData; |
| 461 |
|
| 462 |
// Amount to apply at runtime (does not affect fingerprint). |
| 463 |
|
| 464 |
real64 fAmount; |
| 465 |
|
| 466 |
public: |
| 467 |
|
| 468 |
dng_look_table (); |
| 469 |
|
| 470 |
dng_look_table (const dng_look_table &table); |
| 471 |
|
| 472 |
dng_look_table & operator= (const dng_look_table &table); |
| 473 |
|
| 474 |
virtual ~dng_look_table (); |
| 475 |
|
| 476 |
bool operator== (const dng_look_table &table) const |
| 477 |
{ |
| 478 |
return Fingerprint () == table.Fingerprint () && |
| 479 |
Amount () == table.Amount () && |
| 480 |
IsMissing () == table.IsMissing (); |
| 481 |
} |
| 482 |
|
| 483 |
bool operator!= (const dng_look_table &table) const |
| 484 |
{ |
| 485 |
return !(*this == table); |
| 486 |
} |
| 487 |
|
| 488 |
void Set (const dng_hue_sat_map &map, |
| 489 |
uint32 encoding); |
| 490 |
|
| 491 |
virtual bool IsValid () const; |
| 492 |
|
| 493 |
void SetInvalid (); |
| 494 |
|
| 495 |
real64 MinAmount () const |
| 496 |
{ |
| 497 |
return fData.fMinAmount; |
| 498 |
} |
| 499 |
|
| 500 |
real64 MaxAmount () const |
| 501 |
{ |
| 502 |
return fData.fMaxAmount; |
| 503 |
} |
| 504 |
|
| 505 |
void SetAmountRange (real64 minAmount, |
| 506 |
real64 maxAmount) |
| 507 |
{ |
| 508 |
|
| 509 |
fData.fMinAmount = Pin_real64 (0.0, |
| 510 |
Round_int32 (minAmount * 100.0) * 0.01, |
| 511 |
1.0); |
| 512 |
|
| 513 |
fData.fMaxAmount = Pin_real64 (1.0, |
| 514 |
Round_int32 (maxAmount * 100.0) * 0.01, |
| 515 |
2.0); |
| 516 |
|
| 517 |
fAmount = Pin_real64 (fData.fMinAmount, fAmount, fData.fMaxAmount); |
| 518 |
|
| 519 |
RecomputeFingerprint (); |
| 520 |
|
| 521 |
} |
| 522 |
|
| 523 |
real64 Amount () const |
| 524 |
{ |
| 525 |
return fAmount; |
| 526 |
} |
| 527 |
|
| 528 |
void SetAmount (real64 amount) |
| 529 |
{ |
| 530 |
|
| 531 |
fAmount = Pin_real64 (fData.fMinAmount, |
| 532 |
Round_int32 (amount * 100.0) * 0.01, |
| 533 |
fData.fMaxAmount); |
| 534 |
|
| 535 |
// Not part of fingerprint. |
| 536 |
|
| 537 |
} |
| 538 |
|
| 539 |
const dng_hue_sat_map & Map () const |
| 540 |
{ |
| 541 |
return fData.fMap; |
| 542 |
} |
| 543 |
|
| 544 |
uint32 Encoding () const |
| 545 |
{ |
| 546 |
return fData.fEncoding; |
| 547 |
} |
| 548 |
|
| 549 |
bool Monochrome () const |
| 550 |
{ |
| 551 |
return IsValid () && fAmount == 1.0 && fData.fMonochrome; |
| 552 |
} |
| 553 |
|
| 554 |
protected: |
| 555 |
|
| 556 |
virtual bool GetStream (dng_stream &stream); |
| 557 |
|
| 558 |
virtual void PutStream (dng_stream &stream, |
| 559 |
bool forFingerprint) const; |
| 560 |
|
| 561 |
virtual uint32 GetFlags () const |
| 562 |
{ |
| 563 |
return fData.fFlags; |
| 564 |
} |
| 565 |
|
| 566 |
virtual void SetFlags (uint32 flags) |
| 567 |
{ |
| 568 |
|
| 569 |
fData.fFlags = flags; |
| 570 |
|
| 571 |
RecomputeFingerprint (); |
| 572 |
|
| 573 |
} |
| 574 |
|
| 575 |
}; |
| 576 |
|
| 577 |
/*****************************************************************************/ |
| 578 |
|
| 579 |
class dng_rgb_table : public dng_big_table |
| 580 |
{ |
| 581 |
|
| 582 |
friend class dng_rgb_table_cache; |
| 583 |
|
| 584 |
public: |
| 585 |
|
| 586 |
enum |
| 587 |
{ |
| 588 |
|
| 589 |
kMinDivisions1D = 2, |
| 590 |
kMaxDivisions1D = 4096, |
| 591 |
|
| 592 |
kMinDivisions3D = 2, |
| 593 |
kMaxDivisions3D = 32, |
| 594 |
|
| 595 |
kMaxDivisions3D_InMemory = 130 |
| 596 |
|
| 597 |
}; |
| 598 |
|
| 599 |
enum primaries_enum |
| 600 |
{ |
| 601 |
|
| 602 |
primaries_sRGB = 0, |
| 603 |
primaries_Adobe, |
| 604 |
primaries_ProPhoto, |
| 605 |
primaries_P3, |
| 606 |
primaries_Rec2020, |
| 607 |
|
| 608 |
primaries_count |
| 609 |
|
| 610 |
}; |
| 611 |
|
| 612 |
enum gamma_enum |
| 613 |
{ |
| 614 |
|
| 615 |
gamma_Linear = 0, |
| 616 |
gamma_sRGB, |
| 617 |
gamma_1_8, |
| 618 |
gamma_2_2, |
| 619 |
gamma_Rec2020, |
| 620 |
|
| 621 |
gamma_count |
| 622 |
|
| 623 |
}; |
| 624 |
|
| 625 |
enum gamut_enum |
| 626 |
{ |
| 627 |
|
| 628 |
gamut_clip = 0, |
| 629 |
gamut_extend, |
| 630 |
|
| 631 |
gamut_count |
| 632 |
|
| 633 |
}; |
| 634 |
|
| 635 |
private: |
| 636 |
|
| 637 |
enum |
| 638 |
{ |
| 639 |
kRGBTableVersion = 1 |
| 640 |
}; |
| 641 |
|
| 642 |
// Table data affecting fingerprint and caching. |
| 643 |
|
| 644 |
struct table_data |
| 645 |
{ |
| 646 |
|
| 647 |
// Number of dimensions of the table (1 or 3). |
| 648 |
|
| 649 |
uint32 fDimensions; |
| 650 |
|
| 651 |
// Number of samples per side of table. |
| 652 |
|
| 653 |
uint32 fDivisions; |
| 654 |
|
| 655 |
// Sample data. 16-bit unsigned encoding. |
| 656 |
// Right zero padded to 64 bits per sample (i.e. RGB0). |
| 657 |
|
| 658 |
dng_ref_counted_block fSamples; |
| 659 |
|
| 660 |
// Color primaries for table. |
| 661 |
|
| 662 |
primaries_enum fPrimaries; |
| 663 |
|
| 664 |
// Gamma encoding for table. |
| 665 |
|
| 666 |
gamma_enum fGamma; |
| 667 |
|
| 668 |
// Gamut processing option for table. |
| 669 |
|
| 670 |
gamut_enum fGamut; |
| 671 |
|
| 672 |
// Minimum and maximum scale amounts supported by table. |
| 673 |
|
| 674 |
real64 fMinAmount; |
| 675 |
real64 fMaxAmount; |
| 676 |
|
| 677 |
// Does this table have only monochrome output (when amount is 1.0)? |
| 678 |
|
| 679 |
bool fMonochrome; |
| 680 |
|
| 681 |
// Flags. |
| 682 |
|
| 683 |
uint32 fFlags; |
| 684 |
|
| 685 |
// Constructor to set defaults. |
| 686 |
|
| 687 |
table_data () |
| 688 |
|
| 689 |
: fDimensions (0) |
| 690 |
, fDivisions (0) |
| 691 |
, fSamples () |
| 692 |
, fPrimaries (primaries_sRGB) |
| 693 |
, fGamma (gamma_sRGB) |
| 694 |
, fGamut (gamut_clip) |
| 695 |
, fMinAmount (0.0) |
| 696 |
, fMaxAmount (2.0) |
| 697 |
, fMonochrome (false) |
| 698 |
, fFlags (0) |
| 699 |
|
| 700 |
{ |
| 701 |
} |
| 702 |
|
| 703 |
// Compute monchrome flag. |
| 704 |
|
| 705 |
void ComputeMonochrome () |
| 706 |
{ |
| 707 |
|
| 708 |
if (fPrimaries != primaries_ProPhoto && |
| 709 |
fGamut != gamut_clip) |
| 710 |
{ |
| 711 |
|
| 712 |
fMonochrome = false; |
| 713 |
|
| 714 |
return; |
| 715 |
|
| 716 |
} |
| 717 |
|
| 718 |
if (fDimensions != 3) |
| 719 |
{ |
| 720 |
|
| 721 |
fMonochrome = false; |
| 722 |
|
| 723 |
return; |
| 724 |
|
| 725 |
} |
| 726 |
|
| 727 |
fMonochrome = true; |
| 728 |
|
| 729 |
uint32 count = fDivisions * fDivisions * fDivisions; |
| 730 |
|
| 731 |
const uint16 * sample = fSamples.Buffer_uint16 (); |
| 732 |
|
| 733 |
for (uint32 index = 0; index < count; index++) |
| 734 |
{ |
| 735 |
|
| 736 |
if (sample [0] != sample [1] || |
| 737 |
sample [0] != sample [2]) |
| 738 |
{ |
| 739 |
|
| 740 |
fMonochrome = false; |
| 741 |
|
| 742 |
return; |
| 743 |
|
| 744 |
} |
| 745 |
|
| 746 |
sample += 4; |
| 747 |
|
| 748 |
} |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
}; |
| 753 |
|
| 754 |
table_data fData; |
| 755 |
|
| 756 |
// Amount to apply at runtime (does not affect fingerprint). |
| 757 |
|
| 758 |
real64 fAmount; |
| 759 |
|
| 760 |
public: |
| 761 |
|
| 762 |
dng_rgb_table (); |
| 763 |
|
| 764 |
dng_rgb_table (const dng_rgb_table &table); |
| 765 |
|
| 766 |
dng_rgb_table & operator= (const dng_rgb_table &table); |
| 767 |
|
| 768 |
virtual ~dng_rgb_table (); |
| 769 |
|
| 770 |
bool operator== (const dng_rgb_table &table) const |
| 771 |
{ |
| 772 |
return Fingerprint () == table.Fingerprint () && |
| 773 |
Amount () == table.Amount () && |
| 774 |
IsMissing () == table.IsMissing (); |
| 775 |
} |
| 776 |
|
| 777 |
bool operator!= (const dng_rgb_table &table) const |
| 778 |
{ |
| 779 |
return !(*this == table); |
| 780 |
} |
| 781 |
|
| 782 |
virtual bool IsValid () const; |
| 783 |
|
| 784 |
void SetInvalid (); |
| 785 |
|
| 786 |
primaries_enum Primaries () const |
| 787 |
{ |
| 788 |
return fData.fPrimaries; |
| 789 |
} |
| 790 |
|
| 791 |
void SetPrimaries (primaries_enum primaries) |
| 792 |
{ |
| 793 |
|
| 794 |
fData.fPrimaries = primaries; |
| 795 |
|
| 796 |
fData.ComputeMonochrome (); |
| 797 |
|
| 798 |
RecomputeFingerprint (); |
| 799 |
|
| 800 |
} |
| 801 |
|
| 802 |
gamma_enum Gamma () const |
| 803 |
{ |
| 804 |
return fData.fGamma; |
| 805 |
} |
| 806 |
|
| 807 |
void SetGamma (gamma_enum gamma) |
| 808 |
{ |
| 809 |
|
| 810 |
fData.fGamma = gamma; |
| 811 |
|
| 812 |
RecomputeFingerprint (); |
| 813 |
|
| 814 |
} |
| 815 |
|
| 816 |
gamut_enum Gamut () const |
| 817 |
{ |
| 818 |
return fData.fGamut; |
| 819 |
} |
| 820 |
|
| 821 |
void SetGamut (gamut_enum gamut) |
| 822 |
{ |
| 823 |
|
| 824 |
fData.fGamut = gamut; |
| 825 |
|
| 826 |
fData.ComputeMonochrome (); |
| 827 |
|
| 828 |
RecomputeFingerprint (); |
| 829 |
|
| 830 |
} |
| 831 |
|
| 832 |
real64 MinAmount () const |
| 833 |
{ |
| 834 |
return fData.fMinAmount; |
| 835 |
} |
| 836 |
|
| 837 |
real64 MaxAmount () const |
| 838 |
{ |
| 839 |
return fData.fMaxAmount; |
| 840 |
} |
| 841 |
|
| 842 |
void SetAmountRange (real64 minAmount, |
| 843 |
real64 maxAmount) |
| 844 |
{ |
| 845 |
|
| 846 |
fData.fMinAmount = Pin_real64 (0.0, |
| 847 |
Round_int32 (minAmount * 100.0) * 0.01, |
| 848 |
1.0); |
| 849 |
|
| 850 |
fData.fMaxAmount = Pin_real64 (1.0, |
| 851 |
Round_int32 (maxAmount * 100.0) * 0.01, |
| 852 |
2.0); |
| 853 |
|
| 854 |
fAmount = Pin_real64 (fData.fMinAmount, fAmount, fData.fMaxAmount); |
| 855 |
|
| 856 |
RecomputeFingerprint (); |
| 857 |
|
| 858 |
} |
| 859 |
|
| 860 |
real64 Amount () const |
| 861 |
{ |
| 862 |
return fAmount; |
| 863 |
} |
| 864 |
|
| 865 |
void SetAmount (real64 amount) |
| 866 |
{ |
| 867 |
|
| 868 |
fAmount = Pin_real64 (fData.fMinAmount, |
| 869 |
Round_int32 (amount * 100.0) * 0.01, |
| 870 |
fData.fMaxAmount); |
| 871 |
|
| 872 |
// Not part of fingerprint. |
| 873 |
|
| 874 |
} |
| 875 |
|
| 876 |
uint32 Dimensions () const |
| 877 |
{ |
| 878 |
return fData.fDimensions; |
| 879 |
} |
| 880 |
|
| 881 |
uint32 Divisions () const |
| 882 |
{ |
| 883 |
return fData.fDivisions; |
| 884 |
} |
| 885 |
|
| 886 |
const uint16 * Samples () const |
| 887 |
{ |
| 888 |
return fData.fSamples.Buffer_uint16 (); |
| 889 |
} |
| 890 |
|
| 891 |
bool Monochrome () const |
| 892 |
{ |
| 893 |
return IsValid () && fAmount == 1.0 && fData.fMonochrome; |
| 894 |
} |
| 895 |
|
| 896 |
void Set (uint32 dimensions, |
| 897 |
uint32 divisions, |
| 898 |
dng_ref_counted_block samples); |
| 899 |
|
| 900 |
protected: |
| 901 |
|
| 902 |
virtual bool GetStream (dng_stream &stream); |
| 903 |
|
| 904 |
virtual void PutStream (dng_stream &stream, |
| 905 |
bool forFingerprint) const; |
| 906 |
|
| 907 |
virtual uint32 GetFlags () const |
| 908 |
{ |
| 909 |
return fData.fFlags; |
| 910 |
} |
| 911 |
|
| 912 |
virtual void SetFlags (uint32 flags) |
| 913 |
{ |
| 914 |
|
| 915 |
fData.fFlags = flags; |
| 916 |
|
| 917 |
RecomputeFingerprint (); |
| 918 |
|
| 919 |
} |
| 920 |
|
| 921 |
}; |
| 922 |
|
| 923 |
/*****************************************************************************/ |
| 924 |
|
| 925 |
// Compression info for image tables. This base class implementation uses |
| 926 |
// Lossless JPEG for integer data and Deflate for floating-point data. |
| 927 |
|
| 928 |
class dng_image_table_compression_info |
| 929 |
{ |
| 930 |
|
| 931 |
public: |
| 932 |
|
| 933 |
virtual ~dng_image_table_compression_info (); |
| 934 |
|
| 935 |
virtual uint32 Type () const |
| 936 |
{ |
| 937 |
return 0; |
| 938 |
} |
| 939 |
|
| 940 |
virtual void Compress (dng_host &host, |
| 941 |
dng_stream &stream, |
| 942 |
const dng_image &image) const; |
| 943 |
|
| 944 |
}; |
| 945 |
|
| 946 |
/*****************************************************************************/ |
| 947 |
|
| 948 |
// This subclass uses JPEG XL to compress image tables. |
| 949 |
|
| 950 |
class dng_image_table_jxl_compression_info : public dng_image_table_compression_info |
| 951 |
{ |
| 952 |
|
| 953 |
public: |
| 954 |
|
| 955 |
AutoPtr<dng_jxl_encode_settings> fEncodeSettings; |
| 956 |
|
| 957 |
std::shared_ptr<const dng_jxl_color_space_info> fColorSpaceInfo; |
| 958 |
|
| 959 |
// If true, then write floating-point image tables using fp16 instead |
| 960 |
// of fp32. This field is ignored for integer images. |
| 961 |
|
| 962 |
bool fPreferHalfFloat = true; |
| 963 |
|
| 964 |
public: |
| 965 |
|
| 966 |
dng_image_table_jxl_compression_info (); |
| 967 |
|
| 968 |
uint32 Type () const override |
| 969 |
{ |
| 970 |
return ccJXL; |
| 971 |
} |
| 972 |
|
| 973 |
void Compress (dng_host &host, |
| 974 |
dng_stream &stream, |
| 975 |
const dng_image &image) const override; |
| 976 |
|
| 977 |
}; |
| 978 |
|
| 979 |
/*****************************************************************************/ |
| 980 |
|
| 981 |
class dng_image_table_data |
| 982 |
{ |
| 983 |
|
| 984 |
public: |
| 985 |
|
| 986 |
std::shared_ptr<const dng_image> fImage; |
| 987 |
|
| 988 |
mutable std::shared_ptr<const dng_memory_block> fCompressedData; |
| 989 |
|
| 990 |
uint32 fCompressionType = 0; |
| 991 |
|
| 992 |
}; |
| 993 |
|
| 994 |
/*****************************************************************************/ |
| 995 |
|
| 996 |
class dng_image_table : public dng_big_table |
| 997 |
{ |
| 998 |
|
| 999 |
friend class dng_image_table_cache; |
| 1000 |
friend class dng_packed_image_table_cache; |
| 1001 |
|
| 1002 |
private: |
| 1003 |
|
| 1004 |
enum |
| 1005 |
{ |
| 1006 |
kImageTableVersion = 1 |
| 1007 |
}; |
| 1008 |
|
| 1009 |
protected: |
| 1010 |
|
| 1011 |
std::shared_ptr<const dng_image> fImage; |
| 1012 |
|
| 1013 |
// For lossy-compressed big table data, we store a copy of the |
| 1014 |
// compressed data to avoid round-trip errors. |
| 1015 |
|
| 1016 |
mutable std::shared_ptr<const dng_memory_block> fCompressedData; |
| 1017 |
|
| 1018 |
// Compression type -- for information/debugging purposes only. |
| 1019 |
|
| 1020 |
uint32 fCompressionType = 0; |
| 1021 |
|
| 1022 |
public: |
| 1023 |
|
| 1024 |
dng_image_table (); |
| 1025 |
|
| 1026 |
dng_image_table (const dng_image_table &table); |
| 1027 |
|
| 1028 |
dng_image_table & operator= (const dng_image_table &table); |
| 1029 |
|
| 1030 |
virtual ~dng_image_table (); |
| 1031 |
|
| 1032 |
virtual bool IsValid () const; |
| 1033 |
|
| 1034 |
void SetInvalid (); |
| 1035 |
|
| 1036 |
bool operator== (const dng_image_table &table) const |
| 1037 |
{ |
| 1038 |
return Fingerprint () == table.Fingerprint () && |
| 1039 |
IsMissing () == table.IsMissing (); |
| 1040 |
} |
| 1041 |
|
| 1042 |
bool operator!= (const dng_image_table &table) const |
| 1043 |
{ |
| 1044 |
return !(*this == table); |
| 1045 |
} |
| 1046 |
|
| 1047 |
const dng_image & Image () const |
| 1048 |
{ |
| 1049 |
return *fImage; |
| 1050 |
} |
| 1051 |
|
| 1052 |
std::shared_ptr<const dng_image> ShareImage () const |
| 1053 |
{ |
| 1054 |
return fImage; |
| 1055 |
}; |
| 1056 |
|
| 1057 |
void SetImage (const dng_image *image, |
| 1058 |
const dng_image_table_compression_info *compressionInfo = nullptr, |
| 1059 |
dng_abort_sniffer *sniffer = nullptr); |
| 1060 |
|
| 1061 |
void SetImage (const std::shared_ptr<const dng_image> &image, |
| 1062 |
const dng_image_table_compression_info *compressionInfo = nullptr, |
| 1063 |
dng_abort_sniffer *sniffer = nullptr); |
| 1064 |
|
| 1065 |
uint32 CompressionType () const |
| 1066 |
{ |
| 1067 |
return fCompressionType; |
| 1068 |
} |
| 1069 |
|
| 1070 |
std::shared_ptr<const dng_memory_block> CompressedData () const |
| 1071 |
{ |
| 1072 |
return fCompressedData; |
| 1073 |
} |
| 1074 |
|
| 1075 |
private: |
| 1076 |
|
| 1077 |
void SetData (const dng_image_table_data &data); |
| 1078 |
|
| 1079 |
void GetData (dng_image_table_data &data) const; |
| 1080 |
|
| 1081 |
protected: |
| 1082 |
|
| 1083 |
virtual dng_host * MakeHost (dng_abort_sniffer *sniffer) const; |
| 1084 |
|
| 1085 |
virtual dng_fingerprint ComputeFingerprint () const; |
| 1086 |
|
| 1087 |
// dng_image_table uses its own (internal) compression method |
| 1088 |
// optimized for image content, e.g., ccDeflate or ccJXL, and |
| 1089 |
// therefore does not use the general, external compression method |
| 1090 |
// provided by the base class. |
| 1091 |
|
| 1092 |
virtual bool UseCompression () const |
| 1093 |
{ |
| 1094 |
return false; |
| 1095 |
} |
| 1096 |
|
| 1097 |
virtual bool GetStream (dng_stream &stream); |
| 1098 |
|
| 1099 |
virtual void PutStream (dng_stream &stream, |
| 1100 |
bool forFingerprint) const; |
| 1101 |
|
| 1102 |
virtual uint32 GetFlags () const |
| 1103 |
{ |
| 1104 |
return 0; |
| 1105 |
} |
| 1106 |
|
| 1107 |
virtual void SetFlags (uint32 /* flags */) |
| 1108 |
{ |
| 1109 |
} |
| 1110 |
|
| 1111 |
virtual void CompressImage (const dng_image_table_compression_info &info, |
| 1112 |
dng_abort_sniffer *sniffer); |
| 1113 |
|
| 1114 |
protected: |
| 1115 |
|
| 1116 |
virtual void |
| 1117 |
PutCompressedStream (dng_stream &stream, |
| 1118 |
bool forFingerprint, |
| 1119 |
const dng_image_table_compression_info &info) const; |
| 1120 |
|
| 1121 |
}; |
| 1122 |
|
| 1123 |
/*****************************************************************************/ |
| 1124 |
|
| 1125 |
// A packed (opaque) image table. Reading the table will obtain only the |
| 1126 |
// (compressed) bytes but does not perform any decompression until Unpack is |
| 1127 |
// called. |
| 1128 |
|
| 1129 |
class dng_packed_image_table : public dng_big_table |
| 1130 |
{ |
| 1131 |
|
| 1132 |
friend class dng_packed_image_table_cache; |
| 1133 |
|
| 1134 |
private: |
| 1135 |
|
| 1136 |
enum |
| 1137 |
{ |
| 1138 |
kPackedImageTableVersion = 2 |
| 1139 |
}; |
| 1140 |
|
| 1141 |
protected: |
| 1142 |
|
| 1143 |
// Digest of the image table. |
| 1144 |
|
| 1145 |
dng_fingerprint fTableDigest; |
| 1146 |
|
| 1147 |
// The unpacked / concrete image table. |
| 1148 |
|
| 1149 |
std::unique_ptr<dng_image_table> fTable; |
| 1150 |
|
| 1151 |
// The packed / opaque image table. |
| 1152 |
|
| 1153 |
std::shared_ptr<const dng_memory_block> fBlock; |
| 1154 |
|
| 1155 |
// Image properties. |
| 1156 |
|
| 1157 |
dng_point fSize; |
| 1158 |
|
| 1159 |
uint32 fPlanes = 0; |
| 1160 |
|
| 1161 |
uint32 fPixelType = 0; |
| 1162 |
|
| 1163 |
public: |
| 1164 |
|
| 1165 |
dng_packed_image_table (); |
| 1166 |
|
| 1167 |
dng_packed_image_table (const dng_packed_image_table &table); |
| 1168 |
|
| 1169 |
dng_packed_image_table & operator= (const dng_packed_image_table &table); |
| 1170 |
|
| 1171 |
public: |
| 1172 |
|
| 1173 |
const dng_image_table & Table () const; |
| 1174 |
|
| 1175 |
const dng_image & Image () const |
| 1176 |
{ |
| 1177 |
return Table ().Image (); |
| 1178 |
} |
| 1179 |
|
| 1180 |
const_dng_image_sptr ShareImage () const |
| 1181 |
{ |
| 1182 |
return fTable ? fTable->ShareImage () : nullptr; |
| 1183 |
} |
| 1184 |
|
| 1185 |
std::shared_ptr<const dng_memory_block> ShareBlock () const |
| 1186 |
{ |
| 1187 |
return fBlock; |
| 1188 |
} |
| 1189 |
|
| 1190 |
bool IsValid () const override; |
| 1191 |
|
| 1192 |
bool HasTable () const |
| 1193 |
{ |
| 1194 |
return fTable && fTable->IsValid (); |
| 1195 |
} |
| 1196 |
|
| 1197 |
bool IsValidUnpacked () const |
| 1198 |
{ |
| 1199 |
return HasTable (); |
| 1200 |
} |
| 1201 |
|
| 1202 |
bool IsPacked () const |
| 1203 |
{ |
| 1204 |
return fBlock != nullptr; |
| 1205 |
} |
| 1206 |
|
| 1207 |
// The image data is already compressed internally, so we do not want |
| 1208 |
// the overall big table logic perform any additional compression. |
| 1209 |
|
| 1210 |
bool UseCompression () const override |
| 1211 |
{ |
| 1212 |
return false; |
| 1213 |
} |
| 1214 |
|
| 1215 |
uint32 PackedBytes () const; |
| 1216 |
|
| 1217 |
// Info about the image. This is available even if the table is packed. |
| 1218 |
|
| 1219 |
const dng_point & Size () const |
| 1220 |
{ |
| 1221 |
return fSize; |
| 1222 |
} |
| 1223 |
|
| 1224 |
uint32 Planes () const |
| 1225 |
{ |
| 1226 |
return fPlanes; |
| 1227 |
} |
| 1228 |
|
| 1229 |
uint32 PixelType () const |
| 1230 |
{ |
| 1231 |
return fPixelType; |
| 1232 |
} |
| 1233 |
|
| 1234 |
public: |
| 1235 |
|
| 1236 |
bool operator== (const dng_packed_image_table &table) const |
| 1237 |
{ |
| 1238 |
return (Fingerprint () == table.Fingerprint () && |
| 1239 |
IsMissing () == table.IsMissing ()); |
| 1240 |
} |
| 1241 |
|
| 1242 |
bool operator!= (const dng_packed_image_table &table) const |
| 1243 |
{ |
| 1244 |
return !(*this == table); |
| 1245 |
} |
| 1246 |
|
| 1247 |
public: |
| 1248 |
|
| 1249 |
// Factory methods. |
| 1250 |
|
| 1251 |
virtual dng_host * MakeHost (dng_abort_sniffer *sniffer) const; |
| 1252 |
|
| 1253 |
virtual dng_image_table * MakeTable () const; |
| 1254 |
|
| 1255 |
virtual dng_image_table * CloneTable () const; |
| 1256 |
|
| 1257 |
public: |
| 1258 |
|
| 1259 |
void Clear (); |
| 1260 |
|
| 1261 |
void ClearPackedData (); |
| 1262 |
|
| 1263 |
void SetImage (const dng_image *image, |
| 1264 |
const dng_image_table_compression_info *compressionInfo = nullptr, |
| 1265 |
dng_abort_sniffer *sniffer = nullptr); |
| 1266 |
|
| 1267 |
void SetImage (const std::shared_ptr<const dng_image> &image, |
| 1268 |
const dng_image_table_compression_info *compressionInfo = nullptr, |
| 1269 |
dng_abort_sniffer *sniffer = nullptr); |
| 1270 |
|
| 1271 |
void Unpack (dng_abort_sniffer *sniffer); |
| 1272 |
|
| 1273 |
void Pack (dng_abort_sniffer *sniffer); |
| 1274 |
|
| 1275 |
protected: |
| 1276 |
|
| 1277 |
bool GetStream (dng_stream &stream) override; |
| 1278 |
|
| 1279 |
void PutStream (dng_stream &stream, |
| 1280 |
bool forFingerprint) const override; |
| 1281 |
|
| 1282 |
uint32 GetFlags () const override |
| 1283 |
{ |
| 1284 |
return 0; |
| 1285 |
} |
| 1286 |
|
| 1287 |
void SetFlags (uint32 /* flags */) override |
| 1288 |
{ |
| 1289 |
} |
| 1290 |
|
| 1291 |
dng_fingerprint ComputeFingerprint () const override |
| 1292 |
{ |
| 1293 |
return fTableDigest; |
| 1294 |
} |
| 1295 |
|
| 1296 |
}; |
| 1297 |
|
| 1298 |
/*****************************************************************************/ |
| 1299 |
|
| 1300 |
// Implements RGBTables tag from DNG 1.6. |
| 1301 |
|
| 1302 |
class dng_masked_rgb_table: private dng_uncopyable |
| 1303 |
{ |
| 1304 |
|
| 1305 |
private: |
| 1306 |
|
| 1307 |
// TableSemanticName and LengthTableSemanticName fields. |
| 1308 |
|
| 1309 |
dng_string fTableSemanticName; |
| 1310 |
|
| 1311 |
// PixelType field. Note that this is NOT the list of pixel types in |
| 1312 |
// dng_tag_types.h but is instead 0, 1, or 2 per DNG 1.6 spec for |
| 1313 |
// RGBTables tag. Only three values are supported: |
| 1314 |
// |
| 1315 |
// 0 = ttByte |
| 1316 |
// 1 = ttShort |
| 1317 |
// 2 = ttFloat |
| 1318 |
|
| 1319 |
uint32 fPixelType = 0; |
| 1320 |
|
| 1321 |
// The following RGBTables tag fields are represented inside the |
| 1322 |
// dng_rgb_table data structure, along with the table data itself. |
| 1323 |
// |
| 1324 |
// Divisions dng_rgb_table::table_data::fDivisions |
| 1325 |
// GammaEncoding dng_rgb_table::table_data::fGamma |
| 1326 |
// ColorPrimaries dng_rgb_table::table_data::fPrimaries |
| 1327 |
// GamutExtension dng_rgb_table::table_data::fGamut |
| 1328 |
|
| 1329 |
dng_rgb_table fTable; |
| 1330 |
|
| 1331 |
// fTable's internal representation is ttShort (unsigned 16-bit |
| 1332 |
// integer). To avoid round-tripping errors, optionally store a copy |
| 1333 |
// of the sample data in the file. |
| 1334 |
|
| 1335 |
std::shared_ptr<dng_memory_block> fStoredData; |
| 1336 |
|
| 1337 |
public: |
| 1338 |
|
| 1339 |
dng_masked_rgb_table (); |
| 1340 |
|
| 1341 |
dng_masked_rgb_table (dng_string tableSemanticName, |
| 1342 |
uint32 pixelType, |
| 1343 |
const dng_rgb_table &table); |
| 1344 |
|
| 1345 |
void Validate () const; |
| 1346 |
|
| 1347 |
void GetStream (dng_host &host, |
| 1348 |
dng_stream &stream); |
| 1349 |
|
| 1350 |
void PutStream (dng_stream &stream) const; |
| 1351 |
|
| 1352 |
void AddDigest (dng_md5_printer &printer) const; |
| 1353 |
|
| 1354 |
const dng_string & SemanticName () const |
| 1355 |
{ |
| 1356 |
return fTableSemanticName; |
| 1357 |
} |
| 1358 |
|
| 1359 |
const dng_rgb_table & Table () const |
| 1360 |
{ |
| 1361 |
return fTable; |
| 1362 |
} |
| 1363 |
|
| 1364 |
uint32 PixelType () const |
| 1365 |
{ |
| 1366 |
return fPixelType; |
| 1367 |
} |
| 1368 |
|
| 1369 |
#if qDNGValidate |
| 1370 |
void Dump (uint32 indent) const; |
| 1371 |
#endif |
| 1372 |
|
| 1373 |
private: |
| 1374 |
|
| 1375 |
static void CheckDivisions (uint32 divisions); |
| 1376 |
|
| 1377 |
static void CheckPixelType (uint32 pixelType); |
| 1378 |
|
| 1379 |
static void CheckGammaEncoding (dng_rgb_table::gamma_enum gamma); |
| 1380 |
|
| 1381 |
static void CheckGamutExtension (dng_rgb_table::gamut_enum gamut); |
| 1382 |
|
| 1383 |
static void CheckColorPrimaries (dng_rgb_table::primaries_enum primaries); |
| 1384 |
|
| 1385 |
}; |
| 1386 |
|
| 1387 |
/*****************************************************************************/ |
| 1388 |
|
| 1389 |
// Implements RGBTables tag from DNG 1.6. |
| 1390 |
|
| 1391 |
class dng_masked_rgb_tables: private dng_uncopyable |
| 1392 |
{ |
| 1393 |
|
| 1394 |
public: |
| 1395 |
|
| 1396 |
static const uint32 kMaxTables = 20; |
| 1397 |
|
| 1398 |
enum composite_method |
| 1399 |
{ |
| 1400 |
kWeightedSum = 0, |
| 1401 |
kSequential = 1, |
| 1402 |
}; |
| 1403 |
|
| 1404 |
private: |
| 1405 |
|
| 1406 |
composite_method fCompositeMethod = kWeightedSum; |
| 1407 |
|
| 1408 |
std::vector<std::shared_ptr<dng_masked_rgb_table> > fTables; |
| 1409 |
|
| 1410 |
public: |
| 1411 |
|
| 1412 |
dng_masked_rgb_tables (); |
| 1413 |
|
| 1414 |
dng_masked_rgb_tables |
| 1415 |
(const std::vector<std::shared_ptr<dng_masked_rgb_table> > &tables, |
| 1416 |
composite_method compositeMethod); |
| 1417 |
|
| 1418 |
const std::vector<std::shared_ptr<dng_masked_rgb_table> > & Tables () const |
| 1419 |
{ |
| 1420 |
return fTables; |
| 1421 |
} |
| 1422 |
|
| 1423 |
bool IsNOP () const; |
| 1424 |
|
| 1425 |
void Validate () const; |
| 1426 |
|
| 1427 |
void AddDigest (dng_md5_printer &printer) const; |
| 1428 |
|
| 1429 |
void PutStream (dng_stream &stream) const; |
| 1430 |
|
| 1431 |
static dng_masked_rgb_tables * GetStream (dng_host &host, |
| 1432 |
dng_stream &stream, |
| 1433 |
bool isDraft); |
| 1434 |
|
| 1435 |
composite_method CompositeMethod () const |
| 1436 |
{ |
| 1437 |
return fCompositeMethod; |
| 1438 |
} |
| 1439 |
|
| 1440 |
bool UseSequentialMethod () const |
| 1441 |
{ |
| 1442 |
return (fCompositeMethod == kSequential); |
| 1443 |
} |
| 1444 |
|
| 1445 |
bool UseWeightedSumMethod () const |
| 1446 |
{ |
| 1447 |
return !UseSequentialMethod (); |
| 1448 |
} |
| 1449 |
|
| 1450 |
void SetCompositeMethod (composite_method method) |
| 1451 |
{ |
| 1452 |
fCompositeMethod = method; |
| 1453 |
} |
| 1454 |
|
| 1455 |
#if qDNGValidate |
| 1456 |
void Dump () const; |
| 1457 |
#endif |
| 1458 |
|
| 1459 |
}; |
| 1460 |
|
| 1461 |
/*****************************************************************************/ |
| 1462 |
|
| 1463 |
class dng_rgb_to_rgb_table_data |
| 1464 |
{ |
| 1465 |
|
| 1466 |
public: |
| 1467 |
|
| 1468 |
dng_rgb_table fTable; |
| 1469 |
|
| 1470 |
bool fNeedMatrix; |
| 1471 |
|
| 1472 |
dng_matrix fEncodeMatrix; |
| 1473 |
dng_matrix fDecodeMatrix; |
| 1474 |
|
| 1475 |
AutoPtr<dng_1d_table> fEncodeTable; |
| 1476 |
AutoPtr<dng_1d_table> fDecodeTable; |
| 1477 |
|
| 1478 |
AutoPtr<dng_1d_table> fTable1D [3]; |
| 1479 |
|
| 1480 |
public: |
| 1481 |
|
| 1482 |
dng_rgb_to_rgb_table_data (dng_host &host, |
| 1483 |
const dng_rgb_table &table); |
| 1484 |
|
| 1485 |
virtual ~dng_rgb_to_rgb_table_data (); |
| 1486 |
|
| 1487 |
virtual void Process_32 (dng_pixel_buffer &buffer, |
| 1488 |
dng_pixel_buffer *optMaskBuffer, // may be nullptr |
| 1489 |
uint32 optMaskPlane, |
| 1490 |
const dng_rect &dstArea, |
| 1491 |
uint32 bufferStartPlane, |
| 1492 |
bool needOverrange); |
| 1493 |
|
| 1494 |
void AddDigest (dng_md5_printer &printer) const; |
| 1495 |
|
| 1496 |
}; |
| 1497 |
|
| 1498 |
/*****************************************************************************/ |
| 1499 |
|
| 1500 |
class dng_masked_rgb_table_render_data |
| 1501 |
{ |
| 1502 |
|
| 1503 |
public: |
| 1504 |
|
| 1505 |
bool fUseSequentialMethod = false; |
| 1506 |
|
| 1507 |
// A vector of paired RGB tables & masks. A given RGB table is meant |
| 1508 |
// to be applied with the corresponding mask. |
| 1509 |
|
| 1510 |
std::vector<std::pair<dng_masked_rgb_table_sptr, |
| 1511 |
dng_semantic_mask> > fMaskedTables; |
| 1512 |
|
| 1513 |
// A vector of RGB transform data that is precomputed. This vector has |
| 1514 |
// a one-to-one correspondence with fMaskedTables, above. |
| 1515 |
|
| 1516 |
std::vector<dng_rgb_to_rgb_table_data_sptr> fMaskedTableData; |
| 1517 |
|
| 1518 |
// Background RGB table and data. Will be left as nullptr if there is |
| 1519 |
// no background table. |
| 1520 |
|
| 1521 |
dng_masked_rgb_table_sptr fBackgroundTable; |
| 1522 |
|
| 1523 |
AutoPtr<dng_rgb_to_rgb_table_data> fBackgroundTableData; |
| 1524 |
|
| 1525 |
// In the sequential method case, if there is a background table then |
| 1526 |
// this is its index in the fMaskedTables vector. Otherwise this gets |
| 1527 |
// set to fMaskedTables.size () as it may be used in ways that require |
| 1528 |
// to be larger than all other table indices when there is no |
| 1529 |
// background table. |
| 1530 |
|
| 1531 |
uint32 fBackgroundTableIndex = 0; |
| 1532 |
|
| 1533 |
public: |
| 1534 |
|
| 1535 |
void Initialize (const dng_negative &negative, |
| 1536 |
const dng_camera_profile &profile); |
| 1537 |
|
| 1538 |
bool IsNOP () const |
| 1539 |
{ |
| 1540 |
return (fMaskedTables.empty () && !fBackgroundTable); |
| 1541 |
} |
| 1542 |
|
| 1543 |
void PrepareRGBtoRGBTableData (dng_host &host); |
| 1544 |
|
| 1545 |
}; |
| 1546 |
|
| 1547 |
/*****************************************************************************/ |
| 1548 |
|
| 1549 |
// Big tables in the XMP_NS_CRS and XMP_NS_CRSS are removed from the |
| 1550 |
// xmp and added to the big table dictionary. |
| 1551 |
|
| 1552 |
void MoveBigTablesToDictionary (dng_xmp &xmp, |
| 1553 |
dng_big_table_dictionary &dictionary); |
| 1554 |
|
| 1555 |
/******************************************************************************/ |
| 1556 |
|
| 1557 |
// Parses an XMP block into decoded xmp and a big table dictionary. |
| 1558 |
// Big tables in the XMP_NS_CRS and XMP_NS_CRSS are removed from the decoded |
| 1559 |
// xmp and added to the big table dictionary. |
| 1560 |
|
| 1561 |
void DualParseXMP (dng_host &host, |
| 1562 |
dng_xmp &xmp, |
| 1563 |
dng_big_table_dictionary &dictionary, |
| 1564 |
const void *blockData, |
| 1565 |
uint32 blockSize); |
| 1566 |
|
| 1567 |
/*****************************************************************************/ |
| 1568 |
|
| 1569 |
#endif // __dng_big_table__ |
| 1570 |
|
| 1571 |
/*****************************************************************************/ |