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 | |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 11 | #include "SkSize.h" |
| 12 | #include "SkImageInfo.h" |
Mike Reed | 463c848 | 2016-12-21 12:01:12 -0500 | [diff] [blame] | 13 | #include "SkImage.h" |
Leon Scroggins III | 0cbc10f | 2017-10-30 09:07:53 -0400 | [diff] [blame] | 14 | #include "SkPixmap.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 15 | |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame] | 16 | #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 17 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 18 | #ifdef SK_BUILD_FOR_MAC |
yangsu@google.com | ccb74ea | 2011-06-21 13:09:32 +0000 | [diff] [blame] | 19 | #include <ApplicationServices/ApplicationServices.h> |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 20 | #endif |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 21 | |
yangsu@google.com | c134f39 | 2011-06-23 22:27:30 +0000 | [diff] [blame] | 22 | #ifdef SK_BUILD_FOR_IOS |
| 23 | #include <CoreGraphics/CoreGraphics.h> |
| 24 | #endif |
| 25 | |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 26 | class SkBitmap; |
reed@google.com | 12b1f19 | 2013-03-25 20:15:40 +0000 | [diff] [blame] | 27 | class SkData; |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 28 | class SkPixmap; |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 29 | class SkStreamRewindable; |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 30 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 31 | SK_API CGContextRef SkCreateCGContext(const SkPixmap&); |
| 32 | |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 33 | /** |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 34 | * Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not |
| 35 | * null, use it to determine the size of the bitmap, and scale the image to fill the bitmap. |
| 36 | * Otherwise use the image's width/height. |
| 37 | * |
| 38 | * On failure, return false, and leave bitmap unchanged. |
| 39 | */ |
Mike Reed | 463c848 | 2016-12-21 12:01:12 -0500 | [diff] [blame] | 40 | SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src); |
| 41 | |
| 42 | SK_API sk_sp<SkImage> SkMakeImageFromCGImage(CGImageRef); |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure, |
| 46 | * return false (e.g. ImageInfo incompatible with src). |
| 47 | */ |
| 48 | SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels, |
| 49 | CGImageRef src); |
Leon Scroggins III | 0cbc10f | 2017-10-30 09:07:53 -0400 | [diff] [blame] | 50 | static inline bool SkCopyPixelsFromCGImage(const SkPixmap& dst, CGImageRef src) { |
| 51 | return SkCopyPixelsFromCGImage(dst.info(), dst.rowBytes(), dst.writable_addr(), src); |
| 52 | } |
commit-bot@chromium.org | 60b5dce | 2014-04-22 20:24:33 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 55 | * Create an imageref from the specified bitmap using the specified colorspace. |
reed@google.com | 5a8a131 | 2011-01-05 16:29:02 +0000 | [diff] [blame] | 56 | * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used. |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 57 | */ |
thakis@chromium.org | 368b419 | 2012-02-09 22:09:41 +0000 | [diff] [blame] | 58 | SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, |
| 59 | CGColorSpaceRef space); |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame] | 60 | |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 61 | /** |
reed@google.com | 5a8a131 | 2011-01-05 16:29:02 +0000 | [diff] [blame] | 62 | * Create an imageref from the specified bitmap using the colorspace returned |
| 63 | * by CGColorSpaceCreateDeviceRGB() |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 64 | */ |
reed@android.com | 4aaee0a | 2011-01-04 01:29:52 +0000 | [diff] [blame] | 65 | static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 66 | return SkCreateCGImageRefWithColorspace(bm, NULL); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Draw the bitmap into the specified CG context. The bitmap will be converted |
| 71 | * 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] | 72 | * of the top-left corner of the bitmap. The bitmap is converted using the |
| 73 | * colorspace returned by CGColorSpaceCreateDeviceRGB() |
reed@android.com | 38669c1 | 2011-01-03 13:48:50 +0000 | [diff] [blame] | 74 | */ |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 75 | void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y); |
| 76 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 77 | /** |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 78 | * Return a provider that wraps the specified stream. |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 79 | * When the provider is finally deleted, it will delete the stream. |
reed@google.com | 61c2204 | 2012-02-24 15:29:00 +0000 | [diff] [blame] | 80 | */ |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 81 | CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable>); |
reed@google.com | 50b14a2 | 2013-03-25 20:21:26 +0000 | [diff] [blame] | 82 | |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 83 | CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>); |
reed@google.com | 61c2204 | 2012-02-24 15:29:00 +0000 | [diff] [blame] | 84 | |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame] | 85 | #endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 86 | #endif // SkCGUtils_DEFINED |