OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 default: | 103 default: |
104 // we don't know if we're opaque or not, so compute it. | 104 // we don't know if we're opaque or not, so compute it. |
105 bm->computeAndSetOpaquePredicate(); | 105 bm->computeAndSetOpaquePredicate(); |
106 } | 106 } |
107 bm->unlockPixels(); | 107 bm->unlockPixels(); |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
112 | 112 |
| 113 extern SkImageDecoder* image_decoder_from_stream(SkStream*); |
| 114 |
113 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | 115 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { |
114 return SkNEW(SkImageDecoder_CG); | 116 SkImageDecoder* decoder = image_decoder_from_stream(stream); |
| 117 if (NULL == decoder) { |
| 118 // If no image decoder specific to the stream exists, use SkImageDecoder
_CG. |
| 119 return SkNEW(SkImageDecoder_CG); |
| 120 } else { |
| 121 return decoder; |
| 122 } |
115 } | 123 } |
116 | 124 |
117 ///////////////////////////////////////////////////////////////////////// | 125 ///////////////////////////////////////////////////////////////////////// |
118 | 126 |
119 SkMovie* SkMovie::DecodeStream(SkStream* stream) { | 127 SkMovie* SkMovie::DecodeStream(SkStream* stream) { |
120 return NULL; | 128 return NULL; |
121 } | 129 } |
122 | 130 |
123 ///////////////////////////////////////////////////////////////////////// | 131 ///////////////////////////////////////////////////////////////////////// |
124 | 132 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 must only live for the duration of the onEncode() method. | 175 must only live for the duration of the onEncode() method. |
168 */ | 176 */ |
169 bool SkImageEncoder_CG::onEncode(SkWStream* stream, const SkBitmap& bm, | 177 bool SkImageEncoder_CG::onEncode(SkWStream* stream, const SkBitmap& bm, |
170 int quality) { | 178 int quality) { |
171 // Used for converting a bitmap to 8888. | 179 // Used for converting a bitmap to 8888. |
172 const SkBitmap* bmPtr = &bm; | 180 const SkBitmap* bmPtr = &bm; |
173 SkBitmap bitmap8888; | 181 SkBitmap bitmap8888; |
174 | 182 |
175 CFStringRef type; | 183 CFStringRef type; |
176 switch (fType) { | 184 switch (fType) { |
| 185 case kICO_Type: |
| 186 type = kUTTypeICO; |
| 187 break; |
| 188 case kBMP_Type: |
| 189 type = kUTTypeBMP; |
| 190 break; |
| 191 case kGIF_Type: |
| 192 type = kUTTypeGIF; |
| 193 break; |
177 case kJPEG_Type: | 194 case kJPEG_Type: |
178 type = kUTTypeJPEG; | 195 type = kUTTypeJPEG; |
179 break; | 196 break; |
180 case kPNG_Type: | 197 case kPNG_Type: |
181 // PNG encoding an ARGB_4444 bitmap gives the following errors in GM
: | 198 // PNG encoding an ARGB_4444 bitmap gives the following errors in GM
: |
182 // <Error>: CGImageDestinationAddImage image could not be converted
to destination | 199 // <Error>: CGImageDestinationAddImage image could not be converted
to destination |
183 // format. | 200 // format. |
184 // <Error>: CGImageDestinationFinalize image destination does not ha
ve enough images | 201 // <Error>: CGImageDestinationFinalize image destination does not ha
ve enough images |
185 // So instead we copy to 8888. | 202 // So instead we copy to 8888. |
186 if (bm.getConfig() == SkBitmap::kARGB_4444_Config) { | 203 if (bm.getConfig() == SkBitmap::kARGB_4444_Config) { |
(...skipping 15 matching lines...) Expand all Loading... |
202 CGImageRef image = SkCreateCGImageRef(*bmPtr); | 219 CGImageRef image = SkCreateCGImageRef(*bmPtr); |
203 if (NULL == image) { | 220 if (NULL == image) { |
204 return false; | 221 return false; |
205 } | 222 } |
206 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image); | 223 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image); |
207 | 224 |
208 CGImageDestinationAddImage(dst, image, NULL); | 225 CGImageDestinationAddImage(dst, image, NULL); |
209 return CGImageDestinationFinalize(dst); | 226 return CGImageDestinationFinalize(dst); |
210 } | 227 } |
211 | 228 |
212 SkImageEncoder* SkImageEncoder::Create(Type t) { | 229 /////////////////////////////////////////////////////////////////////////////// |
| 230 |
| 231 #include "SkTRegistry.h" |
| 232 |
| 233 static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) { |
213 switch (t) { | 234 switch (t) { |
214 case kJPEG_Type: | 235 case SkImageEncoder::kICO_Type: |
215 case kPNG_Type: | 236 case SkImageEncoder::kBMP_Type: |
| 237 case SkImageEncoder::kGIF_Type: |
| 238 case SkImageEncoder::kJPEG_Type: |
| 239 case SkImageEncoder::kPNG_Type: |
216 break; | 240 break; |
217 default: | 241 default: |
218 return NULL; | 242 return NULL; |
219 } | 243 } |
220 return SkNEW_ARGS(SkImageEncoder_CG, (t)); | 244 return SkNEW_ARGS(SkImageEncoder_CG, (t)); |
221 } | 245 } |
| 246 |
| 247 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_
cg_factory); |
OLD | NEW |