blob: 29df8b81a889d4050ab5f59bea06b0054869c502 [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"
reed@android.comf2b98d62010-12-20 18:26:13 +000013
halcanary0cbe7ee2015-12-01 09:02:49 -080014#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
15
reed@android.comf2b98d62010-12-20 18:26:13 +000016#ifdef SK_BUILD_FOR_MAC
yangsu@google.comccb74ea2011-06-21 13:09:32 +000017#include <ApplicationServices/ApplicationServices.h>
reed@android.comf2b98d62010-12-20 18:26:13 +000018#endif
reed@android.com0d55f1e2008-12-18 19:26:11 +000019
yangsu@google.comc134f392011-06-23 22:27:30 +000020#ifdef SK_BUILD_FOR_IOS
21#include <CoreGraphics/CoreGraphics.h>
22#endif
23
reed@android.com0d55f1e2008-12-18 19:26:11 +000024class SkBitmap;
reed@google.com12b1f192013-03-25 20:15:40 +000025class SkData;
bungemanf93d7112016-09-16 06:24:20 -070026class SkStreamRewindable;
reed@android.com0d55f1e2008-12-18 19:26:11 +000027
reed@android.com38669c12011-01-03 13:48:50 +000028/**
commit-bot@chromium.org60b5dce2014-04-22 20:24:33 +000029 * Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
30 * null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
31 * Otherwise use the image's width/height.
32 *
33 * On failure, return false, and leave bitmap unchanged.
34 */
35SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src, SkISize* scaleToFit = NULL);
36
37/**
38 * Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
39 * return false (e.g. ImageInfo incompatible with src).
40 */
41SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
42 CGImageRef src);
43
44/**
reed@android.com38669c12011-01-03 13:48:50 +000045 * Create an imageref from the specified bitmap using the specified colorspace.
reed@google.com5a8a1312011-01-05 16:29:02 +000046 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
reed@android.com38669c12011-01-03 13:48:50 +000047 */
thakis@chromium.org368b4192012-02-09 22:09:41 +000048SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
49 CGColorSpaceRef space);
reed@android.com0d55f1e2008-12-18 19:26:11 +000050
reed@android.com38669c12011-01-03 13:48:50 +000051/**
reed@google.com5a8a1312011-01-05 16:29:02 +000052 * Create an imageref from the specified bitmap using the colorspace returned
53 * by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000054 */
reed@android.com4aaee0a2011-01-04 01:29:52 +000055static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
reed@android.com38669c12011-01-03 13:48:50 +000056 return SkCreateCGImageRefWithColorspace(bm, NULL);
57}
58
59/**
60 * Draw the bitmap into the specified CG context. The bitmap will be converted
61 * to a CGImage using the generic RGB colorspace. (x,y) specifies the position
reed@google.com5a8a1312011-01-05 16:29:02 +000062 * of the top-left corner of the bitmap. The bitmap is converted using the
63 * colorspace returned by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000064 */
reed@android.comf2b98d62010-12-20 18:26:13 +000065void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
66
scroggoa1193e42015-01-21 12:09:53 -080067/**
bungemanf93d7112016-09-16 06:24:20 -070068 * Return a provider that wraps the specified stream.
scroggoa1193e42015-01-21 12:09:53 -080069 * When the provider is finally deleted, it will delete the stream.
reed@google.com61c22042012-02-24 15:29:00 +000070 */
bungemanf93d7112016-09-16 06:24:20 -070071CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable>);
reed@google.com50b14a22013-03-25 20:21:26 +000072
bungemanf93d7112016-09-16 06:24:20 -070073CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>);
reed@google.com61c22042012-02-24 15:29:00 +000074
halcanary0cbe7ee2015-12-01 09:02:49 -080075#endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
76#endif // SkCGUtils_DEFINED