epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 8 | #ifndef SkCGUtils_DEFINED |
| 9 | #define SkCGUtils_DEFINED |
| 10 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
| 12 | |
| 13 | #ifdef SK_BUILD_FOR_MAC |
yangsu@google.com | ccb74ea | 2011-06-21 13:09:32 +0000 | [diff] [blame] | 14 | #include <ApplicationServices/ApplicationServices.h> |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 15 | #endif |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 16 | |
yangsu@google.com | c134f39 | 2011-06-23 22:27:30 +0000 | [diff] [blame] | 17 | #ifdef SK_BUILD_FOR_IOS |
| 18 | #include <CoreGraphics/CoreGraphics.h> |
| 19 | #endif |
| 20 | |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 21 | class SkBitmap; |
reed@google.com | 12b1f19 | 2013-03-25 20:15:40 +0000 | [diff] [blame^] | 22 | class SkData; |
reed@google.com | 292ade6 | 2011-06-28 20:54:03 +0000 | [diff] [blame] | 23 | class SkStream; |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 24 | |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Create an imageref from the specified bitmap using the specified colorspace. |
reed@google.com | 5a8a131 | 2011-01-05 16:29:02 +0000 | [diff] [blame] | 27 | * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used. |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 28 | */ |
thakis@chromium.org | 368b419 | 2012-02-09 22:09:41 +0000 | [diff] [blame] | 29 | SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, |
| 30 | CGColorSpaceRef space); |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 31 | |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 32 | /** |
reed@google.com | 5a8a131 | 2011-01-05 16:29:02 +0000 | [diff] [blame] | 33 | * Create an imageref from the specified bitmap using the colorspace returned |
| 34 | * by CGColorSpaceCreateDeviceRGB() |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 35 | */ |
reed@android.com | 4aaee0a | 2011-01-04 01:29:52 +0000 | [diff] [blame] | 36 | static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 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 |
reed@google.com | 5a8a131 | 2011-01-05 16:29:02 +0000 | [diff] [blame] | 43 | * of the top-left corner of the bitmap. The bitmap is converted using the |
| 44 | * colorspace returned by CGColorSpaceCreateDeviceRGB() |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 45 | */ |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 46 | void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y); |
| 47 | |
reed@google.com | 292ade6 | 2011-06-28 20:54:03 +0000 | [diff] [blame] | 48 | bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output); |
| 49 | |
reed@google.com | 61c2204 | 2012-02-24 15:29:00 +0000 | [diff] [blame] | 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*); |
reed@google.com | 12b1f19 | 2013-03-25 20:15:40 +0000 | [diff] [blame^] | 64 | CGDataProviderRef SkCreateDataProviderFromStream(SkData*); |
reed@google.com | 61c2204 | 2012-02-24 15:29:00 +0000 | [diff] [blame] | 65 | |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 66 | #endif |