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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void read(void* data, uint32 count, uint64 offset) { | 144 void read(void* data, uint32 count, uint64 offset) { |
145 if (count == 0 && offset == 0) { | 145 if (count == 0 && offset == 0) { |
146 return; | 146 return; |
147 } | 147 } |
148 size_t sum; | 148 size_t sum; |
149 if (!safe_add_to_size_t(static_cast<uint64>(count), offset, &sum) || | 149 if (!safe_add_to_size_t(static_cast<uint64>(count), offset, &sum) || |
150 !this->bufferMoreData(sum)) { | 150 !this->bufferMoreData(sum)) { |
151 ThrowReadFile(); | 151 ThrowReadFile(); |
152 } | 152 } |
153 | 153 |
154 if (!fStreamBuffer.read(data, offset, count)) { | 154 if (!fStreamBuffer.read(data, static_cast<size_t>(offset), count)) { |
155 ThrowReadFile(); | 155 ThrowReadFile(); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 // Note: if the newSize == kReadToEnd (0), this function will read to the en
d of stream. | 160 // Note: if the newSize == kReadToEnd (0), this function will read to the en
d of stream. |
161 bool bufferMoreData(size_t newSize) { | 161 bool bufferMoreData(size_t newSize) { |
162 if (newSize == kReadToEnd) { | 162 if (newSize == kReadToEnd) { |
163 if (fWholeStreamRead) { // already read-to-end. | 163 if (fWholeStreamRead) { // already read-to-end. |
164 return true; | 164 return true; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 fInfo->PostParse(*fHost); | 297 fInfo->PostParse(*fHost); |
298 if (!fInfo->IsValidDNG()) { | 298 if (!fInfo->IsValidDNG()) { |
299 return false; | 299 return false; |
300 } | 300 } |
301 | 301 |
302 fNegative.reset(fHost->Make_dng_negative()); | 302 fNegative.reset(fHost->Make_dng_negative()); |
303 fNegative->Parse(*fHost, *fDngStream, *fInfo); | 303 fNegative->Parse(*fHost, *fDngStream, *fInfo); |
304 fNegative->PostParse(*fHost, *fDngStream, *fInfo); | 304 fNegative->PostParse(*fHost, *fDngStream, *fInfo); |
305 fNegative->SynchronizeMetadata(); | 305 fNegative->SynchronizeMetadata(); |
306 | 306 |
307 fImageInfo = SkImageInfo::Make(fNegative->DefaultCropSizeH().As_real
64(), | 307 fImageInfo = SkImageInfo::Make( |
308 fNegative->DefaultCropSizeV().As_real
64(), | 308 static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), |
309 kN32_SkColorType, kOpaque_SkAlphaType
); | 309 static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), |
| 310 kN32_SkColorType, kOpaque_SkAlphaType); |
310 | 311 |
311 // The DNG SDK scales only for at demosaicing, so only when a mosaic
info | 312 // The DNG SDK scales only for at demosaicing, so only when a mosaic
info |
312 // is available also scale is available. | 313 // is available also scale is available. |
313 fIsScalable = fNegative->GetMosaicInfo() != nullptr; | 314 fIsScalable = fNegative->GetMosaicInfo() != nullptr; |
314 fIsXtransImage = fIsScalable | 315 fIsXtransImage = fIsScalable |
315 ? (fNegative->GetMosaicInfo()->fCFAPatternSize.v == 6 | 316 ? (fNegative->GetMosaicInfo()->fCFAPatternSize.v == 6 |
316 && fNegative->GetMosaicInfo()->fCFAPatternSize.h == 6) | 317 && fNegative->GetMosaicInfo()->fCFAPatternSize.h == 6) |
317 : false; | 318 : false; |
318 return true; | 319 return true; |
319 } catch (...) { | 320 } catch (...) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 435 } |
435 | 436 |
436 SkISize SkRawCodec::onGetScaledDimensions(float desiredScale) const { | 437 SkISize SkRawCodec::onGetScaledDimensions(float desiredScale) const { |
437 SkASSERT(desiredScale <= 1.f); | 438 SkASSERT(desiredScale <= 1.f); |
438 const SkISize dim = this->getInfo().dimensions(); | 439 const SkISize dim = this->getInfo().dimensions(); |
439 if (!fDngImage->isScalable()) { | 440 if (!fDngImage->isScalable()) { |
440 return dim; | 441 return dim; |
441 } | 442 } |
442 | 443 |
443 // Limits the minimum size to be 80 on the short edge. | 444 // Limits the minimum size to be 80 on the short edge. |
444 const float shortEdge = SkTMin(dim.fWidth, dim.fHeight); | 445 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight)); |
445 if (desiredScale < 80.f / shortEdge) { | 446 if (desiredScale < 80.f / shortEdge) { |
446 desiredScale = 80.f / shortEdge; | 447 desiredScale = 80.f / shortEdge; |
447 } | 448 } |
448 | 449 |
449 // For Xtrans images, the integer-factor scaling does not support the half-s
ize scaling case | 450 // For Xtrans images, the integer-factor scaling does not support the half-s
ize scaling case |
450 // (stronger downscalings are fine). In this case, returns the factor "3" sc
aling instead. | 451 // (stronger downscalings are fine). In this case, returns the factor "3" sc
aling instead. |
451 if (fDngImage->isXtransImage() && desiredScale > 1.f / 3.f && desiredScale <
1.f) { | 452 if (fDngImage->isXtransImage() && desiredScale > 1.f / 3.f && desiredScale <
1.f) { |
452 desiredScale = 1.f / 3.f; | 453 desiredScale = 1.f / 3.f; |
453 } | 454 } |
454 | 455 |
455 // Round to integer-factors. | 456 // Round to integer-factors. |
456 const float finalScale = std::floor(1.f/ desiredScale); | 457 const float finalScale = std::floor(1.f/ desiredScale); |
457 return SkISize::Make(std::floor(dim.fWidth / finalScale), | 458 return SkISize::Make(static_cast<int32_t>(std::floor(dim.fWidth / finalScale
)), |
458 std::floor(dim.fHeight / finalScale)); | 459 static_cast<int32_t>(std::floor(dim.fHeight / finalScal
e))); |
459 } | 460 } |
460 | 461 |
461 bool SkRawCodec::onDimensionsSupported(const SkISize& dim) { | 462 bool SkRawCodec::onDimensionsSupported(const SkISize& dim) { |
462 const SkISize fullDim = this->getInfo().dimensions(); | 463 const SkISize fullDim = this->getInfo().dimensions(); |
463 const float fullShortEdge = SkTMin(fullDim.fWidth, fullDim.fHeight); | 464 const float fullShortEdge = static_cast<float>(SkTMin(fullDim.fWidth, fullDi
m.fHeight)); |
464 const float shortEdge = SkTMin(dim.fWidth, dim.fHeight); | 465 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight)); |
465 | 466 |
466 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); | 467 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); |
467 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); | 468 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); |
468 return sizeFloor == dim || sizeCeil == dim; | 469 return sizeFloor == dim || sizeCeil == dim; |
469 } | 470 } |
470 | 471 |
471 SkRawCodec::~SkRawCodec() {} | 472 SkRawCodec::~SkRawCodec() {} |
472 | 473 |
473 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 474 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
474 : INHERITED(dngImage->getImageInfo(), nullptr) | 475 : INHERITED(dngImage->getImageInfo(), nullptr) |
475 , fDngImage(dngImage) {} | 476 , fDngImage(dngImage) {} |
OLD | NEW |