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 "SkErrorInternals.h" | |
11 #include "SkImagePriv.h" | 12 #include "SkImagePriv.h" |
12 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
15 #include "SkCanvas.h" | 16 #include "SkCanvas.h" |
16 | 17 |
17 SK_DEFINE_INST_COUNT(SkImageDecoder::Peeker) | 18 SK_DEFINE_INST_COUNT(SkImageDecoder::Peeker) |
18 SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser) | 19 SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser) |
19 SK_DEFINE_INST_COUNT(SkImageDecoderFactory) | 20 SK_DEFINE_INST_COUNT(SkImageDecoderFactory) |
20 | 21 |
21 const char *SkImageDecoder::sFormatName[] = { | |
22 "Unknown Format", | |
23 "BMP", | |
24 "GIF", | |
25 "ICO", | |
26 "JPEG", | |
27 "PNG", | |
28 "WBMP", | |
29 "WEBP", | |
30 }; | |
31 | |
32 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; | 22 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; |
33 | 23 |
34 SkBitmap::Config SkImageDecoder::GetDeviceConfig() | 24 SkBitmap::Config SkImageDecoder::GetDeviceConfig() |
35 { | 25 { |
36 return gDeviceConfig; | 26 return gDeviceConfig; |
37 } | 27 } |
38 | 28 |
39 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) | 29 void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) |
40 { | 30 { |
41 gDeviceConfig = config; | 31 gDeviceConfig = config; |
(...skipping 10 matching lines...) Expand all Loading... | |
52 SkImageDecoder::~SkImageDecoder() { | 42 SkImageDecoder::~SkImageDecoder() { |
53 SkSafeUnref(fPeeker); | 43 SkSafeUnref(fPeeker); |
54 SkSafeUnref(fChooser); | 44 SkSafeUnref(fChooser); |
55 SkSafeUnref(fAllocator); | 45 SkSafeUnref(fAllocator); |
56 } | 46 } |
57 | 47 |
58 SkImageDecoder::Format SkImageDecoder::getFormat() const { | 48 SkImageDecoder::Format SkImageDecoder::getFormat() const { |
59 return kUnknown_Format; | 49 return kUnknown_Format; |
60 } | 50 } |
61 | 51 |
52 SkImageDecoder::Format SkImageDecoder::onGetFormat(SkStream*) const { | |
53 return kUnknown_Format; | |
54 } | |
55 | |
56 SkImageDecoder::Format SkImageDecoder::getFormat(SkStream* stream) const { | |
57 Format format = this->onGetFormat(stream); | |
epoger
2013/04/23 16:03:41
It bugs me that SkImageDecoder::getFormat(SkStream
scroggo
2013/04/24 18:00:05
I've replaced this function with a static function
| |
58 if (!stream->rewind()) { | |
59 SkErrorInternals::SetError(kInvalidOperation_SkError, | |
60 "Unable to rewind the image stream\n"); | |
61 } | |
62 return format; | |
63 } | |
64 | |
62 const char* SkImageDecoder::getFormatName() const { | 65 const char* SkImageDecoder::getFormatName() const { |
63 SkASSERT(SK_ARRAY_COUNT(sFormatName) == kLastKnownFormat); | 66 switch (this->getFormat()) { |
64 return sFormatName[this->getFormat()]; | 67 case kUnknown_Format: |
68 return "Unknown Format"; | |
69 case kBMP_Format: | |
70 return "BMP"; | |
71 case kGIF_Format: | |
72 return "GIF"; | |
73 case kICO_Format: | |
74 return "ICO"; | |
75 case kJPEG_Format: | |
76 return "JPEG"; | |
77 case kPNG_Format: | |
78 return "PNG"; | |
79 case kWBMP_Format: | |
80 return "WBMP"; | |
81 case kWEBP_Format: | |
82 return "WEBP"; | |
83 case kMultiple_Formats: | |
84 return "Multiple formats"; | |
85 default: | |
86 SkASSERT(!"Invalid format type!"); | |
87 } | |
88 return "Unknown Format"; | |
65 } | 89 } |
66 | 90 |
67 SkImageDecoder::Peeker* SkImageDecoder::setPeeker(Peeker* peeker) { | 91 SkImageDecoder::Peeker* SkImageDecoder::setPeeker(Peeker* peeker) { |
68 SkRefCnt_SafeAssign(fPeeker, peeker); | 92 SkRefCnt_SafeAssign(fPeeker, peeker); |
69 return peeker; | 93 return peeker; |
70 } | 94 } |
71 | 95 |
72 SkImageDecoder::Chooser* SkImageDecoder::setChooser(Chooser* chooser) { | 96 SkImageDecoder::Chooser* SkImageDecoder::setChooser(Chooser* chooser) { |
73 SkRefCnt_SafeAssign(fChooser, chooser); | 97 SkRefCnt_SafeAssign(fChooser, chooser); |
74 return chooser; | 98 return chooser; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 | 343 |
320 if (NULL != codec) { | 344 if (NULL != codec) { |
321 success = codec->decode(stream, bm, pref, mode); | 345 success = codec->decode(stream, bm, pref, mode); |
322 if (success && format) { | 346 if (success && format) { |
323 *format = codec->getFormat(); | 347 *format = codec->getFormat(); |
324 } | 348 } |
325 delete codec; | 349 delete codec; |
326 } | 350 } |
327 return success; | 351 return success; |
328 } | 352 } |
OLD | NEW |