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

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: Respond to comments. 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 | « gyp/images.gyp ('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"
11 #include "SkColorPriv.h"
11 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
12 #include "SkScaledBitmapSampler.h" 13 #include "SkScaledBitmapSampler.h"
13 #include "SkStream.h" 14 #include "SkStream.h"
14 #include "SkColorPriv.h" 15 #include "SkStreamHelpers.h"
15 #include "SkTDArray.h" 16 #include "SkTDArray.h"
16 #include "SkTRegistry.h" 17 #include "SkTRegistry.h"
17 18
18 class SkBMPImageDecoder : public SkImageDecoder { 19 class SkBMPImageDecoder : public SkImageDecoder {
19 public: 20 public:
20 SkBMPImageDecoder() {} 21 SkBMPImageDecoder() {}
21 22
22 virtual Format getFormat() const SK_OVERRIDE { 23 virtual Format getFormat() const SK_OVERRIDE {
23 return kBMP_Format; 24 return kBMP_Format;
24 } 25 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 SkTDArray<uint8_t> fRGB; 90 SkTDArray<uint8_t> fRGB;
90 int fWidth; 91 int fWidth;
91 int fHeight; 92 int fHeight;
92 bool fJustBounds; 93 bool fJustBounds;
93 }; 94 };
94 95
95 bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { 96 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 97 // First read the entire stream, so that all of the data can be passed to
97 // the BmpDecoderHelper. 98 // the BmpDecoderHelper.
98 99
99 // Byte length of all of the data.
100 size_t length;
101 // Allocated space used to hold the data. 100 // Allocated space used to hold the data.
102 SkAutoMalloc storage; 101 SkAutoMalloc storage;
103 102 // Byte length of all of the data.
104 if (stream->hasLength()) { 103 const size_t length = CopyStreamToStorage(&storage, stream);
105 length = stream->getLength(); 104 if (0 == length) {
106 void* dst = storage.reset(length); 105 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 } 106 }
125 107
126 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode; 108 const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
127 SkBmpDecoderCallback callback(justBounds); 109 SkBmpDecoderCallback callback(justBounds);
128 110
129 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...] 111 // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...]
130 { 112 {
131 image_codec::BmpDecoderHelper helper; 113 image_codec::BmpDecoderHelper helper;
132 const int max_pixels = 16383*16383; // max width*height 114 const int max_pixels = 16383*16383; // max width*height
133 if (!helper.DecodeImage((const char*)storage.get(), length, 115 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(); 155 const int dstHeight = sampler.scaledHeight();
174 const uint8_t* srcRow = callback.rgb(); 156 const uint8_t* srcRow = callback.rgb();
175 157
176 srcRow += sampler.srcY0() * srcRowBytes; 158 srcRow += sampler.srcY0() * srcRowBytes;
177 for (int y = 0; y < dstHeight; y++) { 159 for (int y = 0; y < dstHeight; y++) {
178 sampler.next(srcRow); 160 sampler.next(srcRow);
179 srcRow += sampler.srcDY() * srcRowBytes; 161 srcRow += sampler.srcDY() * srcRowBytes;
180 } 162 }
181 return true; 163 return true;
182 } 164 }
OLDNEW
« no previous file with comments | « gyp/images.gyp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698