OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 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 #include "SkErrorInternals.h" |
8 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
9 #include "SkStream.h" | 10 #include "SkStream.h" |
10 #include "SkTRegistry.h" | 11 #include "SkTRegistry.h" |
11 | 12 |
12 // This file is used for registration of SkImageDecoders. It also holds a functi
on | 13 // This file is used for registration of SkImageDecoders. It also holds a functi
on |
13 // for checking all the the registered SkImageDecoders for one that matches an | 14 // for checking all the the registered SkImageDecoders for one that matches an |
14 // input SkStream. | 15 // input SkStream. |
15 | 16 |
16 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; | 17 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; |
17 | 18 |
(...skipping 20 matching lines...) Expand all Loading... |
38 return NULL; | 39 return NULL; |
39 } | 40 } |
40 | 41 |
41 if (codec) { | 42 if (codec) { |
42 return codec; | 43 return codec; |
43 } | 44 } |
44 curr = curr->next(); | 45 curr = curr->next(); |
45 } | 46 } |
46 return NULL; | 47 return NULL; |
47 } | 48 } |
| 49 |
| 50 typedef SkTRegistry<SkImageDecoder::Format, SkStream*> FormatReg; |
| 51 |
| 52 template FormatReg* SkTRegistry<SkImageDecoder::Format, SkStream*>::gHead; |
| 53 |
| 54 SkImageDecoder::Format SkImageDecoder::GetFormat(SkStream* stream) { |
| 55 const FormatReg* curr = FormatReg::Head(); |
| 56 while (curr != NULL) { |
| 57 Format format = curr->factory()(stream); |
| 58 if (!stream->rewind()) { |
| 59 SkErrorInternals::SetError(kInvalidOperation_SkError, |
| 60 "Unable to rewind the image stream\n"); |
| 61 return kUnknown_Format; |
| 62 } |
| 63 if (format != kUnknown_Format) { |
| 64 return format; |
| 65 } |
| 66 curr = curr->next(); |
| 67 } |
| 68 return kUnknown_Format; |
| 69 } |
OLD | NEW |