Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: src/images/SkImageDecoder_libbmp.cpp

Issue 23330002: Avoid getLength in ico decoder. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/images/SkImageDecoder.cpp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libbmp.cpp
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp
index 6c5ae27c478a22e13b3b62d77e59f0776ad45b23..e078d327f3e8581eeacc4cf7aa0d0f8144dfe0a2 100644
--- a/src/images/SkImageDecoder_libbmp.cpp
+++ b/src/images/SkImageDecoder_libbmp.cpp
@@ -92,35 +92,19 @@ private:
bool fJustBounds;
};
+// Defined in SkImageDecoder.cpp
+extern size_t copy_stream_to_storage(SkAutoMalloc* storage, SkStream* stream);
djsollen 2013/08/19 16:57:20 why not make it a protected method on SkImageDecod
scroggo 2013/08/19 18:45:55 Done.
+
bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
// 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);
+ // Byte length of all of the data.
+ const size_t length = copy_stream_to_storage(&storage, stream);
+ if (0 == length) {
+ return 0;
}
const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
« no previous file with comments | « src/images/SkImageDecoder.cpp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698