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" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 ct = kN32_SkColorType; | 149 ct = kN32_SkColorType; |
150 break; | 150 break; |
151 case k32Bit_SrcDepth: | 151 case k32Bit_SrcDepth: |
152 ct = kN32_SkColorType; | 152 ct = kN32_SkColorType; |
153 break; | 153 break; |
154 } | 154 } |
155 } | 155 } |
156 return ct; | 156 return ct; |
157 } | 157 } |
158 | 158 |
159 bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mo
de mode) { | 159 SkImageDecoder::Result SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, Sk
ColorType pref, |
| 160 Mode mode) { |
160 // we reset this to false before calling onDecode | 161 // we reset this to false before calling onDecode |
161 fShouldCancelDecode = false; | 162 fShouldCancelDecode = false; |
162 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals
e | 163 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals
e |
163 fDefaultPref = pref; | 164 fDefaultPref = pref; |
164 | 165 |
165 // pass a temporary bitmap, so that if we return false, we are assured of | 166 // pass a temporary bitmap, so that if we return false, we are assured of |
166 // leaving the caller's bitmap untouched. | 167 // leaving the caller's bitmap untouched. |
167 SkBitmap tmp; | 168 SkBitmap tmp; |
168 if (!this->onDecode(stream, &tmp, mode)) { | 169 const Result result = this->onDecode(stream, &tmp, mode); |
169 return false; | 170 if (kFailure != result) { |
| 171 bm->swap(tmp); |
170 } | 172 } |
171 bm->swap(tmp); | 173 return result; |
172 return true; | |
173 } | 174 } |
174 | 175 |
175 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, SkColorType
pref) { | 176 bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, SkColorType
pref) { |
176 // we reset this to false before calling onDecodeSubset | 177 // we reset this to false before calling onDecodeSubset |
177 fShouldCancelDecode = false; | 178 fShouldCancelDecode = false; |
178 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals
e | 179 // assign this, for use by getPrefColorType(), in case fUsePrefTable is fals
e |
179 fDefaultPref = pref; | 180 fDefaultPref = pref; |
180 | 181 |
181 return this->onDecodeSubset(bm, rect); | 182 return this->onDecodeSubset(bm, rect); |
182 } | 183 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 266 |
266 bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkCo
lorType pref, | 267 bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkCo
lorType pref, |
267 Mode mode, Format* format) { | 268 Mode mode, Format* format) { |
268 SkASSERT(stream); | 269 SkASSERT(stream); |
269 SkASSERT(bm); | 270 SkASSERT(bm); |
270 | 271 |
271 bool success = false; | 272 bool success = false; |
272 SkImageDecoder* codec = SkImageDecoder::Factory(stream); | 273 SkImageDecoder* codec = SkImageDecoder::Factory(stream); |
273 | 274 |
274 if (codec) { | 275 if (codec) { |
275 success = codec->decode(stream, bm, pref, mode); | 276 success = codec->decode(stream, bm, pref, mode) != kFailure; |
276 if (success && format) { | 277 if (success && format) { |
277 *format = codec->getFormat(); | 278 *format = codec->getFormat(); |
278 if (kUnknown_Format == *format) { | 279 if (kUnknown_Format == *format) { |
279 if (stream->rewind()) { | 280 if (stream->rewind()) { |
280 *format = GetStreamFormat(stream); | 281 *format = GetStreamFormat(stream); |
281 } | 282 } |
282 } | 283 } |
283 } | 284 } |
284 delete codec; | 285 delete codec; |
285 } | 286 } |
286 return success; | 287 return success; |
287 } | 288 } |
288 | 289 |
289 bool SkImageDecoder::decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3
], void* planes[3], | 290 bool SkImageDecoder::decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3
], void* planes[3], |
290 size_t rowBytes[3], SkYUVColorSpace* color
Space) { | 291 size_t rowBytes[3], SkYUVColorSpace* color
Space) { |
291 // we reset this to false before calling onDecodeYUV8Planes | 292 // we reset this to false before calling onDecodeYUV8Planes |
292 fShouldCancelDecode = false; | 293 fShouldCancelDecode = false; |
293 | 294 |
294 return this->onDecodeYUV8Planes(stream, componentSizes, planes, rowBytes, co
lorSpace); | 295 return this->onDecodeYUV8Planes(stream, componentSizes, planes, rowBytes, co
lorSpace); |
295 } | 296 } |
OLD | NEW |