1/* libs/graphics/ports/SkImageDecoder_Factory.cpp 2** 3** Copyright 2006, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18#include "SkImageDecoder.h" 19#include "SkMovie.h" 20#include "SkStream.h" 21 22extern SkImageDecoder* SkImageDecoder_GIF_Factory(SkStream*); 23extern SkImageDecoder* SkImageDecoder_BMP_Factory(SkStream*); 24extern SkImageDecoder* SkImageDecoder_ICO_Factory(SkStream*); 25extern SkImageDecoder* SkImageDecoder_PNG_Factory(SkStream*); 26extern SkImageDecoder* SkImageDecoder_WBMP_Factory(SkStream*); 27extern SkImageDecoder* SkImageDecoder_JPEG_Factory(SkStream*); 28 29typedef SkImageDecoder* (*SkImageDecoderFactoryProc)(SkStream*); 30 31struct CodecFormat { 32 SkImageDecoderFactoryProc fProc; 33 SkImageDecoder::Format fFormat; 34}; 35 36static const CodecFormat gPairs[] = { 37#if 0 38 { SkImageDecoder_GIF_Factory, SkImageDecoder::kGIF_Format }, 39 { SkImageDecoder_PNG_Factory, SkImageDecoder::kPNG_Format }, 40 { SkImageDecoder_ICO_Factory, SkImageDecoder::kICO_Format }, 41 { SkImageDecoder_WBMP_Factory, SkImageDecoder::kWBMP_Format }, 42 { SkImageDecoder_BMP_Factory, SkImageDecoder::kBMP_Format }, 43 { SkImageDecoder_JPEG_Factory, SkImageDecoder::kJPEG_Format } 44#endif 45}; 46 47SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { 48 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { 49 SkImageDecoder* codec = gPairs[i].fProc(stream); 50 stream->rewind(); 51 if (NULL != codec) { 52 return codec; 53 } 54 } 55 return NULL; 56} 57 58bool SkImageDecoder::SupportsFormat(Format format) { 59 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { 60 if (gPairs[i].fFormat == format) { 61 return true; 62 } 63 } 64 return false; 65} 66 67///////////////////////////////////////////////////////////////////////// 68 69typedef SkMovie* (*SkMovieFactoryProc)(SkStream*); 70 71extern SkMovie* SkMovie_GIF_Factory(SkStream*); 72 73static const SkMovieFactoryProc gMovieProcs[] = { 74#if 0 75 SkMovie_GIF_Factory 76#endif 77}; 78 79SkMovie* SkMovie::DecodeStream(SkStream* stream) { 80 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMovieProcs); i++) { 81 SkMovie* movie = gMovieProcs[i](stream); 82 if (NULL != movie) { 83 return movie; 84 } 85 stream->rewind(); 86 } 87 return NULL; 88} 89 90///////////////////////////////////////////////////////////////////////// 91 92extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); 93extern SkImageEncoder* SkImageEncoder_PNG_Factory(); 94 95SkImageEncoder* SkImageEncoder::Create(Type t) { 96 switch (t) { 97#if 0 98 case kJPEG_Type: 99 return SkImageEncoder_JPEG_Factory(); 100 case kPNG_Type: 101 return SkImageEncoder_PNG_Factory(); 102#endif 103 default: 104 return NULL; 105 } 106} 107 108