blob: 84b95a4aac672a456b742c9523333c021bd19f31 [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
reed@android.comf2b98d62010-12-20 18:26:13 +000011#include "SkTypes.h"
12
13#ifdef SK_BUILD_FOR_MAC
yangsu@google.comccb74ea2011-06-21 13:09:32 +000014#include <ApplicationServices/ApplicationServices.h>
reed@android.comf2b98d62010-12-20 18:26:13 +000015#endif
reed@android.com0d55f1e2008-12-18 19:26:11 +000016
yangsu@google.comc134f392011-06-23 22:27:30 +000017#ifdef SK_BUILD_FOR_IOS
18#include <CoreGraphics/CoreGraphics.h>
19#endif
20
reed@android.com0d55f1e2008-12-18 19:26:11 +000021class SkBitmap;
reed@google.com12b1f192013-03-25 20:15:40 +000022class SkData;
reed@google.com292ade62011-06-28 20:54:03 +000023class SkStream;
reed@android.com0d55f1e2008-12-18 19:26:11 +000024
reed@android.com38669c12011-01-03 13:48:50 +000025/**
26 * Create an imageref from the specified bitmap using the specified colorspace.
reed@google.com5a8a1312011-01-05 16:29:02 +000027 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
reed@android.com38669c12011-01-03 13:48:50 +000028 */
thakis@chromium.org368b4192012-02-09 22:09:41 +000029SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
30 CGColorSpaceRef space);
reed@android.com0d55f1e2008-12-18 19:26:11 +000031
reed@android.com38669c12011-01-03 13:48:50 +000032/**
reed@google.com5a8a1312011-01-05 16:29:02 +000033 * Create an imageref from the specified bitmap using the colorspace returned
34 * by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000035 */
reed@android.com4aaee0a2011-01-04 01:29:52 +000036static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
reed@android.com38669c12011-01-03 13:48:50 +000037 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.com5a8a1312011-01-05 16:29:02 +000043 * of the top-left corner of the bitmap. The bitmap is converted using the
44 * colorspace returned by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000045 */
reed@android.comf2b98d62010-12-20 18:26:13 +000046void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
47
reed@google.com292ade62011-06-28 20:54:03 +000048bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
49
reed@google.com61c22042012-02-24 15:29:00 +000050/**
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 */
63CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
reed@google.com12b1f192013-03-25 20:15:40 +000064CGDataProviderRef SkCreateDataProviderFromStream(SkData*);
reed@google.com61c22042012-02-24 15:29:00 +000065
reed@android.com0d55f1e2008-12-18 19:26:11 +000066#endif