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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return SkStreamCopy(&fStreamBuffer, fStream.get()); | 260 return SkStreamCopy(&fStreamBuffer, fStream.get()); |
261 } | 261 } |
262 | 262 |
263 if (newSize <= fStreamBuffer.bytesWritten()) { // already buffered to n
ewSize | 263 if (newSize <= fStreamBuffer.bytesWritten()) { // already buffered to n
ewSize |
264 return true; | 264 return true; |
265 } | 265 } |
266 if (fWholeStreamRead) { // newSize is larger than the whole stream. | 266 if (fWholeStreamRead) { // newSize is larger than the whole stream. |
267 return false; | 267 return false; |
268 } | 268 } |
269 | 269 |
270 // Try to read at least 8192 bytes to avoid to many small reads. | 270 const size_t sizeToRead = newSize - fStreamBuffer.bytesWritten(); |
271 const size_t kMinSizeToRead = 8192; | 271 SkAutoTMalloc<uint8> tempBuffer(sizeToRead); |
272 const size_t sizeRequested = newSize - fStreamBuffer.bytesWritten(); | |
273 const size_t sizeToRead = SkTMax(kMinSizeToRead, sizeRequested); | |
274 SkAutoSTMalloc<kMinSizeToRead, uint8> tempBuffer(sizeToRead); | |
275 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); | 272 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); |
276 if (bytesRead < sizeRequested) { | 273 if (bytesRead != sizeToRead) { |
277 return false; | 274 return false; |
278 } | 275 } |
279 return fStreamBuffer.write(tempBuffer.get(), bytesRead); | 276 return fStreamBuffer.write(tempBuffer.get(), bytesRead); |
280 } | 277 } |
281 | 278 |
282 SkAutoTDelete<SkStream> fStream; | 279 SkAutoTDelete<SkStream> fStream; |
283 bool fWholeStreamRead; | 280 bool fWholeStreamRead; |
284 | 281 |
285 SkDynamicMemoryWStream fStreamBuffer; | 282 SkDynamicMemoryWStream fStreamBuffer; |
286 | 283 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 }; | 431 }; |
435 | 432 |
436 /* | 433 /* |
437 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe
w image, create a | 434 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe
w image, create a |
438 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr.
In other cases, | 435 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr.
In other cases, |
439 * fallback to create SkRawCodec for DNG images. | 436 * fallback to create SkRawCodec for DNG images. |
440 */ | 437 */ |
441 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { | 438 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { |
442 SkAutoTDelete<SkRawStream> rawStream(new SkRawStream(stream)); | 439 SkAutoTDelete<SkRawStream> rawStream(new SkRawStream(stream)); |
443 ::piex::PreviewImageData imageData; | 440 ::piex::PreviewImageData imageData; |
| 441 // FIXME: ::piex::GetPreviewImageData() calls GetData() frequently with smal
l amounts, |
| 442 // resulting in many calls to bufferMoreData(). Could we make this more effi
cient by grouping |
| 443 // smaller requests together? |
444 if (::piex::IsRaw(rawStream.get())) { | 444 if (::piex::IsRaw(rawStream.get())) { |
445 ::piex::Error error = ::piex::GetPreviewImageData(rawStream.get(), &imag
eData); | 445 ::piex::Error error = ::piex::GetPreviewImageData(rawStream.get(), &imag
eData); |
446 | 446 |
447 if (error == ::piex::Error::kOk && imageData.preview_length > 0) { | 447 if (error == ::piex::Error::kOk && imageData.preview_length > 0) { |
448 #if !defined(GOOGLE3) | 448 #if !defined(GOOGLE3) |
449 // transferBuffer() is destructive to the rawStream. Abandon the raw
Stream after this | 449 // transferBuffer() is destructive to the rawStream. Abandon the raw
Stream after this |
450 // function call. | 450 // function call. |
451 // FIXME: one may avoid the copy of memoryStream and use the buffere
d rawStream. | 451 // FIXME: one may avoid the copy of memoryStream and use the buffere
d rawStream. |
452 SkMemoryStream* memoryStream = | 452 SkMemoryStream* memoryStream = |
453 rawStream->transferBuffer(imageData.preview_offset, imageDat
a.preview_length); | 453 rawStream->transferBuffer(imageData.preview_offset, imageDat
a.preview_length); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); | 559 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); |
560 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); | 560 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); |
561 return sizeFloor == dim || sizeCeil == dim; | 561 return sizeFloor == dim || sizeCeil == dim; |
562 } | 562 } |
563 | 563 |
564 SkRawCodec::~SkRawCodec() {} | 564 SkRawCodec::~SkRawCodec() {} |
565 | 565 |
566 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 566 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
567 : INHERITED(dngImage->getImageInfo(), nullptr) | 567 : INHERITED(dngImage->getImageInfo(), nullptr) |
568 , fDngImage(dngImage) {} | 568 , fDngImage(dngImage) {} |
OLD | NEW |