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

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

Issue 23477009: Change SkImageDecoders to take an SkStreamRewindable. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove accidental whitespace change Created 7 years, 3 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
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 bool onDecode(SkStreamRewindable* stream, SkBitmap* bm, Mode) SK_OVE RRIDE;
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(SkStreamRewindable* stream, uint8_t* data)
32 { 32 {
33 return stream->read(data, 1) == 1; 33 return stream->read(data, 1) == 1;
34 } 34 }
35 35
36 static bool read_mbf(SkStream* stream, int* value) 36 static bool read_mbf(SkStreamRewindable* stream, int* value)
37 { 37 {
38 int n = 0; 38 int n = 0;
39 uint8_t data; 39 uint8_t data;
40 do { 40 do {
41 if (!read_byte(stream, &data)) { 41 if (!read_byte(stream, &data)) {
42 return false; 42 return false;
43 } 43 }
44 n = (n << 7) | (data & 0x7F); 44 n = (n << 7) | (data & 0x7F);
45 } while (data & 0x80); 45 } while (data & 0x80);
46 46
47 *value = n; 47 *value = n;
48 return true; 48 return true;
49 } 49 }
50 50
51 struct wbmp_head { 51 struct wbmp_head {
52 int fWidth; 52 int fWidth;
53 int fHeight; 53 int fHeight;
54 54
55 bool init(SkStream* stream) 55 bool init(SkStreamRewindable* stream)
56 { 56 {
57 uint8_t data; 57 uint8_t data;
58 58
59 if (!read_byte(stream, &data) || data != 0) { // unknown type 59 if (!read_byte(stream, &data) || data != 0) { // unknown type
60 return false; 60 return false;
61 } 61 }
62 if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header 62 if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header
63 return false; 63 return false;
64 } 64 }
65 if (!read_mbf(stream, &fWidth) || (unsigned)fWidth > 0xFFFF) { 65 if (!read_mbf(stream, &fWidth) || (unsigned)fWidth > 0xFFFF) {
(...skipping 26 matching lines...) Expand all
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 bool SkWBMPImageDecoder::onDecode(SkStreamRewindable* stream, SkBitmap* decodedB itmap,
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 false;
109 } 109 }
110 110
111 int width = head.fWidth; 111 int width = head.fWidth;
112 int height = head.fHeight; 112 int height = head.fHeight;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 return true; 148 return true;
149 } 149 }
150 150
151 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
152 DEFINE_DECODER_CREATOR(WBMPImageDecoder); 152 DEFINE_DECODER_CREATOR(WBMPImageDecoder);
153 /////////////////////////////////////////////////////////////////////////////// 153 ///////////////////////////////////////////////////////////////////////////////
154 154
155 #include "SkTRegistry.h" 155 #include "SkTRegistry.h"
156 156
157 static SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) { 157 static SkImageDecoder* sk_wbmp_dfactory(SkStreamRewindable* stream) {
158 wbmp_head head; 158 wbmp_head head;
159 159
160 if (head.init(stream)) { 160 if (head.init(stream)) {
161 return SkNEW(SkWBMPImageDecoder); 161 return SkNEW(SkWBMPImageDecoder);
162 } 162 }
163 return NULL; 163 return NULL;
164 } 164 }
165 165
166 static SkImageDecoder::Format get_format_wbmp(SkStream* stream) { 166 static SkImageDecoder::Format get_format_wbmp(SkStreamRewindable* stream) {
167 wbmp_head head; 167 wbmp_head head;
168 if (head.init(stream)) { 168 if (head.init(stream)) {
169 return SkImageDecoder::kWBMP_Format; 169 return SkImageDecoder::kWBMP_Format;
170 } 170 }
171 return SkImageDecoder::kUnknown_Format; 171 return SkImageDecoder::kUnknown_Format;
172 } 172 }
173 173
174 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_wbmp_dfactory); 174 static SkTRegistry<SkImageDecoder*, SkStreamRewindable*> gReg(sk_wbmp_dfactory);
175 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_wbmp ); 175 static SkTRegistry<SkImageDecoder::Format, SkStreamRewindable*> gFormatReg(get_f ormat_wbmp);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698