michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkCGUtils_DEFINED michael@0: #define SkCGUtils_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: #ifdef SK_BUILD_FOR_MAC michael@0: #include michael@0: #endif michael@0: michael@0: #ifdef SK_BUILD_FOR_IOS michael@0: #include michael@0: #endif michael@0: michael@0: class SkBitmap; michael@0: class SkData; michael@0: class SkStream; michael@0: michael@0: /** michael@0: * Create an imageref from the specified bitmap using the specified colorspace. michael@0: * If space is NULL, then CGColorSpaceCreateDeviceRGB() is used. michael@0: */ michael@0: SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, michael@0: CGColorSpaceRef space); michael@0: michael@0: /** michael@0: * Create an imageref from the specified bitmap using the colorspace returned michael@0: * by CGColorSpaceCreateDeviceRGB() michael@0: */ michael@0: static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { michael@0: return SkCreateCGImageRefWithColorspace(bm, NULL); michael@0: } michael@0: michael@0: /** michael@0: * Draw the bitmap into the specified CG context. The bitmap will be converted michael@0: * to a CGImage using the generic RGB colorspace. (x,y) specifies the position michael@0: * of the top-left corner of the bitmap. The bitmap is converted using the michael@0: * colorspace returned by CGColorSpaceCreateDeviceRGB() michael@0: */ michael@0: void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y); michael@0: michael@0: bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output); michael@0: michael@0: /** michael@0: * Return a provider that wraps the specified stream. It will become an michael@0: * owner of the stream, so the caller must still manage its ownership. michael@0: * michael@0: * To hand-off ownership of the stream to the provider, the caller must do michael@0: * something like the following: michael@0: * michael@0: * SkStream* stream = new ...; michael@0: * CGDataProviderRef provider = SkStreamToDataProvider(stream); michael@0: * stream->unref(); michael@0: * michael@0: * Now when the provider is finally deleted, it will delete the stream. michael@0: */ michael@0: CGDataProviderRef SkCreateDataProviderFromStream(SkStream*); michael@0: michael@0: CGDataProviderRef SkCreateDataProviderFromData(SkData*); michael@0: michael@0: #endif