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 9 10 #include "SkImageDecoder.h" 11 #include "SkMovie.h" 12 #include "SkStream.h" 13 14 extern SkImageDecoder* SkImageDecoder_GIF_Factory(SkStream*); 15 extern SkImageDecoder* SkImageDecoder_BMP_Factory(SkStream*); 16 extern SkImageDecoder* SkImageDecoder_ICO_Factory(SkStream*); 17 extern SkImageDecoder* SkImageDecoder_PNG_Factory(SkStream*); 18 extern SkImageDecoder* SkImageDecoder_WBMP_Factory(SkStream*); 19 extern SkImageDecoder* SkImageDecoder_JPEG_Factory(SkStream*); 20 21 typedef SkImageDecoder* (*SkImageDecoderFactoryProc)(SkStream*); 22 23 struct CodecFormat { 24 SkImageDecoderFactoryProc fProc; 25 SkImageDecoder::Format fFormat; 26 }; 27 28 static const CodecFormat gPairs[] = { 29 #if 0 30 { SkImageDecoder_GIF_Factory, SkImageDecoder::kGIF_Format }, 31 { SkImageDecoder_PNG_Factory, SkImageDecoder::kPNG_Format }, 32 { SkImageDecoder_ICO_Factory, SkImageDecoder::kICO_Format }, 33 { SkImageDecoder_WBMP_Factory, SkImageDecoder::kWBMP_Format }, 34 { SkImageDecoder_BMP_Factory, SkImageDecoder::kBMP_Format }, 35 { SkImageDecoder_JPEG_Factory, SkImageDecoder::kJPEG_Format } 36 #endif 37 }; 38 39 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { 40 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { 41 SkImageDecoder* codec = gPairs[i].fProc(stream); 42 stream->rewind(); 43 if (NULL != codec) { 44 return codec; 45 } 46 } 47 return NULL; 48 } 49 50 bool SkImageDecoder::SupportsFormat(Format format) { 51 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { 52 if (gPairs[i].fFormat == format) { 53 return true; 54 } 55 } 56 return false; 57 } 58 59 ///////////////////////////////////////////////////////////////////////// 60 61 typedef SkMovie* (*SkMovieFactoryProc)(SkStream*); 62 63 extern SkMovie* SkMovie_GIF_Factory(SkStream*); 64 65 static const SkMovieFactoryProc gMovieProcs[] = { 66 #if 0 67 SkMovie_GIF_Factory 68 #endif 69 }; 70 71 SkMovie* SkMovie::DecodeStream(SkStream* stream) { 72 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMovieProcs); i++) { 73 SkMovie* movie = gMovieProcs[i](stream); 74 if (NULL != movie) { 75 return movie; 76 } 77 stream->rewind(); 78 } 79 return NULL; 80 } 81 82 ///////////////////////////////////////////////////////////////////////// 83 84 extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); 85 extern SkImageEncoder* SkImageEncoder_PNG_Factory(); 86 87 SkImageEncoder* SkImageEncoder::Create(Type t) { 88 switch (t) { 89 #if 0 90 case kJPEG_Type: 91 return SkImageEncoder_JPEG_Factory(); 92 case kPNG_Type: 93 return SkImageEncoder_PNG_Factory(); 94 #endif 95 default: 96 return NULL; 97 } 98 } 99 100