2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2008-12-18 19:26:11 +00:00
|
|
|
#ifndef SkCGUtils_DEFINED
|
|
|
|
#define SkCGUtils_DEFINED
|
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkImageInfo.h"
|
2016-12-21 17:01:12 +00:00
|
|
|
#include "SkImage.h"
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2015-12-01 17:02:49 +00:00
|
|
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2011-06-21 13:09:32 +00:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
2010-12-20 18:26:13 +00:00
|
|
|
#endif
|
2008-12-18 19:26:11 +00:00
|
|
|
|
2011-06-23 22:27:30 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
|
|
|
#include <CoreGraphics/CoreGraphics.h>
|
|
|
|
#endif
|
|
|
|
|
2008-12-18 19:26:11 +00:00
|
|
|
class SkBitmap;
|
2013-03-25 20:15:40 +00:00
|
|
|
class SkData;
|
2017-01-10 16:58:39 +00:00
|
|
|
class SkPixmap;
|
2016-09-16 13:24:20 +00:00
|
|
|
class SkStreamRewindable;
|
2008-12-18 19:26:11 +00:00
|
|
|
|
2017-01-10 16:58:39 +00:00
|
|
|
SK_API CGContextRef SkCreateCGContext(const SkPixmap&);
|
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
/**
|
|
|
|
* Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
|
|
|
|
* null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
|
|
|
|
* Otherwise use the image's width/height.
|
|
|
|
*
|
|
|
|
* On failure, return false, and leave bitmap unchanged.
|
|
|
|
*/
|
2016-12-21 17:01:12 +00:00
|
|
|
SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src);
|
|
|
|
|
|
|
|
SK_API sk_sp<SkImage> SkMakeImageFromCGImage(CGImageRef);
|
2014-04-22 20:24:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
|
|
|
|
* return false (e.g. ImageInfo incompatible with src).
|
|
|
|
*/
|
|
|
|
SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
|
|
|
|
CGImageRef src);
|
|
|
|
|
2011-01-03 13:48:50 +00:00
|
|
|
/**
|
|
|
|
* Create an imageref from the specified bitmap using the specified colorspace.
|
2011-01-05 16:29:02 +00:00
|
|
|
* If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
|
2011-01-03 13:48:50 +00:00
|
|
|
*/
|
2012-02-09 22:09:41 +00:00
|
|
|
SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
|
|
|
|
CGColorSpaceRef space);
|
2008-12-18 19:26:11 +00:00
|
|
|
|
2011-01-03 13:48:50 +00:00
|
|
|
/**
|
2011-01-05 16:29:02 +00:00
|
|
|
* Create an imageref from the specified bitmap using the colorspace returned
|
|
|
|
* by CGColorSpaceCreateDeviceRGB()
|
2011-01-03 13:48:50 +00:00
|
|
|
*/
|
2011-01-04 01:29:52 +00:00
|
|
|
static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
|
2011-01-03 13:48:50 +00:00
|
|
|
return SkCreateCGImageRefWithColorspace(bm, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the bitmap into the specified CG context. The bitmap will be converted
|
|
|
|
* to a CGImage using the generic RGB colorspace. (x,y) specifies the position
|
2011-01-05 16:29:02 +00:00
|
|
|
* of the top-left corner of the bitmap. The bitmap is converted using the
|
|
|
|
* colorspace returned by CGColorSpaceCreateDeviceRGB()
|
2011-01-03 13:48:50 +00:00
|
|
|
*/
|
2010-12-20 18:26:13 +00:00
|
|
|
void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
|
|
|
|
|
2015-01-21 20:09:53 +00:00
|
|
|
/**
|
2016-09-16 13:24:20 +00:00
|
|
|
* Return a provider that wraps the specified stream.
|
2015-01-21 20:09:53 +00:00
|
|
|
* When the provider is finally deleted, it will delete the stream.
|
2012-02-24 15:29:00 +00:00
|
|
|
*/
|
2016-09-16 13:24:20 +00:00
|
|
|
CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable>);
|
2013-03-25 20:21:26 +00:00
|
|
|
|
2016-09-16 13:24:20 +00:00
|
|
|
CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>);
|
2012-02-24 15:29:00 +00:00
|
|
|
|
2015-12-01 17:02:49 +00:00
|
|
|
#endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
#endif // SkCGUtils_DEFINED
|