blob: 46f89960f8cd069a23e21594930cd9291d6759cc [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.com292ade62011-06-28 20:54:03 +000022class SkStream;
reed@android.com0d55f1e2008-12-18 19:26:11 +000023
reed@android.com38669c12011-01-03 13:48:50 +000024/**
25 * Create an imageref from the specified bitmap using the specified colorspace.
reed@google.com5a8a1312011-01-05 16:29:02 +000026 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
reed@android.com38669c12011-01-03 13:48:50 +000027 */
thakis@chromium.org368b4192012-02-09 22:09:41 +000028SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
29 CGColorSpaceRef space);
reed@android.com0d55f1e2008-12-18 19:26:11 +000030
reed@android.com38669c12011-01-03 13:48:50 +000031/**
reed@google.com5a8a1312011-01-05 16:29:02 +000032 * Create an imageref from the specified bitmap using the colorspace returned
33 * by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000034 */
reed@android.com4aaee0a2011-01-04 01:29:52 +000035static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
reed@android.com38669c12011-01-03 13:48:50 +000036 return SkCreateCGImageRefWithColorspace(bm, NULL);
37}
38
39/**
40 * Draw the bitmap into the specified CG context. The bitmap will be converted
41 * to a CGImage using the generic RGB colorspace. (x,y) specifies the position
reed@google.com5a8a1312011-01-05 16:29:02 +000042 * of the top-left corner of the bitmap. The bitmap is converted using the
43 * colorspace returned by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000044 */
reed@android.comf2b98d62010-12-20 18:26:13 +000045void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
46
reed@google.com292ade62011-06-28 20:54:03 +000047bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
48
reed@google.com61c22042012-02-24 15:29:00 +000049/**
50 * Return a provider that wraps the specified stream. It will become an
51 * owner of the stream, so the caller must still manage its ownership.
52 *
53 * To hand-off ownership of the stream to the provider, the caller must do
54 * something like the following:
55 *
56 * SkStream* stream = new ...;
57 * CGDataProviderRef provider = SkStreamToDataProvider(stream);
58 * stream->unref();
59 *
60 * Now when the provider is finally deleted, it will delete the stream.
61 */
62CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
63
reed@android.com0d55f1e2008-12-18 19:26:11 +000064#endif