Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 The Android Open Source Project | |
|
scroggo
2014/11/12 18:00:12
2014 Google Inc
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
| |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkErrorInternals.h" | |
| 9 #include "SkImageDecoder.h" | |
| 10 #include "SkStream.h" | |
| 11 | |
| 12 #include "SkImageDecoder_libjpeg.h" | |
| 13 #include "SkImageDecoder_libwebp.h" | |
| 14 #include "SkImageDecoder_libico.h" | |
| 15 #include "SkImageDecoder_libbmp.h" | |
| 16 #include "SkImageDecoder_wbmp.h" | |
| 17 | |
| 18 #if defined(SK_BUILD_FOR_WIN) | |
| 19 #include "SkImageDecoder_WIC.h" | |
| 20 #endif | |
| 21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | |
| 22 #include "SkImageDecoder_CG.h" | |
| 23 #endif | |
| 24 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) | |
| 25 #include "SkImageDecoder_libpng.h" | |
| 26 #endif | |
| 27 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | |
|
scroggo
2014/11/12 18:00:12
line too long.
Kimmo Kinnunen
2014/11/18 08:29:44
Done. Sorry about the whitespace problems, I've fi
| |
| 28 #include "SkImageDecoder_libgif.h" | |
| 29 #include "SkMovie_gif.h" | |
| 30 #endif | |
| 31 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | |
| 32 #include "SkImageDecoder_astc.h" | |
| 33 #include "SkImageDecoder_ktx.h" | |
| 34 #include "SkImageDecoder_pkm.h" | |
| 35 #endif | |
| 36 | |
| 37 // This file is used for registration of SkImageDecoders. It also holds a functi on | |
| 38 // for checking all the the registered SkImageDecoders for one that matches an | |
| 39 // input SkStreamRewindable. | |
| 40 | |
| 41 typedef SkImageDecoder* (*FactoryCreateFunc)(SkStreamRewindable*); | |
| 42 typedef SkImageDecoder::Format (*FactoryDetectFormatFunc)(SkStreamRewindable*); | |
| 43 static const struct { | |
| 44 FactoryCreateFunc createFunc; | |
| 45 FactoryDetectFormatFunc getFormatFunc; | |
| 46 } gDecoderFactoryFuncs[] = { | |
|
scroggo
2014/11/12 18:00:12
Could you add a comment here that the order is mea
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
| |
| 47 #if defined(SK_BUILD_FOR_WIN) | |
| 48 { SkCreateImageDecoder_WIC, SkDetectFormatImageDecoder_WIC }, | |
| 49 #endif | |
| 50 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | |
| 51 { SkCreateImageDecoder_CG, SkDetectFormatImageDecoder_CG }, | |
| 52 #endif | |
| 53 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) | |
| 54 { SkCreatePNGImageDecoder, SkDetectFormatPNGImageDecoder }, | |
| 55 #endif | |
| 56 { SkCreateJPEGImageDecoder, SkDetectFormatJPEGImageDecoder }, | |
| 57 { SkCreateWEBPImageDecoder, SkDetectFormatWEBPImageDecoder }, | |
| 58 { SkCreateICOImageDecoder, SkDetectFormatICOImageDecoder }, | |
| 59 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | |
|
scroggo
2014/11/12 18:00:12
line too long
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
| |
| 60 { SkCreateGIFImageDecoder, SkDetectFormatGIFImageDecoder }, | |
| 61 #endif | |
| 62 { SkCreateBMPImageDecoder, SkDetectFormatBMPImageDecoder }, | |
| 63 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | |
| 64 { SkCreateASTCImageDecoder, SkDetectFormatASTCImageDecoder }, | |
| 65 { SkCreateKTXImageDecoder, SkDetectFormatKTXImageDecoder }, | |
| 66 { SkCreatePKMImageDecoder, SkDetectFormatPKMImageDecoder }, | |
| 67 #endif | |
| 68 { SkCreateWBMPImageDecoder, SkDetectFormatWBMPImageDecoder } | |
| 69 }; | |
| 70 | |
| 71 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { | |
| 72 SkImageDecoder* codec = NULL; | |
| 73 for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) { | |
| 74 FactoryCreateFunc createFunc = gDecoderFactoryFuncs[i].createFunc; | |
|
scroggo
2014/11/12 18:00:12
Here's a thought:
I notice that in every one of t
Kimmo Kinnunen
2014/11/18 08:29:44
...
scroggo
2014/11/18 16:52:23
The issue isn't so much having two three-line func
| |
| 75 codec = createFunc(stream); | |
| 76 // we rewind here, because we promise later when we call "decode", that | |
| 77 // the stream will be at its beginning. | |
| 78 bool rewindSuceeded = stream->rewind(); | |
| 79 | |
| 80 // our image decoder's require that rewind is supported so we fail early | |
|
scroggo
2014/11/12 18:00:12
decoders*
(I know this duplicating an old typo, b
Kimmo Kinnunen
2014/11/18 08:29:44
Done.
| |
| 81 // if we are given a stream that does not support rewinding. | |
| 82 if (!rewindSuceeded) { | |
| 83 SkDEBUGF(("Unable to rewind the image stream.")); | |
| 84 SkDELETE(codec); | |
| 85 return NULL; | |
| 86 } | |
| 87 | |
| 88 if (codec) { | |
| 89 return codec; | |
| 90 } | |
| 91 } | |
| 92 return NULL; | |
| 93 } | |
| 94 | |
| 95 SkImageDecoder::Format SkImageDecoder::GetStreamFormat(SkStreamRewindable* strea m) { | |
| 96 for (size_t i = 0; i < SK_ARRAY_COUNT(gDecoderFactoryFuncs); ++i) { | |
| 97 FactoryDetectFormatFunc detectFormatFunc = gDecoderFactoryFuncs[i].getFo rmatFunc; | |
| 98 Format format = detectFormatFunc(stream); | |
| 99 if (!stream->rewind()) { | |
| 100 SkErrorInternals::SetError(kInvalidOperation_SkError, | |
| 101 "Unable to rewind the image stream\n"); | |
| 102 return kUnknown_Format; | |
| 103 } | |
| 104 if (format != kUnknown_Format) { | |
| 105 return format; | |
| 106 } | |
| 107 } | |
| 108 return kUnknown_Format; | |
| 109 } | |
| 110 | |
| 111 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) { | |
| 112 SkMovie* movie = NULL; | |
| 113 #if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUIL D_FOR_WIN) && !defined(SK_BUILD_FOR_NACL) | |
|
scroggo
2014/11/12 18:00:12
line too long
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 114 movie = SkGIFMovieCreate(stream); | |
|
scroggo
2014/11/12 18:00:12
The old code does a rewind if movie is null.
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 115 #endif | |
| 116 return movie; | |
| 117 } | |
| OLD | NEW |