| 1 | /* CoreGraphics - CGImage.h |
|---|
| 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | #ifndef CGIMAGE_H_ |
|---|
| 7 | #define CGIMAGE_H_ |
|---|
| 8 | |
|---|
| 9 | typedef struct CGImage *CGImageRef; |
|---|
| 10 | |
|---|
| 11 | #include <CoreGraphics/CGColorSpace.h> |
|---|
| 12 | #include <CoreGraphics/CGDataProvider.h> |
|---|
| 13 | #include <CoreGraphics/CGGeometry.h> |
|---|
| 14 | |
|---|
| 15 | CG_EXTERN_C_BEGIN |
|---|
| 16 | |
|---|
| 17 | enum CGImageAlphaInfo { |
|---|
| 18 | kCGImageAlphaNone, /* For example, RGB. */ |
|---|
| 19 | kCGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */ |
|---|
| 20 | kCGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */ |
|---|
| 21 | kCGImageAlphaLast, /* For example, non-premultiplied RGBA */ |
|---|
| 22 | kCGImageAlphaFirst, /* For example, non-premultiplied ARGB */ |
|---|
| 23 | kCGImageAlphaNoneSkipLast, /* For example, RBGX. */ |
|---|
| 24 | kCGImageAlphaNoneSkipFirst, /* For example, XRGB. */ |
|---|
| 25 | kCGImageAlphaOnly /* No color data, alpha data only */ |
|---|
| 26 | }; |
|---|
| 27 | typedef enum CGImageAlphaInfo CGImageAlphaInfo; |
|---|
| 28 | |
|---|
| 29 | enum { |
|---|
| 30 | kCGBitmapAlphaInfoMask = 0x1F, |
|---|
| 31 | kCGBitmapFloatComponents = (1 << 8), |
|---|
| 32 | |
|---|
| 33 | kCGBitmapByteOrderMask = 0x7000, |
|---|
| 34 | kCGBitmapByteOrderDefault = (0 << 12), |
|---|
| 35 | kCGBitmapByteOrder16Little = (1 << 12), |
|---|
| 36 | kCGBitmapByteOrder32Little = (2 << 12), |
|---|
| 37 | kCGBitmapByteOrder16Big = (3 << 12), |
|---|
| 38 | kCGBitmapByteOrder32Big = (4 << 12) |
|---|
| 39 | }; |
|---|
| 40 | typedef uint32_t CGBitmapInfo; /* Available in MAC OS X 10.4 & later. */ |
|---|
| 41 | |
|---|
| 42 | #ifdef __BIG_ENDIAN__ |
|---|
| 43 | #define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Big |
|---|
| 44 | #define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Big |
|---|
| 45 | #else /* Little endian. */ |
|---|
| 46 | #define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Little |
|---|
| 47 | #define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Little |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | /* Return the CFTypeID for CGImageRefs. */ |
|---|
| 51 | |
|---|
| 52 | CG_EXTERN CFTypeID CGImageGetTypeID(void) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
|---|
| 53 | |
|---|
| 54 | /* Create an image. */ |
|---|
| 55 | |
|---|
| 56 | CG_EXTERN CGImageRef CGImageCreate(size_t width, size_t height, size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo, CGDataProviderRef provider, const float decode[], bool shouldInterpolate, CGColorRenderingIntent intent); |
|---|
| 57 | |
|---|
| 58 | /* Create an image mask. */ |
|---|
| 59 | |
|---|
| 60 | CG_EXTERN CGImageRef CGImageMaskCreate(size_t width, size_t height, size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow, CGDataProviderRef provider, const float decode[], bool shouldInterpolate); |
|---|
| 61 | |
|---|
| 62 | /* Return a copy of `image'. Only the image structure itself is copied; the |
|---|
| 63 | * underlying data is not. */ |
|---|
| 64 | |
|---|
| 65 | CG_EXTERN CGImageRef CGImageCreateCopy(CGImageRef image); |
|---|
| 66 | |
|---|
| 67 | /* Create an image from `source', a data provider of JPEG-encoded data. */ |
|---|
| 68 | |
|---|
| 69 | CG_EXTERN CGImageRef CGImageCreateWithJPEGDataProvider(CGDataProviderRef source, const float decode[], bool shouldInterpolate, CGColorRenderingIntent intent) AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER; |
|---|
| 70 | |
|---|
| 71 | /* Create an image using `source', a data provider for PNG-encoded data. */ |
|---|
| 72 | |
|---|
| 73 | CG_EXTERN CGImageRef CGImageCreateWithPNGDataProvider(CGDataProviderRef source, const float decode[], bool shouldInterpolate, CGColorRenderingIntent intent) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
|---|
| 74 | |
|---|
| 75 | /* Create an image using the data contained within the subrectangle `rect' |
|---|
| 76 | * of `image'. |
|---|
| 77 | * |
|---|
| 78 | * The new image is created by |
|---|
| 79 | * 1) adjusting `rect' to integral bounds by calling "CGRectIntegral"; |
|---|
| 80 | * 2) intersecting the result with a rectangle with origin (0, 0) and |
|---|
| 81 | * size equal to the size of `image'; |
|---|
| 82 | * 3) referencing the pixels within the resulting rectangle, treating the |
|---|
| 83 | * first pixel of the image data as the origin of the image. |
|---|
| 84 | * If the resulting rectangle is the null rectangle, this function returns |
|---|
| 85 | * NULL. |
|---|
| 86 | * |
|---|
| 87 | * If W and H are the width and height of image, respectively, then the |
|---|
| 88 | * point (0,0) corresponds to the first pixel of the image data; the point |
|---|
| 89 | * (W-1, 0) is the last pixel of the first row of the image data; (0, H-1) |
|---|
| 90 | * is the first pixel of the last row of the image data; and (W-1, H-1) is |
|---|
| 91 | * the last pixel of the last row of the image data. |
|---|
| 92 | * |
|---|
| 93 | * The resulting image retains a reference to the original image, so you |
|---|
| 94 | * may release the original image after calling this function. */ |
|---|
| 95 | |
|---|
| 96 | CG_EXTERN CGImageRef CGImageCreateWithImageInRect(CGImageRef image, CGRect rect) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; |
|---|
| 97 | |
|---|
| 98 | /* Create a new image from `image' masked by `mask', which may be an image |
|---|
| 99 | * mask or an image. |
|---|
| 100 | * |
|---|
| 101 | * If `mask' is an image mask, then it indicates which parts of the context |
|---|
| 102 | * are to be painted with the image when drawn in a context, and which are |
|---|
| 103 | * to be masked out (left unchanged). The source samples of the image mask |
|---|
| 104 | * determine which areas are painted, acting as an "inverse alpha": if the |
|---|
| 105 | * value of a source sample in the image mask is S, then the corresponding |
|---|
| 106 | * region in `image' is blended with the destination using an alpha of |
|---|
| 107 | * (1-S). (For example, if S is 1, then the region is not painted, while |
|---|
| 108 | * if S is 0, the region is fully painted.) |
|---|
| 109 | * |
|---|
| 110 | * If `mask' is an image, then it serves as alpha mask for blending the |
|---|
| 111 | * image onto the destination. The source samples of `mask' determine |
|---|
| 112 | * which areas are painted: if the value of the source sample in mask is S, |
|---|
| 113 | * then the corresponding region in image is blended with the destination |
|---|
| 114 | * with an alpha of S. (For example, if S is 0, then the region is not |
|---|
| 115 | * painted, while if S is 1, the region is fully painted.) |
|---|
| 116 | * |
|---|
| 117 | * The parameter `image' may not be an image mask and may not have an image |
|---|
| 118 | * mask or masking color associated with it. |
|---|
| 119 | * |
|---|
| 120 | * If `mask' is an image, then it must be in the DeviceGray color space, |
|---|
| 121 | * may not have alpha, and may not itself be masked by an image mask |
|---|
| 122 | * or a masking color. */ |
|---|
| 123 | |
|---|
| 124 | CG_EXTERN CGImageRef CGImageCreateWithMask(CGImageRef image, CGImageRef mask) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; |
|---|
| 125 | |
|---|
| 126 | /* Create a new image from `image' masked by `components', an array of 2N |
|---|
| 127 | * values { min[1], max[1], ... min[N], max[N] } where N is the number of |
|---|
| 128 | * components in color space of `image'. Any image sample with color value |
|---|
| 129 | * {c[1], ... c[N]} where min[i] <= c[i] <= max[i] for 1 <= i <= N is |
|---|
| 130 | * masked out (that is, not painted). |
|---|
| 131 | * |
|---|
| 132 | * Each value in `components' must be a valid image sample value: if |
|---|
| 133 | * `image' has integral pixel components, then each value of must be in the |
|---|
| 134 | * range [0 .. 2**bitsPerComponent - 1] (where `bitsPerComponent' is the |
|---|
| 135 | * number of bits/component of `image'); if `image' has floating-point |
|---|
| 136 | * pixel components, then each value may be any floating-point number which |
|---|
| 137 | * is a valid color component. |
|---|
| 138 | * |
|---|
| 139 | * The parameter `image' may not be an image mask, and may not already have |
|---|
| 140 | * an image mask or masking color associated with it. */ |
|---|
| 141 | |
|---|
| 142 | CG_EXTERN CGImageRef CGImageCreateWithMaskingColors(CGImageRef image, const float components[]) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; |
|---|
| 143 | |
|---|
| 144 | /* Create a copy of `image', replacing the image's colorspace with |
|---|
| 145 | * `colorspace'. Returns NULL if `image' is an image mask, or if the |
|---|
| 146 | * number of components of `colorspace' isn't the same as the number of |
|---|
| 147 | * components of the colorspace of `image'. */ |
|---|
| 148 | |
|---|
| 149 | CG_EXTERN CGImageRef CGImageCreateCopyWithColorSpace(CGImageRef image, CGColorSpaceRef colorspace) AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER; |
|---|
| 150 | |
|---|
| 151 | /* Equivalent to `CFRetain(image)'. */ |
|---|
| 152 | |
|---|
| 153 | CG_EXTERN CGImageRef CGImageRetain(CGImageRef image); |
|---|
| 154 | |
|---|
| 155 | /* Equivalent to `CFRelease(image)'. */ |
|---|
| 156 | |
|---|
| 157 | CG_EXTERN void CGImageRelease(CGImageRef image); |
|---|
| 158 | |
|---|
| 159 | /* Return true if `image' is an image mask, false otherwise. */ |
|---|
| 160 | |
|---|
| 161 | CG_EXTERN bool CGImageIsMask(CGImageRef image); |
|---|
| 162 | |
|---|
| 163 | /* Return the width of `image'. */ |
|---|
| 164 | |
|---|
| 165 | CG_EXTERN size_t CGImageGetWidth(CGImageRef image); |
|---|
| 166 | |
|---|
| 167 | /* Return the height of `image'. */ |
|---|
| 168 | |
|---|
| 169 | CG_EXTERN size_t CGImageGetHeight(CGImageRef image); |
|---|
| 170 | |
|---|
| 171 | /* Return the number of bits/component of `image'. */ |
|---|
| 172 | |
|---|
| 173 | CG_EXTERN size_t CGImageGetBitsPerComponent(CGImageRef image); |
|---|
| 174 | |
|---|
| 175 | /* Return the number of bits/pixel of `image'. */ |
|---|
| 176 | |
|---|
| 177 | CG_EXTERN size_t CGImageGetBitsPerPixel(CGImageRef image); |
|---|
| 178 | |
|---|
| 179 | /* Return the number of bytes/row of `image'. */ |
|---|
| 180 | |
|---|
| 181 | CG_EXTERN size_t CGImageGetBytesPerRow(CGImageRef image); |
|---|
| 182 | |
|---|
| 183 | /* Return the colorspace of `image', or NULL if `image' is an image |
|---|
| 184 | * mask. */ |
|---|
| 185 | |
|---|
| 186 | CG_EXTERN CGColorSpaceRef CGImageGetColorSpace(CGImageRef image); |
|---|
| 187 | |
|---|
| 188 | /* Return the alpha info of `image'. */ |
|---|
| 189 | |
|---|
| 190 | CG_EXTERN CGImageAlphaInfo CGImageGetAlphaInfo(CGImageRef image); |
|---|
| 191 | |
|---|
| 192 | /* Return the data provider of `image'. */ |
|---|
| 193 | |
|---|
| 194 | CG_EXTERN CGDataProviderRef CGImageGetDataProvider(CGImageRef image); |
|---|
| 195 | |
|---|
| 196 | /* Return the decode array of `image'. */ |
|---|
| 197 | |
|---|
| 198 | CG_EXTERN const float *CGImageGetDecode(CGImageRef image); |
|---|
| 199 | |
|---|
| 200 | /* Return the interpolation parameter of `image'. */ |
|---|
| 201 | |
|---|
| 202 | CG_EXTERN bool CGImageGetShouldInterpolate(CGImageRef image); |
|---|
| 203 | |
|---|
| 204 | /* Return the rendering intent of `image'. */ |
|---|
| 205 | |
|---|
| 206 | CG_EXTERN CGColorRenderingIntent CGImageGetRenderingIntent(CGImageRef image); |
|---|
| 207 | |
|---|
| 208 | /* Return the bitmap info of `image'. */ |
|---|
| 209 | |
|---|
| 210 | CG_EXTERN CGBitmapInfo CGImageGetBitmapInfo(CGImageRef image) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; |
|---|
| 211 | |
|---|
| 212 | CG_EXTERN_C_END |
|---|
| 213 | |
|---|
| 214 | #endif /* CGIMAGE_H_ */ |
|---|