• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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  */
8 #ifndef SkCGUtils_DEFINED
9 #define SkCGUtils_DEFINED
10 
11 #include "SkSize.h"
12 #include "SkImageInfo.h"
13 
14 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
15 
16 #ifdef SK_BUILD_FOR_MAC
17 #include <ApplicationServices/ApplicationServices.h>
18 #endif
19 
20 #ifdef SK_BUILD_FOR_IOS
21 #include <CoreGraphics/CoreGraphics.h>
22 #endif
23 
24 class SkBitmap;
25 class SkData;
26 class SkStream;
27 
28 /**
29  *  Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not
30  *  null, use it to determine the size of the bitmap, and scale the image to fill the bitmap.
31  *  Otherwise use the image's width/height.
32  *
33  *  On failure, return false, and leave bitmap unchanged.
34  */
35 SK_API bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef src, SkISize* scaleToFit = NULL);
36 
37 /**
38  *  Copy the pixels from src into the memory specified by info/rowBytes/dstPixels. On failure,
39  *  return false (e.g. ImageInfo incompatible with src).
40  */
41 SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* dstPixels,
42                                     CGImageRef src);
43 
44 /**
45  *  Create an imageref from the specified bitmap using the specified colorspace.
46  *  If space is NULL, then CGColorSpaceCreateDeviceRGB() is used.
47  */
48 SK_API CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
49                                                    CGColorSpaceRef space);
50 
51 /**
52  *  Create an imageref from the specified bitmap using the colorspace returned
53  *  by CGColorSpaceCreateDeviceRGB()
54  */
SkCreateCGImageRef(const SkBitmap & bm)55 static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
56     return SkCreateCGImageRefWithColorspace(bm, NULL);
57 }
58 
59 /**
60  *  Draw the bitmap into the specified CG context. The bitmap will be converted
61  *  to a CGImage using the generic RGB colorspace. (x,y) specifies the position
62  *  of the top-left corner of the bitmap. The bitmap is converted using the
63  *  colorspace returned by CGColorSpaceCreateDeviceRGB()
64  */
65 void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
66 
67 /**
68  *  Create an SkBitmap drawing of the encoded PDF document, returning true on
69  *  success. Deletes the stream when finished.
70  */
71 bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
72 
73 /**
74  *  Return a provider that wraps the specified stream. It will become the only
75  *  owner of the stream, so the caller must stop referring to the stream.
76  *
77  *  When the provider is finally deleted, it will delete the stream.
78  */
79 CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
80 
81 CGDataProviderRef SkCreateDataProviderFromData(SkData*);
82 
83 #endif  // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
84 #endif  // SkCGUtils_DEFINED
85