Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: src/codec/SkRawCodec.cpp

Issue 1659873002: Updates Piex and uses it to obtain the DNG dimensions. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Adds unit test. Removes rotation code. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « resources/sample_1mp_rotated.dng ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 ThrowReadFile(); 391 ThrowReadFile();
392 } 392 }
393 } 393 }
394 394
395 private: 395 private:
396 SkRawStream* fStream; 396 SkRawStream* fStream;
397 }; 397 };
398 398
399 class SkDngImage { 399 class SkDngImage {
400 public: 400 public:
401 // Will take the ownership of the stream. 401 /*
402 * Initializes the object with the information from Piex in a first attempt. This way it can
403 * save time and storage to obtain the DNG dimensions and color filter array (CFA) pattern
404 * which is essential for the demosaicing of the sensor image.
405 * Note: this will take the ownership of the stream.
406 */
402 static SkDngImage* NewFromStream(SkRawStream* stream) { 407 static SkDngImage* NewFromStream(SkRawStream* stream) {
403 SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream)); 408 SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream));
404 if (!dngImage->readDng()) { 409 if (!dngImage->initFromPiex()) {
405 return nullptr; 410 if (!dngImage->readDng()) {
411 return nullptr;
412 }
406 } 413 }
407 414
408 SkASSERT(dngImage->fNegative);
409 return dngImage.release(); 415 return dngImage.release();
410 } 416 }
411 417
412 /* 418 /*
413 * Renders the DNG image to the size. The DNG SDK only allows scaling close to integer factors 419 * Renders the DNG image to the size. The DNG SDK only allows scaling close to integer factors
414 * down to 80 pixels on the short edge. The rendered image will be close to the specified size, 420 * down to 80 pixels on the short edge. The rendered image will be close to the specified size,
415 * but there is no guarantee that any of the edges will match the requested size. E.g. 421 * but there is no guarantee that any of the edges will match the requested size. E.g.
416 * 100% size: 4000 x 3000 422 * 100% size: 4000 x 3000
417 * requested size: 1600 x 1200 423 * requested size: 1600 x 1200
418 * returned size could be: 2000 x 1500 424 * returned size could be: 2000 x 1500
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 476
471 bool isScalable() const { 477 bool isScalable() const {
472 return fIsScalable; 478 return fIsScalable;
473 } 479 }
474 480
475 bool isXtransImage() const { 481 bool isXtransImage() const {
476 return fIsXtransImage; 482 return fIsXtransImage;
477 } 483 }
478 484
479 private: 485 private:
486 void init(const int width, const int height, const dng_point& cfaPatternSize ) {
487 fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_ SkAlphaType);
488
489 // The DNG SDK scales only during demosaicing, so scaling is only possib le when
490 // a mosaic info is available.
491 fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0;
492 fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize. h == 6) : false;
493 }
494
495 bool initFromPiex() {
496 // Does not take the ownership of rawStream.
497 SkPiexStream piexStream(fStream.get());
498 ::piex::PreviewImageData imageData;
499 if (::piex::IsRaw(&piexStream)
500 && ::piex::GetPreviewImageData(&piexStream, &imageData) == ::piex::E rror::kOk)
501 {
502 dng_point cfaPatternSize(imageData.cfa_pattern_dim[1], imageData.cfa _pattern_dim[0]);
503 this->init(static_cast<int>(imageData.full_width),
504 static_cast<int>(imageData.full_height), cfaPatternSize);
505 return true;
506 }
507 return false;
508 }
509
480 bool readDng() { 510 bool readDng() {
481 // Due to the limit of DNG SDK, we need to reset host and info. 511 // Due to the limit of DNG SDK, we need to reset host and info.
482 fHost.reset(new SkDngHost(&fAllocator)); 512 fHost.reset(new SkDngHost(&fAllocator));
483 fInfo.reset(new dng_info); 513 fInfo.reset(new dng_info);
484 fDngStream.reset(new SkDngStream(fStream)); 514 fDngStream.reset(new SkDngStream(fStream));
485 try { 515 try {
486 fHost->ValidateSizes(); 516 fHost->ValidateSizes();
487 fInfo->Parse(*fHost, *fDngStream); 517 fInfo->Parse(*fHost, *fDngStream);
488 fInfo->PostParse(*fHost); 518 fInfo->PostParse(*fHost);
489 if (!fInfo->IsValidDNG()) { 519 if (!fInfo->IsValidDNG()) {
490 return false; 520 return false;
491 } 521 }
492 522
493 fNegative.reset(fHost->Make_dng_negative()); 523 fNegative.reset(fHost->Make_dng_negative());
494 fNegative->Parse(*fHost, *fDngStream, *fInfo); 524 fNegative->Parse(*fHost, *fDngStream, *fInfo);
495 fNegative->PostParse(*fHost, *fDngStream, *fInfo); 525 fNegative->PostParse(*fHost, *fDngStream, *fInfo);
496 fNegative->SynchronizeMetadata(); 526 fNegative->SynchronizeMetadata();
497 527
498 fImageInfo = SkImageInfo::Make( 528 dng_point cfaPatternSize(0, 0);
499 static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), 529 if (fNegative->GetMosaicInfo() != nullptr) {
500 static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), 530 cfaPatternSize = fNegative->GetMosaicInfo()->fCFAPatternSize;
501 kN32_SkColorType, kOpaque_SkAlphaType); 531 }
502 532 this->init(static_cast<int>(fNegative->DefaultCropSizeH().As_real64( )),
503 // The DNG SDK scales only for at demosaicing, so only when a mosaic info 533 static_cast<int>(fNegative->DefaultCropSizeV().As_real64( )),
504 // is available also scale is available. 534 cfaPatternSize);
505 fIsScalable = fNegative->GetMosaicInfo() != nullptr;
506 fIsXtransImage = fIsScalable
507 ? (fNegative->GetMosaicInfo()->fCFAPatternSize.v == 6
508 && fNegative->GetMosaicInfo()->fCFAPatternSize.h == 6)
509 : false;
510 return true; 535 return true;
511 } catch (...) { 536 } catch (...) {
512 fNegative.reset(nullptr);
513 return false; 537 return false;
514 } 538 }
515 } 539 }
516 540
517 SkDngImage(SkRawStream* stream) 541 SkDngImage(SkRawStream* stream)
518 : fStream(stream) {} 542 : fStream(stream) {}
519 543
520 SkDngMemoryAllocator fAllocator; 544 SkDngMemoryAllocator fAllocator;
521 SkAutoTDelete<SkRawStream> fStream; 545 SkAutoTDelete<SkRawStream> fStream;
522 SkAutoTDelete<dng_host> fHost; 546 SkAutoTDelete<dng_host> fHost;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); 688 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge));
665 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); 689 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge));
666 return sizeFloor == dim || sizeCeil == dim; 690 return sizeFloor == dim || sizeCeil == dim;
667 } 691 }
668 692
669 SkRawCodec::~SkRawCodec() {} 693 SkRawCodec::~SkRawCodec() {}
670 694
671 SkRawCodec::SkRawCodec(SkDngImage* dngImage) 695 SkRawCodec::SkRawCodec(SkDngImage* dngImage)
672 : INHERITED(dngImage->getImageInfo(), nullptr) 696 : INHERITED(dngImage->getImageInfo(), nullptr)
673 , fDngImage(dngImage) {} 697 , fDngImage(dngImage) {}
OLDNEW
« no previous file with comments | « resources/sample_1mp_rotated.dng ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698