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 const size_t sizeToRead = newSize - fStreamBuffer.bytesWritten(); | 270 // Try to read at least 256 bytes to avoid to many small reads. |
adaubert
2016/01/28 14:20:25
FYI: In Snapseed we usually read 8192, same applie
yujieqin
2016/01/28 14:27:44
I don't have preference here. msarett@ & scroggo@,
msarett
2016/01/28 16:23:44
I guess how much we need really depends on the ima
scroggo
2016/01/28 16:49:58
As Matt suggested, the ideal number will depend on
msarett
2016/01/28 17:00:35
In the case that Piex can find a preview, I think
| |
271 SkAutoTMalloc<uint8> tempBuffer(sizeToRead); | 271 const size_t minSizeToRead = 256; |
scroggo
2016/01/28 16:49:57
nit: This is effectively a constant, which we woul
yujieqin
2016/02/01 16:25:19
Done.
| |
272 const size_t sizeMustRead = newSize - fStreamBuffer.bytesWritten(); | |
scroggo
2016/01/28 16:49:58
nit: These names don't distinguish themselves very
yujieqin
2016/02/01 16:25:19
Done.
| |
273 const size_t sizeToRead = SkTMax(minSizeToRead, sizeMustRead); | |
274 SkAutoSTMalloc<minSizeToRead, uint8> tempBuffer(sizeToRead); | |
272 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); | 275 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); |
273 if (bytesRead != sizeToRead) { | 276 if (bytesRead < sizeMustRead) { |
274 return false; | 277 return false; |
275 } | 278 } |
276 return fStreamBuffer.write(tempBuffer.get(), bytesRead); | 279 return fStreamBuffer.write(tempBuffer.get(), bytesRead); |
277 } | 280 } |
278 | 281 |
279 SkAutoTDelete<SkStream> fStream; | 282 SkAutoTDelete<SkStream> fStream; |
280 bool fWholeStreamRead; | 283 bool fWholeStreamRead; |
281 | 284 |
282 SkDynamicMemoryWStream fStreamBuffer; | 285 SkDynamicMemoryWStream fStreamBuffer; |
283 | 286 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 }; | 434 }; |
432 | 435 |
433 /* | 436 /* |
434 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe w image, create a | 437 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe w image, create a |
435 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr. In other cases, | 438 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr. In other cases, |
436 * fallback to create SkRawCodec for DNG images. | 439 * fallback to create SkRawCodec for DNG images. |
437 */ | 440 */ |
438 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { | 441 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { |
439 SkAutoTDelete<SkRawStream> rawStream(new SkRawStream(stream)); | 442 SkAutoTDelete<SkRawStream> rawStream(new SkRawStream(stream)); |
440 ::piex::PreviewImageData imageData; | 443 ::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 |