epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkImageDecoder.h" |
| 11 | #include "SkMovie.h" |
| 12 | #include "SkStream.h" |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 13 | #include "SkTRegistry.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 15 | typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
agl@chromium.org | 4f9cdcc | 2010-06-10 21:32:00 +0000 | [diff] [blame] | 17 | // N.B. You can't use "DecodeReg::gHead here" due to complex C++ |
| 18 | // corner cases. |
| 19 | template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; |
reed@android.com | 3c2b7e8 | 2009-01-27 01:43:36 +0000 | [diff] [blame] | 20 | |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 21 | #ifdef SK_ENABLE_LIBPNG |
| 22 | extern SkImageDecoder* sk_libpng_dfactory(SkStream*); |
| 23 | #endif |
| 24 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 26 | SkImageDecoder* codec = NULL; |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 27 | const DecodeReg* curr = DecodeReg::Head(); |
| 28 | while (curr) { |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 29 | codec = curr->factory()(stream); |
reed@android.com | a16cb97 | 2009-06-18 20:26:58 +0000 | [diff] [blame] | 30 | // we rewind here, because we promise later when we call "decode", that |
| 31 | // the stream will be at its beginning. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | stream->rewind(); |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 33 | if (codec) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | return codec; |
| 35 | } |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 36 | curr = curr->next(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | } |
reed@android.com | dfee579 | 2010-04-15 14:24:50 +0000 | [diff] [blame] | 38 | #ifdef SK_ENABLE_LIBPNG |
| 39 | codec = sk_libpng_dfactory(stream); |
| 40 | stream->rewind(); |
| 41 | if (codec) { |
| 42 | return codec; |
| 43 | } |
| 44 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | return NULL; |
| 46 | } |
| 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | ///////////////////////////////////////////////////////////////////////// |
| 49 | |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 50 | typedef SkTRegistry<SkMovie*, SkStream*> MovieReg; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | |
| 52 | SkMovie* SkMovie::DecodeStream(SkStream* stream) { |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 53 | const MovieReg* curr = MovieReg::Head(); |
| 54 | while (curr) { |
| 55 | SkMovie* movie = curr->factory()(stream); |
| 56 | if (movie) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | return movie; |
| 58 | } |
reed@android.com | a16cb97 | 2009-06-18 20:26:58 +0000 | [diff] [blame] | 59 | // 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 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | stream->rewind(); |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 62 | curr = curr->next(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | } |
| 64 | return NULL; |
| 65 | } |