diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-17 21:07:55 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-17 21:07:55 +0000 |
commit | 4c6adf9a089dbdd541f25d01d257ec05aedcb57d (patch) | |
tree | 59d154352b81cceb92f64fa2bcbce6422baf7881 /src/images/SkImageDecoder_FactoryRegistrar.cpp | |
parent | b7decc539887069f3fb0f9fc80d543b437bdd624 (diff) |
Updates to images project.
Use the SkImageEncoder_Factory on all platforms. On Windows and Mac,
register the platform's image encoder as an option for
SkImageEncoder::Create. Also add more types that can be decoded.
Update comments for SkImageDecoder to be more accurate.
Add more types to SkImageEncoder::Type, and return the correct type of
encoder, if it exists.
Use a custom version of SkImageDecoder::Factory on Windows and Mac to
check the stream for registered decoders before defaulting to the platform's
version. Share code with the existing SkImageDecoder::Factory method.
Preparation for testing decoders and encoders:
BUG=https://code.google.com/p/skia/issues/detail?id=1241
Review URL: https://codereview.chromium.org/14298010
git-svn-id: http://skia.googlecode.com/svn/trunk@8730 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images/SkImageDecoder_FactoryRegistrar.cpp')
-rw-r--r-- | src/images/SkImageDecoder_FactoryRegistrar.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/images/SkImageDecoder_FactoryRegistrar.cpp b/src/images/SkImageDecoder_FactoryRegistrar.cpp new file mode 100644 index 0000000000..6cc417a46f --- /dev/null +++ b/src/images/SkImageDecoder_FactoryRegistrar.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2013 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkImageDecoder.h" +#include "SkStream.h" +#include "SkTRegistry.h" + +// This file is used for registration of SkImageDecoders. It also holds a function +// for checking all the the registered SkImageDecoders for one that matches an +// input SkStream. + +typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg; + +// N.B. You can't use "DecodeReg::gHead here" due to complex C++ +// corner cases. +template DecodeReg* SkTRegistry<SkImageDecoder*, SkStream*>::gHead; + +SkImageDecoder* image_decoder_from_stream(SkStream*); + +SkImageDecoder* image_decoder_from_stream(SkStream* stream) { + SkImageDecoder* codec = NULL; + const DecodeReg* curr = DecodeReg::Head(); + while (curr) { + codec = curr->factory()(stream); + // we rewind here, because we promise later when we call "decode", that + // the stream will be at its beginning. + bool rewindSuceeded = stream->rewind(); + + // our image decoder's require that rewind is supported so we fail early + // if we are given a stream that does not support rewinding. + if (!rewindSuceeded) { + SkDEBUGF(("Unable to rewind the image stream.")); + SkDELETE(codec); + return NULL; + } + + if (codec) { + return codec; + } + curr = curr->next(); + } + return NULL; +} |