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

Side by Side Diff: src/images/SkImageDecoder_libico.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 | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkStreamHelpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
2 /* 1 /*
3 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 8 #include "SkColorPriv.h"
10 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
11 #include "SkStream.h" 10 #include "SkStream.h"
12 #include "SkColorPriv.h" 11 #include "SkStreamHelpers.h"
13 #include "SkTypes.h" 12 #include "SkTypes.h"
14 13
15 class SkICOImageDecoder : public SkImageDecoder { 14 class SkICOImageDecoder : public SkImageDecoder {
16 public: 15 public:
17 SkICOImageDecoder(); 16 SkICOImageDecoder();
18 17
19 virtual Format getFormat() const SK_OVERRIDE { 18 virtual Format getFormat() const SK_OVERRIDE {
20 return kICO_Format; 19 return kICO_Format;
21 } 20 }
22 21
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Add 4 to ensure that it is still a multiple of 4. 67 // Add 4 to ensure that it is still a multiple of 4.
69 if (4 == bitCount && (w & 0x1)) { 68 if (4 == bitCount && (w & 0x1)) {
70 return (w + 1) << 2; 69 return (w + 1) << 2;
71 } 70 }
72 // Otherwise return 0, which will allow it to be calculated automatically. 71 // Otherwise return 0, which will allow it to be calculated automatically.
73 return 0; 72 return 0;
74 } 73 }
75 74
76 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) 75 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
77 { 76 {
78 size_t length = stream->getLength(); 77 SkAutoMalloc autoMal;
79 SkAutoMalloc autoMal(length); 78 const size_t length = CopyStreamToStorage(&autoMal, stream);
80 unsigned char* buf = (unsigned char*)autoMal.get(); 79 if (0 == length) {
81 if (stream->read((void*)buf, length) != length) {
82 return false; 80 return false;
83 } 81 }
84 82
83 unsigned char* buf = (unsigned char*)autoMal.get();
84
85 //these should always be the same - should i use for error checking? - what about files that have some 85 //these should always be the same - should i use for error checking? - what about files that have some
86 //incorrect values, but still decode properly? 86 //incorrect values, but still decode properly?
87 int reserved = read2Bytes(buf, 0); // 0 87 int reserved = read2Bytes(buf, 0); // 0
88 int type = read2Bytes(buf, 2); // 1 88 int type = read2Bytes(buf, 2); // 1
89 if (reserved != 0 || type != 1) 89 if (reserved != 0 || type != 1)
90 return false; 90 return false;
91 int count = read2Bytes(buf, 4); 91 int count = read2Bytes(buf, 4);
92 92
93 //need to at least have enough space to hold the initial table of info 93 //need to at least have enough space to hold the initial table of info
94 if (length < (size_t)(6 + count*16)) 94 if (length < (size_t)(6 + count*16))
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); 410 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory);
411 411
412 static SkImageDecoder::Format get_format_ico(SkStream* stream) { 412 static SkImageDecoder::Format get_format_ico(SkStream* stream) {
413 if (is_ico(stream)) { 413 if (is_ico(stream)) {
414 return SkImageDecoder::kICO_Format; 414 return SkImageDecoder::kICO_Format;
415 } 415 }
416 return SkImageDecoder::kUnknown_Format; 416 return SkImageDecoder::kUnknown_Format;
417 } 417 }
418 418
419 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico) ; 419 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico) ;
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkStreamHelpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698