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

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: Remove accidental whitespace change Created 7 years, 3 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
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 10 matching lines...) Expand all
21 #ifdef SK_BUILD_FOR_IOS 21 #ifdef SK_BUILD_FOR_IOS
22 #include <CoreGraphics/CoreGraphics.h> 22 #include <CoreGraphics/CoreGraphics.h>
23 #include <ImageIO/ImageIO.h> 23 #include <ImageIO/ImageIO.h>
24 #include <MobileCoreServices/MobileCoreServices.h> 24 #include <MobileCoreServices/MobileCoreServices.h>
25 #endif 25 #endif
26 26
27 static void malloc_release_proc(void* info, const void* data, size_t size) { 27 static void malloc_release_proc(void* info, const void* data, size_t size) {
28 sk_free(info); 28 sk_free(info);
29 } 29 }
30 30
31 static CGDataProviderRef SkStreamToDataProvider(SkStream* stream) { 31 static CGDataProviderRef SkStreamToDataProvider(SkStreamRewindable* stream) {
32 // TODO: use callbacks, so we don't have to load all the data into RAM 32 // TODO: use callbacks, so we don't have to load all the data into RAM
33 size_t len = stream->getLength(); 33 size_t len = stream->getLength();
34 void* data = sk_malloc_throw(len); 34 void* data = sk_malloc_throw(len);
35 stream->read(data, len); 35 stream->read(data, len);
36 36
37 return CGDataProviderCreateWithData(data, data, len, malloc_release_proc); 37 return CGDataProviderCreateWithData(data, data, len, malloc_release_proc);
38 } 38 }
39 39
40 static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { 40 static CGImageSourceRef SkStreamToCGImageSource(SkStreamRewindable* stream) {
41 CGDataProviderRef data = SkStreamToDataProvider(stream); 41 CGDataProviderRef data = SkStreamToDataProvider(stream);
42 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); 42 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0);
43 CGDataProviderRelease(data); 43 CGDataProviderRelease(data);
44 return imageSrc; 44 return imageSrc;
45 } 45 }
46 46
47 class SkImageDecoder_CG : public SkImageDecoder { 47 class SkImageDecoder_CG : public SkImageDecoder {
48 protected: 48 protected:
49 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); 49 virtual bool onDecode(SkStreamRewindable* stream, SkBitmap* bm, Mode);
50 }; 50 };
51 51
52 // Returns an unpremultiplied version of color. It will have the same ordering a nd size as an 52 // Returns an unpremultiplied version of color. It will have the same ordering a nd size as an
53 // SkPMColor, but the alpha will not be premultiplied. 53 // SkPMColor, but the alpha will not be premultiplied.
54 static SkPMColor unpremultiply_pmcolor(SkPMColor color) { 54 static SkPMColor unpremultiply_pmcolor(SkPMColor color) {
55 U8CPU a = SkGetPackedA32(color); 55 U8CPU a = SkGetPackedA32(color);
56 const SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(a); 56 const SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(a);
57 return SkPackARGB32NoCheck(a, 57 return SkPackARGB32NoCheck(a,
58 SkUnPreMultiply::ApplyScale(scale, SkGetPackedR32 (color)), 58 SkUnPreMultiply::ApplyScale(scale, SkGetPackedR32 (color)),
59 SkUnPreMultiply::ApplyScale(scale, SkGetPackedG32 (color)), 59 SkUnPreMultiply::ApplyScale(scale, SkGetPackedG32 (color)),
60 SkUnPreMultiply::ApplyScale(scale, SkGetPackedB32 (color))); 60 SkUnPreMultiply::ApplyScale(scale, SkGetPackedB32 (color)));
61 } 61 }
62 62
63 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) 63 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast)
64 64
65 bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { 65 bool SkImageDecoder_CG::onDecode(SkStreamRewindable* stream, SkBitmap* bm, Mode mode) {
66 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); 66 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
67 67
68 if (NULL == imageSrc) { 68 if (NULL == imageSrc) {
69 return false; 69 return false;
70 } 70 }
71 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); 71 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
72 72
73 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL); 73 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL);
74 if (NULL == image) { 74 if (NULL == image) {
75 return false; 75 return false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 *addr = unpremultiply_pmcolor(*addr); 118 *addr = unpremultiply_pmcolor(*addr);
119 } 119 }
120 } 120 }
121 } 121 }
122 bm->unlockPixels(); 122 bm->unlockPixels();
123 return true; 123 return true;
124 } 124 }
125 125
126 /////////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////////
127 127
128 extern SkImageDecoder* image_decoder_from_stream(SkStream*); 128 extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*);
129 129
130 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { 130 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) {
131 SkImageDecoder* decoder = image_decoder_from_stream(stream); 131 SkImageDecoder* decoder = image_decoder_from_stream(stream);
132 if (NULL == decoder) { 132 if (NULL == decoder) {
133 // If no image decoder specific to the stream exists, use SkImageDecoder _CG. 133 // If no image decoder specific to the stream exists, use SkImageDecoder _CG.
134 return SkNEW(SkImageDecoder_CG); 134 return SkNEW(SkImageDecoder_CG);
135 } else { 135 } else {
136 return decoder; 136 return decoder;
137 } 137 }
138 } 138 }
139 139
140 ///////////////////////////////////////////////////////////////////////// 140 /////////////////////////////////////////////////////////////////////////
141 141
142 SkMovie* SkMovie::DecodeStream(SkStream* stream) { 142 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) {
143 return NULL; 143 return NULL;
144 } 144 }
145 145
146 ///////////////////////////////////////////////////////////////////////// 146 /////////////////////////////////////////////////////////////////////////
147 147
148 static size_t consumer_put(void* info, const void* buffer, size_t count) { 148 static size_t consumer_put(void* info, const void* buffer, size_t count) {
149 SkWStream* stream = reinterpret_cast<SkWStream*>(info); 149 SkWStream* stream = reinterpret_cast<SkWStream*>(info);
150 return stream->write(buffer, count) ? count : 0; 150 return stream->write(buffer, count) ? count : 0;
151 } 151 }
152 152
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { 280 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) {
281 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { 281 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) {
282 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp areEqualTo) { 282 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp areEqualTo) {
283 return gFormatConversions[i].fFormat; 283 return gFormatConversions[i].fFormat;
284 } 284 }
285 } 285 }
286 return SkImageDecoder::kUnknown_Format; 286 return SkImageDecoder::kUnknown_Format;
287 } 287 }
288 288
289 static SkImageDecoder::Format get_format_cg(SkStream *stream) { 289 static SkImageDecoder::Format get_format_cg(SkStreamRewindable* stream) {
290 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); 290 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
291 291
292 if (NULL == imageSrc) { 292 if (NULL == imageSrc) {
293 return SkImageDecoder::kUnknown_Format; 293 return SkImageDecoder::kUnknown_Format;
294 } 294 }
295 295
296 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); 296 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
297 const CFStringRef name = CGImageSourceGetType(imageSrc); 297 const CFStringRef name = CGImageSourceGetType(imageSrc);
298 if (NULL == name) { 298 if (NULL == name) {
299 return SkImageDecoder::kUnknown_Format; 299 return SkImageDecoder::kUnknown_Format;
300 } 300 }
301 return UTType_to_Format(name); 301 return UTType_to_Format(name);
302 } 302 }
303 303
304 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_cg); 304 static SkTRegistry<SkImageDecoder::Format, SkStreamRewindable*> gFormatReg(get_f ormat_cg);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698