| 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" |
| 11 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkJpegCodec.h" | 12 #include "SkJpegCodec.h" |
| 13 #include "SkMutex.h" | |
| 14 #include "SkRawCodec.h" | 13 #include "SkRawCodec.h" |
| 15 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 16 #include "SkStream.h" | 15 #include "SkStream.h" |
| 17 #include "SkStreamPriv.h" | 16 #include "SkStreamPriv.h" |
| 18 #include "SkSwizzler.h" | 17 #include "SkSwizzler.h" |
| 19 #include "SkTArray.h" | |
| 20 #include "SkTaskGroup.h" | 18 #include "SkTaskGroup.h" |
| 21 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
| 22 #include "SkTypes.h" | 20 #include "SkTypes.h" |
| 23 | 21 |
| 24 #include "dng_area_task.h" | 22 #include "dng_area_task.h" |
| 25 #include "dng_color_space.h" | 23 #include "dng_color_space.h" |
| 26 #include "dng_errors.h" | |
| 27 #include "dng_exceptions.h" | 24 #include "dng_exceptions.h" |
| 28 #include "dng_host.h" | 25 #include "dng_host.h" |
| 29 #include "dng_info.h" | 26 #include "dng_info.h" |
| 30 #include "dng_memory.h" | 27 #include "dng_memory.h" |
| 31 #include "dng_render.h" | 28 #include "dng_render.h" |
| 32 #include "dng_stream.h" | 29 #include "dng_stream.h" |
| 33 | 30 |
| 34 #include "src/piex.h" | 31 #include "src/piex.h" |
| 35 | 32 |
| 36 #include <cmath> // for std::round,floor,ceil | 33 #include <cmath> // for std::round,floor,ceil |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // sub-tasks depending on the architecture. | 98 // sub-tasks depending on the architecture. |
| 102 const int maxTasks = static_cast<int>(task.MaxThreads()); | 99 const int maxTasks = static_cast<int>(task.MaxThreads()); |
| 103 | 100 |
| 104 SkTaskGroup taskGroup; | 101 SkTaskGroup taskGroup; |
| 105 | 102 |
| 106 // tileSize is typically 256x256 | 103 // tileSize is typically 256x256 |
| 107 const dng_point tileSize(task.FindTileSize(area)); | 104 const dng_point tileSize(task.FindTileSize(area)); |
| 108 const std::vector<dng_rect> taskAreas = compute_task_areas(maxTasks, are
a, tileSize); | 105 const std::vector<dng_rect> taskAreas = compute_task_areas(maxTasks, are
a, tileSize); |
| 109 const int numTasks = static_cast<int>(taskAreas.size()); | 106 const int numTasks = static_cast<int>(taskAreas.size()); |
| 110 | 107 |
| 111 SkMutex mutex; | |
| 112 SkTArray<dng_exception> exceptions; | |
| 113 task.Start(numTasks, tileSize, &Allocator(), Sniffer()); | 108 task.Start(numTasks, tileSize, &Allocator(), Sniffer()); |
| 114 for (int taskIndex = 0; taskIndex < numTasks; ++taskIndex) { | 109 for (int taskIndex = 0; taskIndex < numTasks; ++taskIndex) { |
| 115 taskGroup.add([&mutex, &exceptions, &task, this, taskIndex, taskArea
s, tileSize] { | 110 taskGroup.add([&task, this, taskIndex, taskAreas, tileSize] { |
| 116 try { | 111 task.ProcessOnThread(taskIndex, taskAreas[taskIndex], tileSize,
this->Sniffer()); |
| 117 task.ProcessOnThread(taskIndex, taskAreas[taskIndex], tileSi
ze, this->Sniffer()); | |
| 118 } catch (dng_exception& exception) { | |
| 119 SkAutoMutexAcquire lock(mutex); | |
| 120 exceptions.push_back(exception); | |
| 121 } catch (...) { | |
| 122 SkAutoMutexAcquire lock(mutex); | |
| 123 exceptions.push_back(dng_exception(dng_error_unknown)); | |
| 124 } | |
| 125 }); | 112 }); |
| 126 } | 113 } |
| 127 | 114 |
| 128 taskGroup.wait(); | 115 taskGroup.wait(); |
| 129 task.Finish(numTasks); | 116 task.Finish(numTasks); |
| 130 | |
| 131 // Currently we only re-throw the first catched exception. | |
| 132 if (!exceptions.empty()) { | |
| 133 Throw_dng_error(exceptions.front().ErrorCode(), nullptr, nullptr); | |
| 134 } | |
| 135 } | 117 } |
| 136 | 118 |
| 137 uint32 PerformAreaTaskThreads() override { | 119 uint32 PerformAreaTaskThreads() override { |
| 138 // FIXME: Need to get the real amount of available threads used in the S
kTaskGroup. | 120 // FIXME: Need to get the real amount of available threads used in the S
kTaskGroup. |
| 139 return kMaxMPThreads; | 121 return kMaxMPThreads; |
| 140 } | 122 } |
| 141 | 123 |
| 142 private: | 124 private: |
| 143 typedef dng_host INHERITED; | 125 typedef dng_host INHERITED; |
| 144 }; | 126 }; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 * requested size: 1600 x 1200 | 421 * requested size: 1600 x 1200 |
| 440 * returned size could be: 2000 x 1500 | 422 * returned size could be: 2000 x 1500 |
| 441 */ | 423 */ |
| 442 dng_image* render(int width, int height) { | 424 dng_image* render(int width, int height) { |
| 443 if (!fHost || !fInfo || !fNegative || !fDngStream) { | 425 if (!fHost || !fInfo || !fNegative || !fDngStream) { |
| 444 if (!this->readDng()) { | 426 if (!this->readDng()) { |
| 445 return nullptr; | 427 return nullptr; |
| 446 } | 428 } |
| 447 } | 429 } |
| 448 | 430 |
| 431 // render() takes ownership of fHost, fInfo, fNegative and fDngStream wh
en available. |
| 432 SkAutoTDelete<dng_host> host(fHost.release()); |
| 433 SkAutoTDelete<dng_info> info(fInfo.release()); |
| 434 SkAutoTDelete<dng_negative> negative(fNegative.release()); |
| 435 SkAutoTDelete<dng_stream> dngStream(fDngStream.release()); |
| 436 |
| 449 // DNG SDK preserves the aspect ratio, so it only needs to know the long
er dimension. | 437 // DNG SDK preserves the aspect ratio, so it only needs to know the long
er dimension. |
| 450 const int preferredSize = SkTMax(width, height); | 438 const int preferredSize = SkTMax(width, height); |
| 451 try { | 439 try { |
| 452 // render() takes ownership of fHost, fInfo, fNegative and fDngStrea
m when available. | |
| 453 SkAutoTDelete<dng_host> host(fHost.release()); | |
| 454 SkAutoTDelete<dng_info> info(fInfo.release()); | |
| 455 SkAutoTDelete<dng_negative> negative(fNegative.release()); | |
| 456 SkAutoTDelete<dng_stream> dngStream(fDngStream.release()); | |
| 457 | |
| 458 host->SetPreferredSize(preferredSize); | 440 host->SetPreferredSize(preferredSize); |
| 459 host->ValidateSizes(); | 441 host->ValidateSizes(); |
| 460 | 442 |
| 461 negative->ReadStage1Image(*host, *dngStream, *info); | 443 negative->ReadStage1Image(*host, *dngStream, *info); |
| 462 | 444 |
| 463 if (info->fMaskIndex != -1) { | 445 if (info->fMaskIndex != -1) { |
| 464 negative->ReadTransparencyMask(*host, *dngStream, *info); | 446 negative->ReadTransparencyMask(*host, *dngStream, *info); |
| 465 } | 447 } |
| 466 | 448 |
| 467 negative->ValidateRawImageDigest(*host); | 449 negative->ValidateRawImageDigest(*host); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 { | 499 { |
| 518 dng_point cfaPatternSize(imageData.cfa_pattern_dim[1], imageData.cfa
_pattern_dim[0]); | 500 dng_point cfaPatternSize(imageData.cfa_pattern_dim[1], imageData.cfa
_pattern_dim[0]); |
| 519 this->init(static_cast<int>(imageData.full_width), | 501 this->init(static_cast<int>(imageData.full_width), |
| 520 static_cast<int>(imageData.full_height), cfaPatternSize); | 502 static_cast<int>(imageData.full_height), cfaPatternSize); |
| 521 return true; | 503 return true; |
| 522 } | 504 } |
| 523 return false; | 505 return false; |
| 524 } | 506 } |
| 525 | 507 |
| 526 bool readDng() { | 508 bool readDng() { |
| 509 // Due to the limit of DNG SDK, we need to reset host and info. |
| 510 fHost.reset(new SkDngHost(&fAllocator)); |
| 511 fInfo.reset(new dng_info); |
| 512 fDngStream.reset(new SkDngStream(fStream)); |
| 527 try { | 513 try { |
| 528 // Due to the limit of DNG SDK, we need to reset host and info. | |
| 529 fHost.reset(new SkDngHost(&fAllocator)); | |
| 530 fInfo.reset(new dng_info); | |
| 531 fDngStream.reset(new SkDngStream(fStream)); | |
| 532 | |
| 533 fHost->ValidateSizes(); | 514 fHost->ValidateSizes(); |
| 534 fInfo->Parse(*fHost, *fDngStream); | 515 fInfo->Parse(*fHost, *fDngStream); |
| 535 fInfo->PostParse(*fHost); | 516 fInfo->PostParse(*fHost); |
| 536 if (!fInfo->IsValidDNG()) { | 517 if (!fInfo->IsValidDNG()) { |
| 537 return false; | 518 return false; |
| 538 } | 519 } |
| 539 | 520 |
| 540 fNegative.reset(fHost->Make_dng_negative()); | 521 fNegative.reset(fHost->Make_dng_negative()); |
| 541 fNegative->Parse(*fHost, *fDngStream, *fInfo); | 522 fNegative->Parse(*fHost, *fDngStream, *fInfo); |
| 542 fNegative->PostParse(*fHost, *fDngStream, *fInfo); | 523 fNegative->PostParse(*fHost, *fDngStream, *fInfo); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); | 682 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); |
| 702 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); | 683 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); |
| 703 return sizeFloor == dim || sizeCeil == dim; | 684 return sizeFloor == dim || sizeCeil == dim; |
| 704 } | 685 } |
| 705 | 686 |
| 706 SkRawCodec::~SkRawCodec() {} | 687 SkRawCodec::~SkRawCodec() {} |
| 707 | 688 |
| 708 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 689 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
| 709 : INHERITED(dngImage->getImageInfo(), nullptr) | 690 : INHERITED(dngImage->getImageInfo(), nullptr) |
| 710 , fDngImage(dngImage) {} | 691 , fDngImage(dngImage) {} |
| OLD | NEW |