1
2 /*
3 * Copyright 2011 Google Inc.
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 #ifndef SkCGUtils_DEFINED
9 #define SkCGUtils_DEFINED
10
11 #include "SkTypes.h"
12
13 #ifdef SK_BUILD_FOR_MAC
14 #include <ApplicationServices/ApplicationServices.h>
15 #endif
16
17 #ifdef SK_BUILD_FOR_IOS
18 #include <CoreGraphics/CoreGraphics.h>
19 #endif
20
21 class SkBitmap;
22 class SkStream;
23
24 /**
25 * Create an imageref from the specified bitmap using the specified colorspace.
26 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
27 */
28 SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
29 CGColorSpaceRef space);
30
31 /**
32 * Create an imageref from the specified bitmap using the colorspace returned
33 * by CGColorSpaceCreateDeviceRGB()
34 */
SkCreateCGImageRef(const SkBitmap & bm)35 static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
36 return SkCreateCGImageRefWithColorspace(bm, NULL);
37 }
38
39 /**
40 * Draw the bitmap into the specified CG context. The bitmap will be converted
41 * to a CGImage using the generic RGB colorspace. (x,y) specifies the position
42 * of the top-left corner of the bitmap. The bitmap is converted using the
43 * colorspace returned by CGColorSpaceCreateDeviceRGB()
44 */
45 void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
46
47 bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
48
49 /**
50 * Return a provider that wraps the specified stream. It will become an
51 * owner of the stream, so the caller must still manage its ownership.
52 *
53 * To hand-off ownership of the stream to the provider, the caller must do
54 * something like the following:
55 *
56 * SkStream* stream = new ...;
57 * CGDataProviderRef provider = SkStreamToDataProvider(stream);
58 * stream->unref();
59 *
60 * Now when the provider is finally deleted, it will delete the stream.
61 */
62 CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
63
64 #endif
65