diff options
author | 2013-08-21 14:59:03 +0000 | |
---|---|---|
committer | 2013-08-21 14:59:03 +0000 | |
commit | 2fd740ffba01e56864247a78297efcf0636554eb (patch) | |
tree | d1d48c965bd5a40066d7242548e9df9f54dda6b6 /src/images | |
parent | 3c8730a84e469cfc71866a2f8d6bfd1d2ea689e3 (diff) |
Make BMP decoder not depend on call to getLength.
If the decoder does not have a length, use an SkDynamicMemoryStream
to copy it to contiguous memory, to be passed to BmpDecoderHelper.
BUG=https://b.corp.google.com/issue?id=8432093
R=djsollen@google.com
Review URL: https://codereview.chromium.org/22877020
git-svn-id: http://skia.googlecode.com/svn/trunk@10849 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r-- | src/images/SkImageDecoder_libbmp.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp index 14b9090f9b..6c5ae27c47 100644 --- a/src/images/SkImageDecoder_libbmp.cpp +++ b/src/images/SkImageDecoder_libbmp.cpp @@ -93,12 +93,34 @@ private: }; bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { - - size_t length = stream->getLength(); - SkAutoMalloc storage(length); - - if (stream->read(storage.get(), length) != length) { - return false; + // First read the entire stream, so that all of the data can be passed to + // the BmpDecoderHelper. + + // Byte length of all of the data. + size_t length; + // Allocated space used to hold the data. + SkAutoMalloc storage; + + if (stream->hasLength()) { + length = stream->getLength(); + void* dst = storage.reset(length); + if (stream->read(dst, length) != length) { + return false; + } + } else { + SkDynamicMemoryWStream tempStream; + // Arbitrary buffer size. + const size_t bufferSize = 256 * 1024; // 256 KB + char buffer[bufferSize]; + length = 0; + do { + size_t bytesRead = stream->read(buffer, bufferSize); + tempStream.write(buffer, bytesRead); + length += bytesRead; + SkASSERT(tempStream.bytesWritten() == length); + } while (!stream->isAtEnd()); + void* dst = storage.reset(length); + tempStream.copyTo(dst); } const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; |