Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 void DoRead(void* data, uint32 count, uint64 offset) override { | 296 void DoRead(void* data, uint32 count, uint64 offset) override { |
| 297 fRawStream->read(data, count, offset); | 297 fRawStream->read(data, count, offset); |
| 298 } | 298 } |
| 299 | 299 |
| 300 private: | 300 private: |
| 301 SkRawStream* fRawStream; | 301 SkRawStream* fRawStream; |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 class SkDngImage { | 304 class SkDngImage { |
| 305 public: | 305 public: |
| 306 /* | |
| 307 * Initializes the object with the information from Piex in a first attempt. This way it can | |
| 308 * save time and storage to obtain the DNG dimensions and CFA pattern. | |
|
scroggo
2016/02/03 15:56:02
Should there be a comment somewhere describing wha
ebrauer
2016/02/04 15:17:08
Done.
| |
| 309 */ | |
| 306 static SkDngImage* NewFromStream(SkRawStream* stream) { | 310 static SkDngImage* NewFromStream(SkRawStream* stream) { |
| 307 SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream)); | 311 SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream)); |
| 308 if (!dngImage->readDng()) { | 312 if (!dngImage->initFromPiex()) { |
| 309 return nullptr; | 313 if (!dngImage->readDng()) { |
| 314 return nullptr; | |
| 315 } | |
| 310 } | 316 } |
| 311 | 317 |
| 312 SkASSERT(dngImage->fNegative); | |
| 313 return dngImage.release(); | 318 return dngImage.release(); |
| 314 } | 319 } |
| 315 | 320 |
| 316 /* | 321 /* |
| 317 * Renders the DNG image to the size. The DNG SDK only allows scaling close to integer factors | 322 * Renders the DNG image to the size. The DNG SDK only allows scaling close to integer factors |
| 318 * down to 80 pixels on the short edge. The rendered image will be close to the specified size, | 323 * down to 80 pixels on the short edge. The rendered image will be close to the specified size, |
| 319 * but there is no guarantee that any of the edges will match the requested size. E.g. | 324 * but there is no guarantee that any of the edges will match the requested size. E.g. |
| 320 * 100% size: 4000 x 3000 | 325 * 100% size: 4000 x 3000 |
| 321 * requested size: 1600 x 1200 | 326 * requested size: 1600 x 1200 |
| 322 * returned size could be: 2000 x 1500 | 327 * returned size could be: 2000 x 1500 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 | 379 |
| 375 bool isScalable() const { | 380 bool isScalable() const { |
| 376 return fIsScalable; | 381 return fIsScalable; |
| 377 } | 382 } |
| 378 | 383 |
| 379 bool isXtransImage() const { | 384 bool isXtransImage() const { |
| 380 return fIsXtransImage; | 385 return fIsXtransImage; |
| 381 } | 386 } |
| 382 | 387 |
| 383 private: | 388 private: |
| 389 void init(const int width, const int height, const int cfaPatternSize) { | |
| 390 fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_ SkAlphaType); | |
| 391 | |
| 392 // The DNG SDK scales only for at demosaicing, so only when a mosaic inf o is available also | |
|
scroggo
2016/02/03 15:56:02
I don't follow this sentence. I think you mean som
ebrauer
2016/02/04 15:17:08
Done.
| |
| 393 // scale is available. | |
| 394 fIsScalable = cfaPatternSize != 0; | |
| 395 fIsXtransImage = fIsScalable ? cfaPatternSize == 36 : false; | |
|
msarett
2016/02/03 16:21:49
This seems like a possible behavior change to me?
ebrauer
2016/02/04 15:17:08
The pattern size is either 0, 2x2 or 6x6, but theo
| |
| 396 } | |
| 397 | |
| 398 bool initFromPiex() { | |
| 399 ::piex::PreviewImageData imageData; | |
| 400 if (::piex::IsRaw(fStream.get()) | |
|
scroggo
2016/02/03 15:56:02
These two methods have already been called by SkRa
ebrauer
2016/02/04 15:17:07
Yes, they are pretty cheap that is why we try to u
| |
| 401 && ::piex::GetPreviewImageData(fStream.get(), &imageData) == ::piex: :Error::kOk) { | |
|
scroggo
2016/02/03 15:56:02
nit: Easier to follow along if you put the brace o
ebrauer
2016/02/04 15:17:08
Done.
| |
| 402 init(static_cast<int>(imageData.full_width), static_cast<int>(imageD ata.full_height), | |
|
scroggo
2016/02/03 15:56:02
this->init
ebrauer
2016/02/04 15:17:08
Done.
| |
| 403 imageData.cfa_pattern_dim[0] * imageData.cfa_pattern_dim[1]); | |
|
scroggo
2016/02/03 15:56:02
nit: This should either be indented 8 spaces, or t
ebrauer
2016/02/04 15:17:08
Done.
| |
| 404 return true; | |
| 405 } | |
| 406 return false; | |
| 407 } | |
| 408 | |
| 384 bool readDng() { | 409 bool readDng() { |
| 385 // Due to the limit of DNG SDK, we need to reset host and info. | 410 // Due to the limit of DNG SDK, we need to reset host and info. |
| 386 fHost.reset(new SkDngHost(&fAllocator)); | 411 fHost.reset(new SkDngHost(&fAllocator)); |
| 387 fInfo.reset(new dng_info); | 412 fInfo.reset(new dng_info); |
| 388 fDngStream.reset(new SkDngStream(fStream)); | 413 fDngStream.reset(new SkDngStream(fStream)); |
| 389 try { | 414 try { |
| 390 fHost->ValidateSizes(); | 415 fHost->ValidateSizes(); |
| 391 fInfo->Parse(*fHost, *fDngStream); | 416 fInfo->Parse(*fHost, *fDngStream); |
| 392 fInfo->PostParse(*fHost); | 417 fInfo->PostParse(*fHost); |
| 393 if (!fInfo->IsValidDNG()) { | 418 if (!fInfo->IsValidDNG()) { |
| 394 return false; | 419 return false; |
| 395 } | 420 } |
| 396 | 421 |
| 397 fNegative.reset(fHost->Make_dng_negative()); | 422 fNegative.reset(fHost->Make_dng_negative()); |
| 398 fNegative->Parse(*fHost, *fDngStream, *fInfo); | 423 fNegative->Parse(*fHost, *fDngStream, *fInfo); |
| 399 fNegative->PostParse(*fHost, *fDngStream, *fInfo); | 424 fNegative->PostParse(*fHost, *fDngStream, *fInfo); |
| 400 fNegative->SynchronizeMetadata(); | 425 fNegative->SynchronizeMetadata(); |
| 401 | 426 |
| 402 fImageInfo = SkImageInfo::Make( | 427 dng_point cfaPattern(0, 0); |
|
scroggo
2016/02/03 15:56:02
Nit: it appears that a more accurate name for this
ebrauer
2016/02/04 15:17:08
Done.
| |
| 403 static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), | 428 if (fNegative->GetMosaicInfo() != nullptr) { |
| 429 cfaPattern = fNegative->GetMosaicInfo()->fCFAPatternSize; | |
| 430 } | |
| 431 init(static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), | |
|
scroggo
2016/02/03 15:56:02
this->init
ebrauer
2016/02/04 15:17:08
Done.
| |
| 404 static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), | 432 static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), |
| 405 kN32_SkColorType, kOpaque_SkAlphaType); | 433 cfaPattern.v * cfaPattern.h); |
| 406 | |
| 407 // The DNG SDK scales only for at demosaicing, so only when a mosaic info | |
| 408 // is available also scale is available. | |
| 409 fIsScalable = fNegative->GetMosaicInfo() != nullptr; | |
| 410 fIsXtransImage = fIsScalable | |
| 411 ? (fNegative->GetMosaicInfo()->fCFAPatternSize.v == 6 | |
| 412 && fNegative->GetMosaicInfo()->fCFAPatternSize.h == 6) | |
| 413 : false; | |
| 414 return true; | 434 return true; |
| 415 } catch (...) { | 435 } catch (...) { |
| 416 fNegative.reset(nullptr); | |
|
scroggo
2016/02/03 15:56:02
Why is this no longer necessary?
ebrauer
2016/02/04 15:17:08
This is unrelated to the cl, but it is somehow mis
| |
| 417 return false; | 436 return false; |
| 418 } | 437 } |
| 419 } | 438 } |
| 420 | 439 |
| 421 SkDngImage(SkRawStream* stream) | 440 SkDngImage(SkRawStream* stream) |
| 422 : fStream(stream) {} | 441 : fStream(stream) {} |
| 423 | 442 |
| 424 SkDngMemoryAllocator fAllocator; | 443 SkDngMemoryAllocator fAllocator; |
| 425 SkAutoTDelete<SkRawStream> fStream; | 444 SkAutoTDelete<SkRawStream> fStream; |
| 426 SkAutoTDelete<dng_host> fHost; | 445 SkAutoTDelete<dng_host> fHost; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); | 578 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); |
| 560 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); | 579 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); |
| 561 return sizeFloor == dim || sizeCeil == dim; | 580 return sizeFloor == dim || sizeCeil == dim; |
| 562 } | 581 } |
| 563 | 582 |
| 564 SkRawCodec::~SkRawCodec() {} | 583 SkRawCodec::~SkRawCodec() {} |
| 565 | 584 |
| 566 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 585 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
| 567 : INHERITED(dngImage->getImageInfo(), nullptr) | 586 : INHERITED(dngImage->getImageInfo(), nullptr) |
| 568 , fDngImage(dngImage) {} | 587 , fDngImage(dngImage) {} |
| OLD | NEW |