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