| 1 |
/*****************************************************************************/ |
| 2 |
// Copyright 2011-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 |
#include "dng_jpeg_image.h" |
| 10 |
|
| 11 |
#include "dng_abort_sniffer.h" |
| 12 |
#include "dng_area_task.h" |
| 13 |
#include "dng_assertions.h" |
| 14 |
#include "dng_host.h" |
| 15 |
#include "dng_ifd.h" |
| 16 |
#include "dng_jxl.h" |
| 17 |
#include "dng_image.h" |
| 18 |
#include "dng_image_writer.h" |
| 19 |
#include "dng_memory_stream.h" |
| 20 |
#include "dng_safe_arithmetic.h" |
| 21 |
#include "dng_uncopyable.h" |
| 22 |
|
| 23 |
#include <atomic> |
| 24 |
|
| 25 |
/*****************************************************************************/ |
| 26 |
|
| 27 |
class dng_compressed_image_encode_task : public dng_area_task, |
| 28 |
private dng_uncopyable |
| 29 |
{ |
| 30 |
|
| 31 |
private: |
| 32 |
|
| 33 |
dng_host &fHost; |
| 34 |
|
| 35 |
dng_image_writer &fWriter; |
| 36 |
|
| 37 |
const dng_image &fImage; |
| 38 |
|
| 39 |
dng_compressed_image_tiles &fCompressedImage; |
| 40 |
|
| 41 |
uint32 fTileCount; |
| 42 |
|
| 43 |
const dng_ifd &fIFD; |
| 44 |
|
| 45 |
std::atomic_uint fNextTileIndex; |
| 46 |
|
| 47 |
public: |
| 48 |
|
| 49 |
dng_compressed_image_encode_task (dng_host &host, |
| 50 |
dng_image_writer &writer, |
| 51 |
const dng_image &image, |
| 52 |
dng_compressed_image_tiles &compressedImage, |
| 53 |
uint32 tileCount, |
| 54 |
const dng_ifd &ifd) |
| 55 |
|
| 56 |
: dng_area_task ("dng_compressed_image_encode_task") |
| 57 |
|
| 58 |
, fHost (host) |
| 59 |
, fWriter (writer) |
| 60 |
, fImage (image) |
| 61 |
, fCompressedImage (compressedImage) |
| 62 |
, fTileCount (tileCount) |
| 63 |
, fIFD (ifd) |
| 64 |
, fNextTileIndex (0) |
| 65 |
|
| 66 |
{ |
| 67 |
|
| 68 |
fMinTaskArea = 16 * 16; |
| 69 |
fUnitCell = dng_point (16, 16); |
| 70 |
fMaxTileSize = dng_point (16, 16); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
void Process (uint32 /* threadIndex */, |
| 75 |
const dng_rect & /* tile */, |
| 76 |
dng_abort_sniffer *sniffer) |
| 77 |
{ |
| 78 |
|
| 79 |
AutoPtr<dng_memory_block> compressedBuffer; |
| 80 |
AutoPtr<dng_memory_block> uncompressedBuffer; |
| 81 |
AutoPtr<dng_memory_block> subTileBlockBuffer; |
| 82 |
AutoPtr<dng_memory_block> tempBuffer; |
| 83 |
|
| 84 |
uint32 uncompressedSize = SafeUint32Mult (fIFD.fTileLength, |
| 85 |
fIFD.fTileWidth, |
| 86 |
fIFD.fSamplesPerPixel, |
| 87 |
fImage.PixelSize ()); |
| 88 |
|
| 89 |
uncompressedBuffer.Reset (fHost.Allocate (uncompressedSize)); |
| 90 |
|
| 91 |
uint32 compressedSize = fWriter.CompressedBufferSize (fIFD, uncompressedSize); |
| 92 |
|
| 93 |
if (compressedSize) |
| 94 |
{ |
| 95 |
compressedBuffer.Reset (fHost.Allocate (compressedSize)); |
| 96 |
} |
| 97 |
|
| 98 |
uint32 tilesAcross = fIFD.TilesAcross (); |
| 99 |
|
| 100 |
while (true) |
| 101 |
{ |
| 102 |
|
| 103 |
// Note: fNextTileIndex is atomic |
| 104 |
|
| 105 |
uint32 tileIndex = fNextTileIndex++; |
| 106 |
|
| 107 |
if (tileIndex >= fTileCount) |
| 108 |
{ |
| 109 |
return; |
| 110 |
} |
| 111 |
|
| 112 |
dng_abort_sniffer::SniffForAbort (sniffer); |
| 113 |
|
| 114 |
uint32 rowIndex = tileIndex / tilesAcross; |
| 115 |
uint32 colIndex = tileIndex % tilesAcross; |
| 116 |
|
| 117 |
dng_rect tileArea = fIFD.TileArea (rowIndex, colIndex); |
| 118 |
|
| 119 |
dng_memory_stream stream (fHost.Allocator ()); |
| 120 |
|
| 121 |
fWriter.WriteTile (fHost, |
| 122 |
fIFD, |
| 123 |
stream, |
| 124 |
fImage, |
| 125 |
tileArea, |
| 126 |
1, |
| 127 |
compressedBuffer, |
| 128 |
uncompressedBuffer, |
| 129 |
subTileBlockBuffer, |
| 130 |
tempBuffer, |
| 131 |
true); |
| 132 |
|
| 133 |
fCompressedImage.fData [tileIndex].reset |
| 134 |
(stream.AsMemoryBlock (fHost.Allocator ())); |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
}; |
| 141 |
|
| 142 |
/*****************************************************************************/ |
| 143 |
|
| 144 |
void dng_compressed_image_tiles::EncodeTiles (dng_host &host, |
| 145 |
dng_image_writer &writer, |
| 146 |
const dng_image &image, |
| 147 |
const dng_ifd &ifd) |
| 148 |
{ |
| 149 |
|
| 150 |
#if qDNGValidate |
| 151 |
|
| 152 |
char message [256]; |
| 153 |
|
| 154 |
dng_timer timer (message); |
| 155 |
|
| 156 |
#endif |
| 157 |
|
| 158 |
uint32 tilesAcross = ifd.TilesAcross (); |
| 159 |
uint32 tilesDown = ifd.TilesDown (); |
| 160 |
|
| 161 |
uint32 tileCount = tilesAcross * tilesDown; |
| 162 |
|
| 163 |
fData.resize (tileCount); |
| 164 |
|
| 165 |
uint32 threadCount = Min_uint32 (tileCount, |
| 166 |
host.PerformAreaTaskThreads ()); |
| 167 |
|
| 168 |
dng_compressed_image_encode_task task (host, |
| 169 |
writer, |
| 170 |
image, |
| 171 |
*this, |
| 172 |
tileCount, |
| 173 |
ifd); |
| 174 |
|
| 175 |
host.PerformAreaTask (task, |
| 176 |
dng_rect (0, 0, 16, 16 * threadCount)); |
| 177 |
|
| 178 |
#if qDNGValidate |
| 179 |
|
| 180 |
if (ifd.fCompression == ccJXL) |
| 181 |
{ |
| 182 |
|
| 183 |
snprintf (message, |
| 184 |
sizeof (message), |
| 185 |
"JXL encode %u by %u pixels, distance = %.2f, effort = %d, size = %llu", |
| 186 |
image.Width (), |
| 187 |
image.Height (), |
| 188 |
ifd.fJXLEncodeSettings->Distance (), |
| 189 |
ifd.fJXLEncodeSettings->Effort (), |
| 190 |
NonHeaderSize ()); |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
else if (ifd.fCompression == ccLossyJPEG) |
| 195 |
{ |
| 196 |
|
| 197 |
snprintf (message, |
| 198 |
sizeof (message), |
| 199 |
"Lossy JPEG encode %u by %u pixels, quality = %d, size = %llu", |
| 200 |
image.Width (), |
| 201 |
image.Height (), |
| 202 |
ifd.fCompressionQuality, |
| 203 |
NonHeaderSize ()); |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
else if (ifd.fCompression == ccDeflate) |
| 208 |
{ |
| 209 |
|
| 210 |
snprintf (message, |
| 211 |
sizeof (message), |
| 212 |
"Deflate encode %u by %u pixels, quality = %d, size = %llu", |
| 213 |
image.Width (), |
| 214 |
image.Height (), |
| 215 |
ifd.fCompressionQuality, |
| 216 |
NonHeaderSize ()); |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
else |
| 221 |
{ |
| 222 |
|
| 223 |
snprintf (message, |
| 224 |
sizeof (message), |
| 225 |
"EncodeTiles %u by %u pixels, size = %llu", |
| 226 |
image.Width (), |
| 227 |
image.Height (), |
| 228 |
NonHeaderSize ()); |
| 229 |
|
| 230 |
} |
| 231 |
|
| 232 |
#endif |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
/*****************************************************************************/ |
| 237 |
|
| 238 |
uint64 dng_compressed_image_tiles::NonHeaderSize () const |
| 239 |
{ |
| 240 |
|
| 241 |
uint64 size = 0; |
| 242 |
|
| 243 |
for (size_t index = 0; index < fData.size (); index++) |
| 244 |
{ |
| 245 |
|
| 246 |
size += RoundUp2 (fData [index]->LogicalSize ()); |
| 247 |
|
| 248 |
} |
| 249 |
|
| 250 |
return size; |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
/*****************************************************************************/ |
| 255 |
|
| 256 |
void dng_compressed_image_tiles::WriteData (dng_stream &stream, |
| 257 |
dng_basic_tag_set &basic) const |
| 258 |
{ |
| 259 |
|
| 260 |
uint32 tileCount = (uint32) fData.size (); |
| 261 |
|
| 262 |
for (uint32 tileIndex = 0; tileIndex < tileCount; tileIndex++) |
| 263 |
{ |
| 264 |
|
| 265 |
// Remember this offset. |
| 266 |
|
| 267 |
uint64 tileOffset = stream.Position (); |
| 268 |
|
| 269 |
basic.SetTileOffset (tileIndex, tileOffset); |
| 270 |
|
| 271 |
// Write compressed data. |
| 272 |
|
| 273 |
stream.Put (fData [tileIndex]->Buffer (), |
| 274 |
fData [tileIndex]->LogicalSize ()); |
| 275 |
|
| 276 |
// Update tile byte count. |
| 277 |
|
| 278 |
uint64 tileByteCount = stream.Position () - tileOffset; |
| 279 |
|
| 280 |
basic.SetTileByteCount (tileIndex, tileByteCount); |
| 281 |
|
| 282 |
// Keep the tiles on even byte offsets. |
| 283 |
|
| 284 |
if (tileByteCount & 1) |
| 285 |
{ |
| 286 |
stream.Put_uint8 (0); |
| 287 |
} |
| 288 |
|
| 289 |
} |
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
/*****************************************************************************/ |
| 294 |
|
| 295 |
void dng_lossy_compressed_image::EncodeTiles (dng_host &host, |
| 296 |
dng_image_writer &writer, |
| 297 |
const dng_image &image, |
| 298 |
const dng_ifd &ifd) |
| 299 |
{ |
| 300 |
|
| 301 |
dng_compressed_image_tiles::EncodeTiles (host, |
| 302 |
writer, |
| 303 |
image, |
| 304 |
ifd); |
| 305 |
|
| 306 |
fImageSize.h = ifd.fImageWidth; |
| 307 |
fImageSize.v = ifd.fImageLength; |
| 308 |
|
| 309 |
fTileSize.h = ifd.fTileWidth; |
| 310 |
fTileSize.v = ifd.fTileLength; |
| 311 |
|
| 312 |
fUsesStrips = !ifd.fUsesTiles; |
| 313 |
|
| 314 |
fCompressionCode = ifd.fCompression; |
| 315 |
|
| 316 |
fBitsPerSample = ifd.fBitsPerSample [0]; |
| 317 |
|
| 318 |
fRowInterleaveFactor = ifd.fRowInterleaveFactor; |
| 319 |
fColumnInterleaveFactor = ifd.fColumnInterleaveFactor; |
| 320 |
|
| 321 |
if (fCompressionCode == ccJXL && ifd.fJXLEncodeSettings.get ()) |
| 322 |
{ |
| 323 |
fJXLDistance = ifd.fJXLEncodeSettings->Distance (); |
| 324 |
fJXLEffort = ifd.fJXLEncodeSettings->Effort (); |
| 325 |
fJXLDecodeSpeed = ifd.fJXLEncodeSettings->DecodeSpeed (); |
| 326 |
} |
| 327 |
|
| 328 |
} |
| 329 |
|
| 330 |
/*****************************************************************************/ |
| 331 |
|
| 332 |
dng_fingerprint dng_lossy_compressed_image::FindDigest (dng_host &host) const |
| 333 |
{ |
| 334 |
|
| 335 |
const uint32 tileCount = TileCount (); |
| 336 |
|
| 337 |
std::vector<dng_fingerprint> digests (tileCount); |
| 338 |
|
| 339 |
// Compute digest of each compressed tile. |
| 340 |
|
| 341 |
dng_range_parallel_task::Do |
| 342 |
(host, |
| 343 |
dng_range_parallel_task::info (int32 (0), |
| 344 |
int32 (tileCount)), |
| 345 |
"dng_lossy_compressed_image::FindDigest", |
| 346 |
[this, &digests] (const dng_range_parallel_task::range &ra) |
| 347 |
{ |
| 348 |
|
| 349 |
for (int32 i = ra.fBegin; i < ra.fEnd; i++) |
| 350 |
{ |
| 351 |
|
| 352 |
dng_md5_printer printer; |
| 353 |
|
| 354 |
printer.Process (fData [i]->Buffer (), |
| 355 |
fData [i]->LogicalSize ()); |
| 356 |
|
| 357 |
digests [i] = printer.Result (); |
| 358 |
|
| 359 |
} |
| 360 |
|
| 361 |
}); |
| 362 |
|
| 363 |
// Subclasses can add extra data here. |
| 364 |
|
| 365 |
DoFindDigest (host, digests); |
| 366 |
|
| 367 |
// Combine digests into a single digest. |
| 368 |
|
| 369 |
{ |
| 370 |
|
| 371 |
dng_md5_printer printer; |
| 372 |
|
| 373 |
for (const auto &digest : digests) |
| 374 |
printer.Process (digest.data, |
| 375 |
uint32 (sizeof (digest.data))); |
| 376 |
|
| 377 |
return printer.Result (); |
| 378 |
|
| 379 |
} |
| 380 |
|
| 381 |
} |
| 382 |
|
| 383 |
/*****************************************************************************/ |
| 384 |
|
| 385 |
static void CommonConfigureIFD (dng_ifd &ifd, |
| 386 |
const dng_image &image, |
| 387 |
const uint32 compressionCode, |
| 388 |
const dng_point &tileSize, |
| 389 |
const uint32 bitDepth) |
| 390 |
{ |
| 391 |
|
| 392 |
DNG_REQUIRE (image.PixelType () == ttByte || |
| 393 |
image.PixelType () == ttShort || |
| 394 |
image.PixelType () == ttFloat, |
| 395 |
"Unsupported pixel type"); |
| 396 |
|
| 397 |
dng_point imageSize = image.Bounds ().Size (); |
| 398 |
|
| 399 |
ifd.fImageWidth = imageSize.h; |
| 400 |
ifd.fImageLength = imageSize.v; |
| 401 |
|
| 402 |
ifd.fSamplesPerPixel = image.Planes (); |
| 403 |
|
| 404 |
ifd.fBitsPerSample [0] = bitDepth; |
| 405 |
ifd.fBitsPerSample [1] = bitDepth; |
| 406 |
ifd.fBitsPerSample [2] = bitDepth; |
| 407 |
ifd.fBitsPerSample [3] = bitDepth; |
| 408 |
|
| 409 |
ifd.fPhotometricInterpretation = piLinearRaw; |
| 410 |
|
| 411 |
ifd.fCompression = compressionCode; |
| 412 |
|
| 413 |
ifd.FindTileSize (SafeUint32Mult (uint32 (tileSize.h), |
| 414 |
uint32 (tileSize.v), |
| 415 |
ifd.fSamplesPerPixel)); |
| 416 |
|
| 417 |
} |
| 418 |
|
| 419 |
/*****************************************************************************/ |
| 420 |
|
| 421 |
dng_jpeg_image::dng_jpeg_image () |
| 422 |
{ |
| 423 |
|
| 424 |
fCompressionCode = ccLossyJPEG; |
| 425 |
|
| 426 |
} |
| 427 |
|
| 428 |
/*****************************************************************************/ |
| 429 |
|
| 430 |
void dng_jpeg_image::Encode (dng_host &host, |
| 431 |
const dng_negative &negative, |
| 432 |
dng_image_writer &writer, |
| 433 |
const dng_image &image) |
| 434 |
{ |
| 435 |
|
| 436 |
#if qDNGValidate |
| 437 |
dng_timer timer ("Encode JPEG Proxy time"); |
| 438 |
#endif |
| 439 |
|
| 440 |
DNG_REQUIRE (image.PixelType () == ttByte, |
| 441 |
"Cannot JPEG encode non-byte image"); |
| 442 |
|
| 443 |
dng_ifd ifd; |
| 444 |
|
| 445 |
CommonConfigureIFD (ifd, |
| 446 |
image, |
| 447 |
ccLossyJPEG, |
| 448 |
dng_point (512, 512), |
| 449 |
8); |
| 450 |
|
| 451 |
// Choose JPEG encode quality. Need a higher quality for raw proxies than |
| 452 |
// non-raw proxies, since users often perform much greater color changes. |
| 453 |
// Also, if we are targeting a "large" size proxy (larger than 5 MP), or |
| 454 |
// this is a full size proxy, then use a higher quality. |
| 455 |
|
| 456 |
bool useHigherQuality = (uint64) image.Width () * |
| 457 |
(uint64) image.Height () > 5000000 || |
| 458 |
image.Bounds ().Size () == negative.OriginalDefaultFinalSize (); |
| 459 |
|
| 460 |
if (negative.IsSceneReferred ()) |
| 461 |
{ |
| 462 |
ifd.fCompressionQuality = useHigherQuality ? 11 : 10; |
| 463 |
} |
| 464 |
|
| 465 |
else |
| 466 |
{ |
| 467 |
ifd.fCompressionQuality = useHigherQuality ? 10 : 8; |
| 468 |
} |
| 469 |
|
| 470 |
EncodeTiles (host, |
| 471 |
writer, |
| 472 |
image, |
| 473 |
ifd); |
| 474 |
|
| 475 |
} |
| 476 |
|
| 477 |
/*****************************************************************************/ |
| 478 |
|
| 479 |
void dng_jpeg_image::DoFindDigest (dng_host & /* host */, |
| 480 |
std::vector<dng_fingerprint> &digests) const |
| 481 |
{ |
| 482 |
|
| 483 |
// Compute digest of JPEG tables, if any, and add to the given list. |
| 484 |
|
| 485 |
if (fJPEGTables.Get ()) |
| 486 |
{ |
| 487 |
|
| 488 |
dng_md5_printer printer; |
| 489 |
|
| 490 |
printer.Process (fJPEGTables->Buffer (), |
| 491 |
fJPEGTables->LogicalSize ()); |
| 492 |
|
| 493 |
digests.push_back (printer.Result ()); |
| 494 |
|
| 495 |
} |
| 496 |
|
| 497 |
} |
| 498 |
|
| 499 |
/*****************************************************************************/ |
| 500 |
|
| 501 |
dng_jxl_image::dng_jxl_image () |
| 502 |
{ |
| 503 |
|
| 504 |
fCompressionCode = ccJXL; |
| 505 |
|
| 506 |
} |
| 507 |
|
| 508 |
/*****************************************************************************/ |
| 509 |
|
| 510 |
void dng_jxl_image::Encode (dng_host &host, |
| 511 |
dng_image_writer &writer, |
| 512 |
const dng_image &image, |
| 513 |
const dng_jxl_encode_settings &encodeSettings, |
| 514 |
const JxlColorEncoding *colorEncoding) |
| 515 |
{ |
| 516 |
|
| 517 |
DNG_REQUIRE (SupportsJXL (image), |
| 518 |
"Unsupported image"); |
| 519 |
|
| 520 |
DNG_REQUIRE (image.PixelType () == ttByte || |
| 521 |
image.PixelType () == ttShort || |
| 522 |
image.PixelType () == ttFloat, |
| 523 |
"Unsupported pixel type"); |
| 524 |
|
| 525 |
dng_ifd ifd; |
| 526 |
|
| 527 |
ifd.fImageWidth = image.Width (); |
| 528 |
ifd.fImageLength = image.Height (); |
| 529 |
|
| 530 |
ifd.fSamplesPerPixel = image.Planes (); |
| 531 |
|
| 532 |
for (uint32 plane = 0; plane < ifd.fSamplesPerPixel; plane++) |
| 533 |
{ |
| 534 |
|
| 535 |
if (image.PixelType () == ttFloat) |
| 536 |
{ |
| 537 |
ifd.fBitsPerSample [plane] = 16; |
| 538 |
ifd.fSampleFormat [plane] = sfFloatingPoint; |
| 539 |
} |
| 540 |
|
| 541 |
else |
| 542 |
{ |
| 543 |
ifd.fBitsPerSample [plane] = image.PixelSize () * 8; |
| 544 |
} |
| 545 |
|
| 546 |
} |
| 547 |
|
| 548 |
ifd.fCompression = ccJXL; |
| 549 |
|
| 550 |
// This will cause the color encoding to use linear gamma with |
| 551 |
// no color transform, unless we override it. |
| 552 |
|
| 553 |
ifd.fPhotometricInterpretation = piLinearRaw; |
| 554 |
|
| 555 |
// Attach JXL encode settings to IFD. |
| 556 |
|
| 557 |
AutoPtr<dng_jxl_encode_settings> encodeSettingsHolder |
| 558 |
(new dng_jxl_encode_settings (encodeSettings)); |
| 559 |
|
| 560 |
ifd.fJXLEncodeSettings.reset (encodeSettingsHolder.Release ()); |
| 561 |
|
| 562 |
// Attach JXL color encoding to IFD, if any. |
| 563 |
|
| 564 |
if (colorEncoding) |
| 565 |
{ |
| 566 |
|
| 567 |
AutoPtr<JxlColorEncoding> colorEncodingHolder |
| 568 |
(new JxlColorEncoding (*colorEncoding)); |
| 569 |
|
| 570 |
ifd.fJXLColorEncoding.reset (colorEncodingHolder.Release ()); |
| 571 |
|
| 572 |
} |
| 573 |
|
| 574 |
ifd.FindTileSize (1024 * 1024); |
| 575 |
|
| 576 |
EncodeTiles (host, |
| 577 |
writer, |
| 578 |
image, |
| 579 |
ifd); |
| 580 |
|
| 581 |
} |
| 582 |
|
| 583 |
/*****************************************************************************/ |
| 584 |
|
| 585 |
void dng_jxl_image::Encode (dng_host &host, |
| 586 |
dng_image_writer &writer, |
| 587 |
const dng_image &image, |
| 588 |
dng_host::use_case_enum useCase, |
| 589 |
const dng_negative *negative) |
| 590 |
{ |
| 591 |
|
| 592 |
AutoPtr<dng_jxl_encode_settings> encodeSettings |
| 593 |
(host.MakeJXLEncodeSettings (useCase, |
| 594 |
image, |
| 595 |
negative)); |
| 596 |
|
| 597 |
AutoPtr<JxlColorEncoding> colorEncoding; |
| 598 |
|
| 599 |
if ((useCase == dng_host::use_case_EncodedMainImage || |
| 600 |
useCase == dng_host::use_case_ProxyImage) && |
| 601 |
image.PixelType () == ttShort) |
| 602 |
{ |
| 603 |
|
| 604 |
colorEncoding.Reset (new JxlColorEncoding); |
| 605 |
|
| 606 |
memset (colorEncoding.Get (), 0, sizeof (JxlColorEncoding)); |
| 607 |
|
| 608 |
// EncodeImageForCompression leaves the image far from linear gamma, |
| 609 |
// so let's pretend it is sRGB gamma. |
| 610 |
|
| 611 |
colorEncoding->color_space = image.Planes () == 1 ? JXL_COLOR_SPACE_GRAY |
| 612 |
: JXL_COLOR_SPACE_RGB; |
| 613 |
colorEncoding->white_point = JXL_WHITE_POINT_D65; |
| 614 |
colorEncoding->primaries = JXL_PRIMARIES_2100; |
| 615 |
colorEncoding->transfer_function = JXL_TRANSFER_FUNCTION_SRGB; |
| 616 |
|
| 617 |
} |
| 618 |
|
| 619 |
Encode (host, |
| 620 |
writer, |
| 621 |
image, |
| 622 |
*encodeSettings, |
| 623 |
colorEncoding.Get ()); |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
/*****************************************************************************/ |
| 628 |
|
| 629 |
dng_lossy_compressed_image * KeepLossyCompressedImage (dng_host &host, |
| 630 |
const dng_ifd &ifd) |
| 631 |
{ |
| 632 |
|
| 633 |
AutoPtr<dng_lossy_compressed_image> lossyImage; |
| 634 |
|
| 635 |
if (host.SaveDNGVersion () && |
| 636 |
!host.PreferredSize () && |
| 637 |
!host.ForPreview ()) |
| 638 |
{ |
| 639 |
|
| 640 |
// Non-default ColumnInterleaveFactor requires DNG 1.7.1. |
| 641 |
|
| 642 |
if (ifd.fColumnInterleaveFactor != 1 && |
| 643 |
host.SaveDNGVersion () < dngVersion_1_7_1_0) |
| 644 |
{ |
| 645 |
return nullptr; |
| 646 |
} |
| 647 |
|
| 648 |
// See if we should grab the compressed JPEG data. |
| 649 |
|
| 650 |
if (host.SaveDNGVersion () >= MinBackwardVersionForCompression (ccLossyJPEG) && |
| 651 |
ifd.IsBaselineJPEG ()) |
| 652 |
{ |
| 653 |
|
| 654 |
lossyImage.Reset (new dng_jpeg_image); |
| 655 |
|
| 656 |
} |
| 657 |
|
| 658 |
if (host.SaveDNGVersion () >= MinBackwardVersionForCompression (ccJXL) && |
| 659 |
ifd.fCompression == ccJXL) |
| 660 |
{ |
| 661 |
|
| 662 |
lossyImage.Reset (new dng_lossy_compressed_image); |
| 663 |
|
| 664 |
} |
| 665 |
|
| 666 |
} |
| 667 |
|
| 668 |
if (lossyImage.Get ()) |
| 669 |
{ |
| 670 |
|
| 671 |
lossyImage->fCompressionCode = ifd.fCompression; |
| 672 |
|
| 673 |
lossyImage->fBitsPerSample = ifd.fBitsPerSample [0]; |
| 674 |
|
| 675 |
lossyImage->fRowInterleaveFactor = ifd.fRowInterleaveFactor; |
| 676 |
lossyImage->fColumnInterleaveFactor = ifd.fColumnInterleaveFactor; |
| 677 |
|
| 678 |
lossyImage->fJXLDistance = ifd.fJXLDistance; |
| 679 |
lossyImage->fJXLEffort = ifd.fJXLEffort; |
| 680 |
lossyImage->fJXLDecodeSpeed = ifd.fJXLDecodeSpeed; |
| 681 |
|
| 682 |
} |
| 683 |
|
| 684 |
return lossyImage.Release (); |
| 685 |
|
| 686 |
} |
| 687 |
|
| 688 |
/*****************************************************************************/ |