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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/images/SkImageDecoder.cpp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "bmpdecoderhelper.h" 10 #include "bmpdecoderhelper.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 int height() const { return fHeight; } 85 int height() const { return fHeight; }
86 const uint8_t* rgb() const { return fRGB.begin(); } 86 const uint8_t* rgb() const { return fRGB.begin(); }
87 87
88 private: 88 private:
89 SkTDArray<uint8_t> fRGB; 89 SkTDArray<uint8_t> fRGB;
90 int fWidth; 90 int fWidth;
91 int fHeight; 91 int fHeight;
92 bool fJustBounds; 92 bool fJustBounds;
93 }; 93 };
94 94
95 // Defined in SkImageDecoder.cpp
96 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.
97
95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { 98 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
96 // First read the entire stream, so that all of the data can be passed to 99 // First read the entire stream, so that all of the data can be passed to
97 // the BmpDecoderHelper. 100 // the BmpDecoderHelper.
98 101
99 // Byte length of all of the data.
100 size_t length;
101 // Allocated space used to hold the data. 102 // Allocated space used to hold the data.
102 SkAutoMalloc storage; 103 SkAutoMalloc storage;
103 104 // Byte length of all of the data.
104 if (stream->hasLength()) { 105 const size_t length = copy_stream_to_storage(&storage, stream);
105 length = stream->getLength(); 106 if (0 == length) {
106 void* dst = storage.reset(length); 107 return 0;
107 if (stream->read(dst, length) != length) {
108 return false;
109 }
110 } else {
111 SkDynamicMemoryWStream tempStream;
112 // Arbitrary buffer size.
113 const size_t bufferSize = 256 * 1024; // 256 KB
114 char buffer[bufferSize];
115 length = 0;
116 do {
117 size_t bytesRead = stream->read(buffer, bufferSize);
118 tempStream.write(buffer, bytesRead);
119 length += bytesRead;
120 SkASSERT(tempStream.bytesWritten() == length);
121 } while (!stream->isAtEnd());
122 void* dst = storage.reset(length);
123 tempStream.copyTo(dst);
124 } 108 }
125 109
126 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; 110 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
127 SkBmpDecoderCallback callback(justBounds); 111 SkBmpDecoderCallback callback(justBounds);
128 112
129 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] 113 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...]
130 { 114 {
131 image_codec::BmpDecoderHelper helper; 115 image_codec::BmpDecoderHelper helper;
132 const int max_pixels = 16383*16383; // max width*height 116 const int max_pixels = 16383*16383; // max width*height
133 if (!helper.DecodeImage((const char*)storage.get(), length, 117 if (!helper.DecodeImage((const char*)storage.get(), length,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const int dstHeight = sampler.scaledHeight(); 157 const int dstHeight = sampler.scaledHeight();
174 const uint8_t* srcRow = callback.rgb(); 158 const uint8_t* srcRow = callback.rgb();
175 159
176 srcRow += sampler.srcY0() * srcRowBytes; 160 srcRow += sampler.srcY0() * srcRowBytes;
177 for (int y = 0; y < dstHeight; y++) { 161 for (int y = 0; y < dstHeight; y++) {
178 sampler.next(srcRow); 162 sampler.next(srcRow);
179 srcRow += sampler.srcDY() * srcRowBytes; 163 srcRow += sampler.srcDY() * srcRowBytes;
180 } 164 }
181 return true; 165 return true;
182 } 166 }
OLDNEW
« 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