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