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

Side by Side Diff: src/images/SkImageDecoder_libico.cpp

Issue 1604963002: SkStream/Priv cleanups (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update header description Created 4 years, 11 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
« no previous file with comments | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkImageDecoder_pkm.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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * 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
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkData.h"
9 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
10 #include "SkStream.h" 11 #include "SkStream.h"
11 #include "SkStreamPriv.h" 12 #include "SkStreamPriv.h"
12 #include "SkTypes.h" 13 #include "SkTypes.h"
13 14
14 class SkICOImageDecoder : public SkImageDecoder { 15 class SkICOImageDecoder : public SkImageDecoder {
15 public: 16 public:
16 SkICOImageDecoder(); 17 SkICOImageDecoder();
17 18
18 Format getFormat() const override { 19 Format getFormat() const override {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Add 4 to ensure that it is still a multiple of 4. 68 // Add 4 to ensure that it is still a multiple of 4.
68 if (4 == bitCount && (w & 0x1)) { 69 if (4 == bitCount && (w & 0x1)) {
69 return (w + 1) << 2; 70 return (w + 1) << 2;
70 } 71 }
71 // Otherwise return 0, which will allow it to be calculated automatically. 72 // Otherwise return 0, which will allow it to be calculated automatically.
72 return 0; 73 return 0;
73 } 74 }
74 75
75 SkImageDecoder::Result SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) 76 SkImageDecoder::Result SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* b m, Mode mode)
76 { 77 {
77 SkAutoMalloc autoMal; 78 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream));
78 const size_t length = SkCopyStreamToStorage(&autoMal, stream); 79 if (!data) {
80 return kFailure;
81 }
82
83 const size_t length = data->size();
79 // Check that the buffer is large enough to read the directory header 84 // Check that the buffer is large enough to read the directory header
80 if (length < 6) { 85 if (length < 6) {
81 return kFailure; 86 return kFailure;
82 } 87 }
83 88
84 unsigned char* buf = (unsigned char*)autoMal.get(); 89 unsigned char* buf = (unsigned char*) data->data();
85 90
86 //these should always be the same - should i use for error checking? - what about files that have some 91 //these should always be the same - should i use for error checking? - what about files that have some
87 //incorrect values, but still decode properly? 92 //incorrect values, but still decode properly?
88 int reserved = read2Bytes(buf, 0); // 0 93 int reserved = read2Bytes(buf, 0); // 0
89 int type = read2Bytes(buf, 2); // 1 94 int type = read2Bytes(buf, 2); // 1
90 if (reserved != 0 || type != 1) { 95 if (reserved != 0 || type != 1) {
91 return kFailure; 96 return kFailure;
92 } 97 }
93 98
94 int count = read2Bytes(buf, 4); 99 int count = read2Bytes(buf, 4);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); 448 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
444 449
445 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { 450 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
446 if (is_ico(stream)) { 451 if (is_ico(stream)) {
447 return SkImageDecoder::kICO_Format; 452 return SkImageDecoder::kICO_Format;
448 } 453 }
449 return SkImageDecoder::kUnknown_Format; 454 return SkImageDecoder::kUnknown_Format;
450 } 455 }
451 456
452 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); 457 static SkImageDecoder_FormatReg gFormatReg(get_format_ico);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkImageDecoder_pkm.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698