• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkData;
23 class SkStream;
24 
25 /**
26  *  Create an imageref from the specified bitmap using the specified colorspace.
27  *  If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
28  */
29 SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
30                                                    CGColorSpaceRef space);
31 
32 /**
33  *  Create an imageref from the specified bitmap using the colorspace returned
34  *  by CGColorSpaceCreateDeviceRGB()
35  */
SkCreateCGImageRef(const SkBitmap & bm)36 static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
37     return SkCreateCGImageRefWithColorspace(bm, NULL);
38 }
39 
40 /**
41  *  Draw the bitmap into the specified CG context. The bitmap will be converted
42  *  to a CGImage using the generic RGB colorspace. (x,y) specifies the position
43  *  of the top-left corner of the bitmap. The bitmap is converted using the
44  *  colorspace returned by CGColorSpaceCreateDeviceRGB()
45  */
46 void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
47 
48 bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
49 
50 /**
51  *  Return a provider that wraps the specified stream. It will become an
52  *  owner of the stream, so the caller must still manage its ownership.
53  *
54  *  To hand-off ownership of the stream to the provider, the caller must do
55  *  something like the following:
56  *
57  *  SkStream* stream = new ...;
58  *  CGDataProviderRef provider = SkStreamToDataProvider(stream);
59  *  stream->unref();
60  *
61  *  Now when the provider is finally deleted, it will delete the stream.
62  */
63 CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
64 
65 CGDataProviderRef SkCreateDataProviderFromData(SkData*);
66 
67 #endif
68