Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1489)

Side by Side Diff: src/ports/SkImageDecoder_CG.cpp

Issue 23477009: Change SkImageDecoders to take an SkStreamRewindable. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Only switch to SkStreamRewindable when necessary. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/images/SkMovie_gif.cpp ('k') | src/ports/SkImageDecoder_WIC.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCGUtils.h" 8 #include "SkCGUtils.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 *addr = unpremultiply_pmcolor(*addr); 119 *addr = unpremultiply_pmcolor(*addr);
120 } 120 }
121 } 121 }
122 } 122 }
123 bm->unlockPixels(); 123 bm->unlockPixels();
124 return true; 124 return true;
125 } 125 }
126 126
127 /////////////////////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////////////////////
128 128
129 extern SkImageDecoder* image_decoder_from_stream(SkStream*); 129 extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
130 130
131 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { 131 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
132 SkImageDecoder* decoder = image_decoder_from_stream(stream); 132 SkImageDecoder* decoder = image_decoder_from_stream(stream);
133 if (NULL == decoder) { 133 if (NULL == decoder) {
134 // If no image decoder specific to the stream exists, use SkImageDecoder _CG. 134 // If no image decoder specific to the stream exists, use SkImageDecoder _CG.
135 return SkNEW(SkImageDecoder_CG); 135 return SkNEW(SkImageDecoder_CG);
136 } else { 136 } else {
137 return decoder; 137 return decoder;
138 } 138 }
139 } 139 }
140 140
141 ///////////////////////////////////////////////////////////////////////// 141 /////////////////////////////////////////////////////////////////////////
142 142
143 SkMovie* SkMovie::DecodeStream(SkStream* stream) { 143 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
144 return NULL; 144 return NULL;
145 } 145 }
146 146
147 ///////////////////////////////////////////////////////////////////////// 147 /////////////////////////////////////////////////////////////////////////
148 148
149 static size_t consumer_put(void* info, const void* buffer, size_t count) { 149 static size_t consumer_put(void* info, const void* buffer, size_t count) {
150 SkWStream* stream = reinterpret_cast<SkWStream*>(info); 150 SkWStream* stream = reinterpret_cast<SkWStream*>(info);
151 return stream->write(buffer, count) ? count : 0; 151 return stream->write(buffer, count) ? count : 0;
152 } 152 }
153 153
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 return false; 237 return false;
238 } 238 }
239 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image); 239 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image);
240 240
241 CGImageDestinationAddImage(dst, image, NULL); 241 CGImageDestinationAddImage(dst, image, NULL);
242 return CGImageDestinationFinalize(dst); 242 return CGImageDestinationFinalize(dst);
243 } 243 }
244 244
245 /////////////////////////////////////////////////////////////////////////////// 245 ///////////////////////////////////////////////////////////////////////////////
246 246
247 #include "SkTRegistry.h"
248
249 static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) { 247 static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) {
250 switch (t) { 248 switch (t) {
251 case SkImageEncoder::kICO_Type: 249 case SkImageEncoder::kICO_Type:
252 case SkImageEncoder::kBMP_Type: 250 case SkImageEncoder::kBMP_Type:
253 case SkImageEncoder::kGIF_Type: 251 case SkImageEncoder::kGIF_Type:
254 case SkImageEncoder::kJPEG_Type: 252 case SkImageEncoder::kJPEG_Type:
255 case SkImageEncoder::kPNG_Type: 253 case SkImageEncoder::kPNG_Type:
256 break; 254 break;
257 default: 255 default:
258 return NULL; 256 return NULL;
259 } 257 }
260 return SkNEW_ARGS(SkImageEncoder_CG, (t)); 258 return SkNEW_ARGS(SkImageEncoder_CG, (t));
261 } 259 }
262 260
263 static SkTRegistry<SkImageEncoder*(*)(SkImageEncoder::Type)> gEReg(sk_imageencod er_cg_factory); 261 static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_cg_factory);
264 262
265 struct FormatConversion { 263 struct FormatConversion {
266 CFStringRef fUTType; 264 CFStringRef fUTType;
267 SkImageDecoder::Format fFormat; 265 SkImageDecoder::Format fFormat;
268 }; 266 };
269 267
270 // Array of the types supported by the decoder. 268 // Array of the types supported by the decoder.
271 static const FormatConversion gFormatConversions[] = { 269 static const FormatConversion gFormatConversions[] = {
272 { kUTTypeBMP, SkImageDecoder::kBMP_Format }, 270 { kUTTypeBMP, SkImageDecoder::kBMP_Format },
273 { kUTTypeGIF, SkImageDecoder::kGIF_Format }, 271 { kUTTypeGIF, SkImageDecoder::kGIF_Format },
274 { kUTTypeICO, SkImageDecoder::kICO_Format }, 272 { kUTTypeICO, SkImageDecoder::kICO_Format },
275 { kUTTypeJPEG, SkImageDecoder::kJPEG_Format }, 273 { kUTTypeJPEG, SkImageDecoder::kJPEG_Format },
276 // Also include JPEG2000 274 // Also include JPEG2000
277 { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format }, 275 { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format },
278 { kUTTypePNG, SkImageDecoder::kPNG_Format }, 276 { kUTTypePNG, SkImageDecoder::kPNG_Format },
279 }; 277 };
280 278
281 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { 279 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) {
282 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { 280 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) {
283 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp areEqualTo) { 281 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp areEqualTo) {
284 return gFormatConversions[i].fFormat; 282 return gFormatConversions[i].fFormat;
285 } 283 }
286 } 284 }
287 return SkImageDecoder::kUnknown_Format; 285 return SkImageDecoder::kUnknown_Format;
288 } 286 }
289 287
290 static SkImageDecoder::Format get_format_cg(SkStream *stream) { 288 static SkImageDecoder::Format get_format_cg(SkStreamRewindable* stream) {
291 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); 289 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
292 290
293 if (NULL == imageSrc) { 291 if (NULL == imageSrc) {
294 return SkImageDecoder::kUnknown_Format; 292 return SkImageDecoder::kUnknown_Format;
295 } 293 }
296 294
297 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); 295 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
298 const CFStringRef name = CGImageSourceGetType(imageSrc); 296 const CFStringRef name = CGImageSourceGetType(imageSrc);
299 if (NULL == name) { 297 if (NULL == name) {
300 return SkImageDecoder::kUnknown_Format; 298 return SkImageDecoder::kUnknown_Format;
301 } 299 }
302 return UTType_to_Format(name); 300 return UTType_to_Format(name);
303 } 301 }
304 302
305 static SkTRegistry<SkImageDecoder::Format(*)(SkStream*)> gFormatReg(get_format_c g); 303 static SkImageDecoder_FormatReg gFormatReg(get_format_cg);
OLDNEW
« no previous file with comments | « src/images/SkMovie_gif.cpp ('k') | src/ports/SkImageDecoder_WIC.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698