blob: 2dcbb965b4b70493f8d0d25db1c04f661657ff12 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com0d55f1e2008-12-18 19:26:11 +00008#ifndef SkCGUtils_DEFINED
9#define SkCGUtils_DEFINED
10
commit-bot@chromium.org60b5dce2014-04-22 20:24:33 +000011#include "SkSize.h"
12#include "SkImageInfo.h"
Mike Reed463c8482016-12-21 12:01:12 -050013#include "SkImage.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000014
halcanary0cbe7ee2015-12-01 09:02:49 -080015#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
16
reed@android.comf2b98d62010-12-20 18:26:13 +000017#ifdef SK_BUILD_FOR_MAC
yangsu@google.comccb74ea2011-06-21 13:09:32 +000018#include <ApplicationServices/ApplicationServices.h>
reed@android.comf2b98d62010-12-20 18:26:13 +000019#endif
reed@android.com0d55f1e2008-12-18 19:26:11 +000020
yangsu@google.comc134f392011-06-23 22:27:30 +000021#ifdef SK_BUILD_FOR_IOS
22#include <CoreGraphics/CoreGraphics.h>
23#endif
24
reed@android.com0d55f1e2008-12-18 19:26:11 +000025class SkBitmap;
reed@google.com12b1f192013-03-25 20:15:40 +000026class SkData;
Mike Reed356f7c22017-01-10 11:58:39 -050027class SkPixmap;
bungemanf93d7112016-09-16 06:24:20 -070028class SkStreamRewindable;
reed@android.com0d55f1e2008-12-18 19:26:11 +000029
Mike Reed356f7c22017-01-10 11:58:39 -050030SK_API CGContextRef SkCreateCGContext(const SkPixmap&);
31
reed@android.com38669c12011-01-03 13:48:50 +000032/**
commit-bot@chromium.org60b5dce2014-04-22 20:24:33 +000033 * Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
34 * null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
35 * Otherwise use the image's width/height.
36 *
37 * On failure, return false, and leave bitmap unchanged.
38 */
Mike Reed463c8482016-12-21 12:01:12 -050039SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src);
40
41SK_API sk_sp<SkImage> SkMakeImageFromCGImage(CGImageRef);
commit-bot@chromium.org60b5dce2014-04-22 20:24:33 +000042
43/**
44 * Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
45 * return false (e.g. ImageInfo incompatible with src).
46 */
47SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
48 CGImageRef src);
49
50/**
reed@android.com38669c12011-01-03 13:48:50 +000051 * Create an imageref from the specified bitmap using the specified colorspace.
reed@google.com5a8a1312011-01-05 16:29:02 +000052 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
reed@android.com38669c12011-01-03 13:48:50 +000053 */
thakis@chromium.org368b4192012-02-09 22:09:41 +000054SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
55 CGColorSpaceRef space);
reed@android.com0d55f1e2008-12-18 19:26:11 +000056
reed@android.com38669c12011-01-03 13:48:50 +000057/**
reed@google.com5a8a1312011-01-05 16:29:02 +000058 * Create an imageref from the specified bitmap using the colorspace returned
59 * by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000060 */
reed@android.com4aaee0a2011-01-04 01:29:52 +000061static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
reed@android.com38669c12011-01-03 13:48:50 +000062 return SkCreateCGImageRefWithColorspace(bm, NULL);
63}
64
65/**
66 * Draw the bitmap into the specified CG context. The bitmap will be converted
67 * to a CGImage using the generic RGB colorspace. (x,y) specifies the position
reed@google.com5a8a1312011-01-05 16:29:02 +000068 * of the top-left corner of the bitmap. The bitmap is converted using the
69 * colorspace returned by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000070 */
reed@android.comf2b98d62010-12-20 18:26:13 +000071void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
72
scroggoa1193e42015-01-21 12:09:53 -080073/**
bungemanf93d7112016-09-16 06:24:20 -070074 * Return a provider that wraps the specified stream.
scroggoa1193e42015-01-21 12:09:53 -080075 * When the provider is finally deleted, it will delete the stream.
reed@google.com61c22042012-02-24 15:29:00 +000076 */
bungemanf93d7112016-09-16 06:24:20 -070077CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable>);
reed@google.com50b14a22013-03-25 20:21:26 +000078
bungemanf93d7112016-09-16 06:24:20 -070079CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>);
reed@google.com61c22042012-02-24 15:29:00 +000080
halcanary0cbe7ee2015-12-01 09:02:49 -080081#endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
82#endif // SkCGUtils_DEFINED