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 "SkMovie.h" | 11 #include "SkMovie.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 #include "SkTRegistry.h" | 13 #include "SkTRegistry.h" |
14 | 14 |
15 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; | 15 typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; |
16 | 16 |
17 // N.B. You can't use "DecodeReg::gHead here" due to complex C++ | 17 // N.B. You can't use "DecodeReg::gHead here" due to complex C++ |
18 // corner cases. | 18 // corner cases. |
19 template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; | 19 template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; |
20 | 20 |
21 #ifdef SK_ENABLE_LIBPNG | |
22 extern SkImageDecoder* sk_libpng_dfactory(SkStream*); | |
23 #endif | |
24 | |
25 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | 21 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { |
26 SkImageDecoder* codec = NULL; | 22 SkImageDecoder* codec = NULL; |
27 const DecodeReg* curr = DecodeReg::Head(); | 23 const DecodeReg* curr = DecodeReg::Head(); |
28 while (curr) { | 24 while (curr) { |
29 codec = curr->factory()(stream); | 25 codec = curr->factory()(stream); |
30 // we rewind here, because we promise later when we call "decode", that | 26 // we rewind here, because we promise later when we call "decode", that |
31 // the stream will be at its beginning. | 27 // the stream will be at its beginning. |
32 stream->rewind(); | 28 stream->rewind(); |
33 if (codec) { | 29 if (codec) { |
34 return codec; | 30 return codec; |
35 } | 31 } |
36 curr = curr->next(); | 32 curr = curr->next(); |
37 } | 33 } |
38 #ifdef SK_ENABLE_LIBPNG | |
39 codec = sk_libpng_dfactory(stream); | |
40 stream->rewind(); | |
41 if (codec) { | |
42 return codec; | |
43 } | |
44 #endif | |
45 return NULL; | 34 return NULL; |
46 } | 35 } |
47 | 36 |
48 ///////////////////////////////////////////////////////////////////////// | 37 ///////////////////////////////////////////////////////////////////////// |
49 | 38 |
50 typedef SkTRegistry<SkMovie*, SkStream*> MovieReg; | 39 typedef SkTRegistry<SkMovie*, SkStream*> MovieReg; |
51 | 40 |
52 SkMovie* SkMovie::DecodeStream(SkStream* stream) { | 41 SkMovie* SkMovie::DecodeStream(SkStream* stream) { |
53 const MovieReg* curr = MovieReg::Head(); | 42 const MovieReg* curr = MovieReg::Head(); |
54 while (curr) { | 43 while (curr) { |
55 SkMovie* movie = curr->factory()(stream); | 44 SkMovie* movie = curr->factory()(stream); |
56 if (movie) { | 45 if (movie) { |
57 return movie; | 46 return movie; |
58 } | 47 } |
59 // we must rewind only if we got NULL, since we gave the stream to the | 48 // we must rewind only if we got NULL, since we gave the stream to the |
60 // movie, who may have already started reading from it | 49 // movie, who may have already started reading from it |
61 stream->rewind(); | 50 stream->rewind(); |
62 curr = curr->next(); | 51 curr = curr->next(); |
63 } | 52 } |
64 return NULL; | 53 return NULL; |
65 } | 54 } |
OLD | NEW |