blob: 7ac0431b25f0066e2da17b9287868687e9b59456 [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
14#ifdef SK_BUILD_FOR_MAC
yangsu@google.comccb74ea2011-06-21 13:09:32 +000015#include <ApplicationServices/ApplicationServices.h>
reed@android.comf2b98d62010-12-20 18:26:13 +000016#endif
reed@android.com0d55f1e2008-12-18 19:26:11 +000017
yangsu@google.comc134f392011-06-23 22:27:30 +000018#ifdef SK_BUILD_FOR_IOS
19#include <CoreGraphics/CoreGraphics.h>
20#endif
21
reed@android.com0d55f1e2008-12-18 19:26:11 +000022class SkBitmap;
reed@google.com12b1f192013-03-25 20:15:40 +000023class SkData;
reed@google.com292ade62011-06-28 20:54:03 +000024class SkStream;
reed@android.com0d55f1e2008-12-18 19:26:11 +000025
reed@android.com38669c12011-01-03 13:48:50 +000026/**
commit-bot@chromium.org60b5dce2014-04-22 20:24:33 +000027 * Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
28 * null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
29 * Otherwise use the image's width/height.
30 *
31 * On failure, return false, and leave bitmap unchanged.
32 */
33SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src, SkISize* scaleToFit = NULL);
34
35/**
36 * Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
37 * return false (e.g. ImageInfo incompatible with src).
38 */
39SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
40 CGImageRef src);
41
42/**
reed@android.com38669c12011-01-03 13:48:50 +000043 * Create an imageref from the specified bitmap using the specified colorspace.
reed@google.com5a8a1312011-01-05 16:29:02 +000044 * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
reed@android.com38669c12011-01-03 13:48:50 +000045 */
thakis@chromium.org368b4192012-02-09 22:09:41 +000046SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
47 CGColorSpaceRef space);
reed@android.com0d55f1e2008-12-18 19:26:11 +000048
reed@android.com38669c12011-01-03 13:48:50 +000049/**
reed@google.com5a8a1312011-01-05 16:29:02 +000050 * Create an imageref from the specified bitmap using the colorspace returned
51 * by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000052 */
reed@android.com4aaee0a2011-01-04 01:29:52 +000053static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
reed@android.com38669c12011-01-03 13:48:50 +000054 return SkCreateCGImageRefWithColorspace(bm, NULL);
55}
56
57/**
58 * Draw the bitmap into the specified CG context. The bitmap will be converted
59 * to a CGImage using the generic RGB colorspace. (x,y) specifies the position
reed@google.com5a8a1312011-01-05 16:29:02 +000060 * of the top-left corner of the bitmap. The bitmap is converted using the
61 * colorspace returned by CGColorSpaceCreateDeviceRGB()
reed@android.com38669c12011-01-03 13:48:50 +000062 */
reed@android.comf2b98d62010-12-20 18:26:13 +000063void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
64
scroggoa1193e42015-01-21 12:09:53 -080065/**
66 * Create an SkBitmap drawing of the encoded PDF document, returning true on
67 * success. Deletes the stream when finished.
68 */
reed@google.com292ade62011-06-28 20:54:03 +000069bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
70
reed@google.com61c22042012-02-24 15:29:00 +000071/**
scroggoa1193e42015-01-21 12:09:53 -080072 * Return a provider that wraps the specified stream. It will become the only
73 * owner of the stream, so the caller must stop referring to the stream.
reed@google.com61c22042012-02-24 15:29:00 +000074 *
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 */
77CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
reed@google.com50b14a22013-03-25 20:21:26 +000078
79CGDataProviderRef SkCreateDataProviderFromData(SkData*);
reed@google.com61c22042012-02-24 15:29:00 +000080
reed@android.com0d55f1e2008-12-18 19:26:11 +000081#endif