OLD | NEW |
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 { | 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); | 25 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; |
| 26 |
| 27 private: |
| 28 typedef SkImageDecoder INHERITED; |
26 }; | 29 }; |
27 | 30 |
28 static bool read_byte(SkStream* stream, uint8_t* data) | 31 static bool read_byte(SkStream* stream, uint8_t* data) |
29 { | 32 { |
30 return stream->read(data, 1) == 1; | 33 return stream->read(data, 1) == 1; |
31 } | 34 } |
32 | 35 |
33 static bool read_mbf(SkStream* stream, int* value) | 36 static bool read_mbf(SkStream* stream, int* value) |
34 { | 37 { |
35 int n = 0; | 38 int n = 0; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 Mode mode) | 103 Mode mode) |
101 { | 104 { |
102 wbmp_head head; | 105 wbmp_head head; |
103 | 106 |
104 if (!head.init(stream)) { | 107 if (!head.init(stream)) { |
105 return false; | 108 return false; |
106 } | 109 } |
107 | 110 |
108 int width = head.fWidth; | 111 int width = head.fWidth; |
109 int height = head.fHeight; | 112 int height = head.fHeight; |
| 113 |
| 114 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 115 decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height); |
| 116 decodedBitmap->setIsOpaque(true); |
| 117 return true; |
| 118 } |
110 | 119 |
111 // assign these directly, in case we return kDimensions_Result | 120 // No Bitmap reuse supported for this format |
| 121 if (!decodedBitmap->isNull()) { |
| 122 return false; |
| 123 } |
| 124 |
112 decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height); | 125 decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height); |
113 decodedBitmap->setIsOpaque(true); | 126 decodedBitmap->setIsOpaque(true); |
114 | 127 |
115 if (SkImageDecoder::kDecodeBounds_Mode == mode) | |
116 return true; | |
117 | |
118 const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; | 128 const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; |
119 SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2)); | 129 SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2)); |
120 SkAutoUnref aur(ct); | 130 SkAutoUnref aur(ct); |
121 | 131 |
122 if (!this->allocPixelRef(decodedBitmap, ct)) { | 132 if (!this->allocPixelRef(decodedBitmap, ct)) { |
123 return false; | 133 return false; |
124 } | 134 } |
125 | 135 |
126 SkAutoLockPixels alp(*decodedBitmap); | 136 SkAutoLockPixels alp(*decodedBitmap); |
127 | 137 |
(...skipping 26 matching lines...) Expand all Loading... |
154 static SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) { | 164 static SkImageDecoder* sk_wbmp_dfactory(SkStream* stream) { |
155 wbmp_head head; | 165 wbmp_head head; |
156 | 166 |
157 if (head.init(stream)) { | 167 if (head.init(stream)) { |
158 return SkNEW(SkWBMPImageDecoder); | 168 return SkNEW(SkWBMPImageDecoder); |
159 } | 169 } |
160 return NULL; | 170 return NULL; |
161 } | 171 } |
162 | 172 |
163 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_wbmp_dfactory); | 173 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_wbmp_dfactory); |
OLD | NEW |