OLD | NEW |
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 | 8 |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkImagePriv.h" | 11 #include "SkImagePriv.h" |
12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 | 16 |
17 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; | 17 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; |
18 | 18 |
| 19 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG |
19 SkBitmap::Config SkImageDecoder::GetDeviceConfig() | 20 SkBitmap::Config SkImageDecoder::GetDeviceConfig() |
20 { | 21 { |
21 return gDeviceConfig; | 22 return gDeviceConfig; |
22 } | 23 } |
23 | 24 |
24 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) | 25 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) |
25 { | 26 { |
26 gDeviceConfig = config; | 27 gDeviceConfig = config; |
27 } | 28 } |
| 29 #endif |
28 | 30 |
29 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
30 | 32 |
31 SkImageDecoder::SkImageDecoder() | 33 SkImageDecoder::SkImageDecoder() |
32 : fPeeker(NULL) | 34 : fPeeker(NULL) |
33 , fChooser(NULL) | 35 , fChooser(NULL) |
34 , fAllocator(NULL) | 36 , fAllocator(NULL) |
35 , fSampleSize(1) | 37 , fSampleSize(1) |
36 , fDefaultPref(SkBitmap::kNo_Config) | 38 , fDefaultPref(SkBitmap::kNo_Config) |
37 , fDitherImage(true) | 39 , fDitherImage(true) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return alloc; | 115 return alloc; |
114 } | 116 } |
115 | 117 |
116 void SkImageDecoder::setSampleSize(int size) { | 118 void SkImageDecoder::setSampleSize(int size) { |
117 if (size < 1) { | 119 if (size < 1) { |
118 size = 1; | 120 size = 1; |
119 } | 121 } |
120 fSampleSize = size; | 122 fSampleSize = size; |
121 } | 123 } |
122 | 124 |
| 125 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG |
123 bool SkImageDecoder::chooseFromOneChoice(SkBitmap::Config config, int width, | 126 bool SkImageDecoder::chooseFromOneChoice(SkBitmap::Config config, int width, |
124 int height) const { | 127 int height) const { |
| 128 return this->chooseFromOneChoice(SkBitmapConfigToColorType(config), |
| 129 width, height); |
| 130 } |
| 131 #endif |
| 132 bool SkImageDecoder::chooseFromOneChoice(SkColorType colorType, |
| 133 int width, int height) const { |
125 Chooser* chooser = fChooser; | 134 Chooser* chooser = fChooser; |
126 | 135 |
127 if (NULL == chooser) { // no chooser, we just say YES to decoding :) | 136 if (NULL == chooser) { // no chooser, we just say YES to decoding :) |
128 return true; | 137 return true; |
129 } | 138 } |
130 chooser->begin(1); | 139 chooser->begin(1); |
131 chooser->inspect(0, config, width, height); | 140 chooser->inspect(0, colorType, width, height); |
132 return chooser->choose() == 0; | 141 return chooser->choose() == 0; |
133 } | 142 } |
134 | 143 |
135 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, | 144 bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, |
136 SkColorTable* ctable) const { | 145 SkColorTable* ctable) const { |
137 return bitmap->allocPixels(fAllocator, ctable); | 146 return bitmap->allocPixels(fAllocator, ctable); |
138 } | 147 } |
139 | 148 |
140 /////////////////////////////////////////////////////////////////////////////// | 149 /////////////////////////////////////////////////////////////////////////////// |
141 | 150 |
(...skipping 23 matching lines...) Expand all Loading... |
165 } else { | 174 } else { |
166 config = fDefaultPref; | 175 config = fDefaultPref; |
167 } | 176 } |
168 | 177 |
169 if (SkBitmap::kNo_Config == config) { | 178 if (SkBitmap::kNo_Config == config) { |
170 config = SkImageDecoder::GetDeviceConfig(); | 179 config = SkImageDecoder::GetDeviceConfig(); |
171 } | 180 } |
172 return config; | 181 return config; |
173 } | 182 } |
174 | 183 |
| 184 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG |
175 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, | 185 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, |
176 SkBitmap::Config pref, Mode mode) { | 186 SkBitmap::Config pref, Mode mode) { |
| 187 return this->decode(stream, bm, SkBitmapConfigToColorType(pref), mode); |
| 188 } |
| 189 #endif |
| 190 |
| 191 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, |
| 192 SkColorType colorType, Mode mode) { |
177 // we reset this to false before calling onDecode | 193 // we reset this to false before calling onDecode |
178 fShouldCancelDecode = false; | 194 fShouldCancelDecode = false; |
179 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false | 195 // assign this, for use by getPrefConfig(), in case fUsePrefTable is false |
180 fDefaultPref = pref; | 196 fDefaultColorType = colorType; |
181 | 197 |
182 // pass a temporary bitmap, so that if we return false, we are assured of | 198 // pass a temporary bitmap, so that if we return false, we are assured of |
183 // leaving the caller's bitmap untouched. | 199 // leaving the caller's bitmap untouched. |
184 SkBitmap tmp; | 200 SkBitmap tmp; |
185 if (!this->onDecode(stream, &tmp, mode)) { | 201 if (!this->onDecode(stream, &tmp, mode)) { |
186 return false; | 202 return false; |
187 } | 203 } |
188 bm->swap(tmp); | 204 bm->swap(tmp); |
189 return true; | 205 return true; |
190 } | 206 } |
191 | 207 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 if (kUnknown_Format == *format) { | 314 if (kUnknown_Format == *format) { |
299 if (stream->rewind()) { | 315 if (stream->rewind()) { |
300 *format = GetStreamFormat(stream); | 316 *format = GetStreamFormat(stream); |
301 } | 317 } |
302 } | 318 } |
303 } | 319 } |
304 delete codec; | 320 delete codec; |
305 } | 321 } |
306 return success; | 322 return success; |
307 } | 323 } |
OLD | NEW |