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

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

Issue 647023006: Qualify the return value of SkImageDecoder::decode (Closed) Base URL: https://skia.googlesource.com/skia.git/+/master
Patch Set: fix a sample Created 6 years, 2 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_pkm.cpp ('k') | src/images/SkScaledBitmapSampler.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 2006 The Android Open Source Project 3 * Copyright 2006 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 "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkMath.h" 13 #include "SkMath.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkTemplates.h" 15 #include "SkTemplates.h"
16 #include "SkUtils.h" 16 #include "SkUtils.h"
17 17
18 class SkWBMPImageDecoder : public SkImageDecoder { 18 class SkWBMPImageDecoder : public SkImageDecoder {
19 public: 19 public:
20 virtual Format getFormat() const SK_OVERRIDE { 20 virtual Format getFormat() const SK_OVERRIDE {
21 return kWBMP_Format; 21 return kWBMP_Format;
22 } 22 }
23 23
24 protected: 24 protected:
25 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; 25 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
26 26
27 private: 27 private:
28 typedef SkImageDecoder INHERITED; 28 typedef SkImageDecoder INHERITED;
29 }; 29 };
30 30
31 static bool read_byte(SkStream* stream, uint8_t* data) 31 static bool read_byte(SkStream* stream, uint8_t* data)
32 { 32 {
33 return stream->read(data, 1) == 1; 33 return stream->read(data, 1) == 1;
34 } 34 }
35 35
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 bits &= 7; 92 bits &= 7;
93 if (bits > 0) { 93 if (bits > 0) {
94 unsigned mask = *src; 94 unsigned mask = *src;
95 do { 95 do {
96 *dst++ = (mask >> 7) & 1;; 96 *dst++ = (mask >> 7) & 1;;
97 mask <<= 1; 97 mask <<= 1;
98 } while (--bits != 0); 98 } while (--bits != 0);
99 } 99 }
100 } 100 }
101 101
102 bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, 102 SkImageDecoder::Result SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap,
103 Mode mode) 103 Mode mode)
104 { 104 {
105 wbmp_head head; 105 wbmp_head head;
106 106
107 if (!head.init(stream)) { 107 if (!head.init(stream)) {
108 return false; 108 return kFailure;
109 } 109 }
110 110
111 int width = head.fWidth; 111 int width = head.fWidth;
112 int height = head.fHeight; 112 int height = head.fHeight;
113 113
114 decodedBitmap->setInfo(SkImageInfo::Make(width, height, 114 decodedBitmap->setInfo(SkImageInfo::Make(width, height,
115 kIndex_8_SkColorType, kOpaque_SkAlp haType)); 115 kIndex_8_SkColorType, kOpaque_SkAlp haType));
116 116
117 if (SkImageDecoder::kDecodeBounds_Mode == mode) { 117 if (SkImageDecoder::kDecodeBounds_Mode == mode) {
118 return true; 118 return kSuccess;
119 } 119 }
120 120
121 const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; 121 const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
122 SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2)); 122 SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2));
123 SkAutoUnref aur(ct); 123 SkAutoUnref aur(ct);
124 124
125 if (!this->allocPixelRef(decodedBitmap, ct)) { 125 if (!this->allocPixelRef(decodedBitmap, ct)) {
126 return false; 126 return kFailure;
127 } 127 }
128 128
129 SkAutoLockPixels alp(*decodedBitmap); 129 SkAutoLockPixels alp(*decodedBitmap);
130 130
131 uint8_t* dst = decodedBitmap->getAddr8(0, 0); 131 uint8_t* dst = decodedBitmap->getAddr8(0, 0);
132 // store the 1-bit valuess at the end of our pixels, so we won't stomp 132 // store the 1-bit valuess at the end of our pixels, so we won't stomp
133 // on them before we're read them. Just trying to avoid a temp allocation 133 // on them before we're read them. Just trying to avoid a temp allocation
134 size_t srcRB = SkAlign8(width) >> 3; 134 size_t srcRB = SkAlign8(width) >> 3;
135 size_t srcSize = height * srcRB; 135 size_t srcSize = height * srcRB;
136 uint8_t* src = dst + decodedBitmap->getSize() - srcSize; 136 uint8_t* src = dst + decodedBitmap->getSize() - srcSize;
137 if (stream->read(src, srcSize) != srcSize) { 137 if (stream->read(src, srcSize) != srcSize) {
138 return false; 138 return kFailure;
139 } 139 }
140 140
141 for (int y = 0; y < height; y++) 141 for (int y = 0; y < height; y++)
142 { 142 {
143 expand_bits_to_bytes(dst, src, width); 143 expand_bits_to_bytes(dst, src, width);
144 dst += decodedBitmap->rowBytes(); 144 dst += decodedBitmap->rowBytes();
145 src += srcRB; 145 src += srcRB;
146 } 146 }
147 147
148 return true; 148 return kSuccess;
149 } 149 }
150 150
151 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
152 DEFINE_DECODER_CREATOR(WBMPImageDecoder); 152 DEFINE_DECODER_CREATOR(WBMPImageDecoder);
153 /////////////////////////////////////////////////////////////////////////////// 153 ///////////////////////////////////////////////////////////////////////////////
154 154
155 static SkImageDecoder* sk_wbmp_dfactory(SkStreamRewindable* stream) { 155 static SkImageDecoder* sk_wbmp_dfactory(SkStreamRewindable* stream) {
156 wbmp_head head; 156 wbmp_head head;
157 157
158 if (head.init(stream)) { 158 if (head.init(stream)) {
159 return SkNEW(SkWBMPImageDecoder); 159 return SkNEW(SkWBMPImageDecoder);
160 } 160 }
161 return NULL; 161 return NULL;
162 } 162 }
163 163
164 static SkImageDecoder::Format get_format_wbmp(SkStreamRewindable* stream) { 164 static SkImageDecoder::Format get_format_wbmp(SkStreamRewindable* stream) {
165 wbmp_head head; 165 wbmp_head head;
166 if (head.init(stream)) { 166 if (head.init(stream)) {
167 return SkImageDecoder::kWBMP_Format; 167 return SkImageDecoder::kWBMP_Format;
168 } 168 }
169 return SkImageDecoder::kUnknown_Format; 169 return SkImageDecoder::kUnknown_Format;
170 } 170 }
171 171
172 static SkImageDecoder_DecodeReg gDReg(sk_wbmp_dfactory); 172 static SkImageDecoder_DecodeReg gDReg(sk_wbmp_dfactory);
173 static SkImageDecoder_FormatReg gFormatReg(get_format_wbmp); 173 static SkImageDecoder_FormatReg gFormatReg(get_format_wbmp);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_pkm.cpp ('k') | src/images/SkScaledBitmapSampler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698