OLD | NEW |
1 /* libs/graphics/ports/SkImageDecoder_Factory.cpp | 1 /* libs/graphics/ports/SkImageDecoder_Factory.cpp |
2 ** | 2 ** |
3 ** Copyright 2006, The Android Open Source Project | 3 ** Copyright 2006, The Android Open Source Project |
4 ** | 4 ** |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
6 ** you may not use this file except in compliance with 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 | 7 ** You may obtain a copy of the License at |
8 ** | 8 ** |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
10 ** | 10 ** |
(...skipping 15 matching lines...) Expand all Loading... |
26 extern SkImageDecoder* SkImageDecoder_WBMP_Factory(SkStream*); | 26 extern SkImageDecoder* SkImageDecoder_WBMP_Factory(SkStream*); |
27 extern SkImageDecoder* SkImageDecoder_JPEG_Factory(SkStream*); | 27 extern SkImageDecoder* SkImageDecoder_JPEG_Factory(SkStream*); |
28 | 28 |
29 typedef SkImageDecoder* (*SkImageDecoderFactoryProc)(SkStream*); | 29 typedef SkImageDecoder* (*SkImageDecoderFactoryProc)(SkStream*); |
30 | 30 |
31 struct CodecFormat { | 31 struct CodecFormat { |
32 SkImageDecoderFactoryProc fProc; | 32 SkImageDecoderFactoryProc fProc; |
33 SkImageDecoder::Format fFormat; | 33 SkImageDecoder::Format fFormat; |
34 }; | 34 }; |
35 | 35 |
| 36 #ifdef SK_SUPPORT_IMAGE_DECODE |
36 static const CodecFormat gPairs[] = { | 37 static const CodecFormat gPairs[] = { |
37 #ifdef SK_SUPPORT_IMAGE_DECODE | |
38 { SkImageDecoder_GIF_Factory, SkImageDecoder::kGIF_Format }, | 38 { SkImageDecoder_GIF_Factory, SkImageDecoder::kGIF_Format }, |
39 { SkImageDecoder_PNG_Factory, SkImageDecoder::kPNG_Format }, | 39 { SkImageDecoder_PNG_Factory, SkImageDecoder::kPNG_Format }, |
40 { SkImageDecoder_ICO_Factory, SkImageDecoder::kICO_Format }, | 40 { SkImageDecoder_ICO_Factory, SkImageDecoder::kICO_Format }, |
41 { SkImageDecoder_WBMP_Factory, SkImageDecoder::kWBMP_Format }, | 41 { SkImageDecoder_WBMP_Factory, SkImageDecoder::kWBMP_Format }, |
42 { SkImageDecoder_BMP_Factory, SkImageDecoder::kBMP_Format }, | 42 { SkImageDecoder_BMP_Factory, SkImageDecoder::kBMP_Format }, |
43 { SkImageDecoder_JPEG_Factory, SkImageDecoder::kJPEG_Format } | 43 { SkImageDecoder_JPEG_Factory, SkImageDecoder::kJPEG_Format } |
| 44 }; |
44 #endif | 45 #endif |
45 }; | |
46 | 46 |
47 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | 47 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { |
| 48 #ifdef SK_SUPPORT_IMAGE_DECODE |
48 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 49 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
49 SkImageDecoder* codec = gPairs[i].fProc(stream); | 50 SkImageDecoder* codec = gPairs[i].fProc(stream); |
50 stream->rewind(); | 51 stream->rewind(); |
51 if (NULL != codec) { | 52 if (NULL != codec) { |
52 return codec; | 53 return codec; |
53 } | 54 } |
54 } | 55 } |
| 56 #endif |
55 return NULL; | 57 return NULL; |
56 } | 58 } |
57 | 59 |
58 bool SkImageDecoder::SupportsFormat(Format format) { | 60 bool SkImageDecoder::SupportsFormat(Format format) { |
| 61 #ifdef SK_SUPPORT_IMAGE_DECODE |
59 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 62 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
60 if (gPairs[i].fFormat == format) { | 63 if (gPairs[i].fFormat == format) { |
61 return true; | 64 return true; |
62 } | 65 } |
63 } | 66 } |
| 67 #endif |
64 return false; | 68 return false; |
65 } | 69 } |
66 | 70 |
67 ///////////////////////////////////////////////////////////////////////// | 71 ///////////////////////////////////////////////////////////////////////// |
68 | 72 |
69 // the movie may hold onto the stream (by calling ref()) | 73 // the movie may hold onto the stream (by calling ref()) |
70 typedef SkMovie* (*SkMovieStreamProc)(SkStream*); | 74 typedef SkMovie* (*SkMovieStreamProc)(SkStream*); |
71 // the movie may NOT hold onto the pointer | 75 // the movie may NOT hold onto the pointer |
72 typedef SkMovie* (*SkMovieMemoryProc)(const void*, size_t); | 76 typedef SkMovie* (*SkMovieMemoryProc)(const void*, size_t); |
73 | 77 |
74 extern SkMovie* SkMovie_GIF_StreamFactory(SkStream*); | 78 extern SkMovie* SkMovie_GIF_StreamFactory(SkStream*); |
75 extern SkMovie* SkMovie_GIF_MemoryFactory(const void*, size_t); | 79 extern SkMovie* SkMovie_GIF_MemoryFactory(const void*, size_t); |
76 | 80 |
| 81 #ifdef SK_SUPPORT_IMAGE_DECODE |
77 static const SkMovieStreamProc gStreamProc[] = { | 82 static const SkMovieStreamProc gStreamProc[] = { |
78 #ifdef SK_SUPPORT_IMAGE_DECODE | |
79 SkMovie_GIF_StreamFactory | 83 SkMovie_GIF_StreamFactory |
80 #endif | |
81 }; | 84 }; |
82 | 85 |
83 static const SkMovieMemoryProc gMemoryProc[] = { | 86 static const SkMovieMemoryProc gMemoryProc[] = { |
84 #ifdef SK_SUPPORT_IMAGE_DECODE | |
85 SkMovie_GIF_MemoryFactory | 87 SkMovie_GIF_MemoryFactory |
| 88 }; |
86 #endif | 89 #endif |
87 }; | |
88 | 90 |
89 SkMovie* SkMovie::DecodeStream(SkStream* stream) { | 91 SkMovie* SkMovie::DecodeStream(SkStream* stream) { |
| 92 #ifdef SK_SUPPORT_IMAGE_DECODE |
90 for (unsigned i = 0; i < SK_ARRAY_COUNT(gStreamProc); i++) { | 93 for (unsigned i = 0; i < SK_ARRAY_COUNT(gStreamProc); i++) { |
91 SkMovie* movie = gStreamProc[i](stream); | 94 SkMovie* movie = gStreamProc[i](stream); |
92 if (NULL != movie) { | 95 if (NULL != movie) { |
93 return movie; | 96 return movie; |
94 } | 97 } |
95 stream->rewind(); | 98 stream->rewind(); |
96 } | 99 } |
| 100 #endif |
97 return NULL; | 101 return NULL; |
98 } | 102 } |
99 | 103 |
100 SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) | 104 SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) |
101 { | 105 { |
| 106 #ifdef SK_SUPPORT_IMAGE_DECODE |
102 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMemoryProc); i++) { | 107 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMemoryProc); i++) { |
103 SkMovie* movie = gMemoryProc[i](data, length); | 108 SkMovie* movie = gMemoryProc[i](data, length); |
104 if (NULL != movie) { | 109 if (NULL != movie) { |
105 return movie; | 110 return movie; |
106 } | 111 } |
107 } | 112 } |
| 113 #endif |
108 return NULL; | 114 return NULL; |
109 } | 115 } |
110 | 116 |
111 ///////////////////////////////////////////////////////////////////////// | 117 ///////////////////////////////////////////////////////////////////////// |
112 | 118 |
113 #ifdef SK_SUPPORT_IMAGE_ENCODE | 119 #ifdef SK_SUPPORT_IMAGE_ENCODE |
114 | 120 |
115 extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); | 121 extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); |
116 extern SkImageEncoder* SkImageEncoder_PNG_Factory(); | 122 extern SkImageEncoder* SkImageEncoder_PNG_Factory(); |
117 | 123 |
118 SkImageEncoder* SkImageEncoder::Create(Type t) { | 124 SkImageEncoder* SkImageEncoder::Create(Type t) { |
119 switch (t) { | 125 switch (t) { |
120 case kJPEG_Type: | 126 case kJPEG_Type: |
121 return SkImageEncoder_JPEG_Factory(); | 127 return SkImageEncoder_JPEG_Factory(); |
122 case kPNG_Type: | 128 case kPNG_Type: |
123 return SkImageEncoder_PNG_Factory(); | 129 return SkImageEncoder_PNG_Factory(); |
124 default: | 130 default: |
125 return NULL; | 131 return NULL; |
126 } | 132 } |
127 } | 133 } |
128 | 134 |
129 #endif | 135 #endif |
OLD | NEW |