CGImage.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. { CoreGraphics - CGImage.h
  2. * Copyright (c) 2000-2004 Apple Computer, Inc.
  3. * All rights reserved.
  4. }
  5. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, August 2005 }
  6. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  7. { Pascal Translation Updated: Gale R Paeper, <[email protected]>, 2007 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 200
  11. Please report any bugs to <[email protected]>
  12. }
  13. {$mode macpas}
  14. {$packenum 1}
  15. {$macro on}
  16. {$inline on}
  17. {$CALLING MWPASCAL}
  18. unit CGImage;
  19. interface
  20. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  21. {$setc GAP_INTERFACES_VERSION := $0200}
  22. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  23. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  24. {$endc}
  25. {$ifc defined CPUPOWERPC and defined CPUI386}
  26. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  27. {$endc}
  28. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  29. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  30. {$endc}
  31. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  32. {$setc __ppc__ := 1}
  33. {$elsec}
  34. {$setc __ppc__ := 0}
  35. {$endc}
  36. {$ifc not defined __i386__ and defined CPUI386}
  37. {$setc __i386__ := 1}
  38. {$elsec}
  39. {$setc __i386__ := 0}
  40. {$endc}
  41. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  42. {$error Conflicting definitions for __ppc__ and __i386__}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__}
  45. {$setc TARGET_CPU_PPC := TRUE}
  46. {$setc TARGET_CPU_X86 := FALSE}
  47. {$elifc defined __i386__ and __i386__}
  48. {$setc TARGET_CPU_PPC := FALSE}
  49. {$setc TARGET_CPU_X86 := TRUE}
  50. {$elsec}
  51. {$error Neither __ppc__ nor __i386__ is defined.}
  52. {$endc}
  53. {$setc TARGET_CPU_PPC_64 := FALSE}
  54. {$ifc defined FPC_BIG_ENDIAN}
  55. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  56. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  57. {$elifc defined FPC_LITTLE_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  60. {$elsec}
  61. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  62. {$endc}
  63. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  64. {$setc CALL_NOT_IN_CARBON := FALSE}
  65. {$setc OLDROUTINENAMES := FALSE}
  66. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  67. {$setc OPAQUE_UPP_TYPES := TRUE}
  68. {$setc OTCARBONAPPLICATION := TRUE}
  69. {$setc OTKERNEL := FALSE}
  70. {$setc PM_USE_SESSION_APIS := TRUE}
  71. {$setc TARGET_API_MAC_CARBON := TRUE}
  72. {$setc TARGET_API_MAC_OS8 := FALSE}
  73. {$setc TARGET_API_MAC_OSX := TRUE}
  74. {$setc TARGET_CARBON := TRUE}
  75. {$setc TARGET_CPU_68K := FALSE}
  76. {$setc TARGET_CPU_MIPS := FALSE}
  77. {$setc TARGET_CPU_SPARC := FALSE}
  78. {$setc TARGET_OS_MAC := TRUE}
  79. {$setc TARGET_OS_UNIX := FALSE}
  80. {$setc TARGET_OS_WIN32 := FALSE}
  81. {$setc TARGET_RT_MAC_68881 := FALSE}
  82. {$setc TARGET_RT_MAC_CFM := FALSE}
  83. {$setc TARGET_RT_MAC_MACHO := TRUE}
  84. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  85. {$setc TYPE_BOOL := FALSE}
  86. {$setc TYPE_EXTENDED := FALSE}
  87. {$setc TYPE_LONGLONG := TRUE}
  88. uses MacTypes,CFBase,CGBase,CGGeometry,CGColorSpace,CGDataProvider;
  89. {$ALIGN POWER}
  90. type
  91. CGImageRef = ^SInt32; { an opaque 32-bit type }
  92. type
  93. CGImageAlphaInfo = SInt32;
  94. const
  95. kCGImageAlphaNone = 0; { For example, RGB. }
  96. kCGImageAlphaPremultipliedLast = 1; { For example, premultiplied RGBA }
  97. kCGImageAlphaPremultipliedFirst = 2; { For example, premultiplied ARGB }
  98. kCGImageAlphaLast = 3; { For example, non-premultiplied RGBA }
  99. kCGImageAlphaFirst = 4; { For example, non-premultiplied ARGB }
  100. kCGImageAlphaNoneSkipLast = 5; { For example, RBGX. }
  101. kCGImageAlphaNoneSkipFirst = 6; { For example, XRGB. }
  102. kCGImageAlphaOnly = 7; { No color data, alpha data only }
  103. const
  104. kCGBitmapAlphaInfoMask = $1F;
  105. kCGBitmapFloatComponents = 1 shl 8;
  106. kCGBitmapByteOrderMask = $7000;
  107. kCGBitmapByteOrder16Little = 1 shl 12;
  108. kCGBitmapByteOrder32Little = 2 shl 12;
  109. kCGBitmapByteOrder16Big = 3 shl 12;
  110. kCGBitmapByteOrder32Big = 4 shl 12;
  111. type
  112. CGBitmapInfo = UInt32; { Available in MAC OS X 10.4 & later. }
  113. const
  114. {$ifc TARGET_RT_BIG_ENDIAN}
  115. kCGBitmapByteOrder16Host = kCGBitmapByteOrder16Big;
  116. kCGBitmapByteOrder32Host = kCGBitmapByteOrder32Big;
  117. {$elsec}
  118. kCGBitmapByteOrder16Host = kCGBitmapByteOrder16Little;
  119. kCGBitmapByteOrder32Host = kCGBitmapByteOrder32Little;
  120. {$endc}
  121. { Return the CFTypeID for CGImageRefs. }
  122. function CGImageGetTypeID: CFTypeID; external name '_CGImageGetTypeID'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  123. { Create an image. }
  124. function CGImageCreate( width: size_t; height: size_t; bitsPerComponent: size_t; bitsPerPixel: size_t; bytesPerRow: size_t; colorspace: CGColorSpaceRef; bitmapInfo: CGBitmapInfo; provider: CGDataProviderRef; {const} decode: {variable-size-array} Float32Ptr; shouldInterpolate: CBool; intent: CGColorRenderingIntent ): CGImageRef; external name '_CGImageCreate';
  125. { Create an image mask. }
  126. function CGImageMaskCreate( width: size_t; height: size_t; bitsPerComponent: size_t; bitsPerPixel: size_t; bytesPerRow: size_t; provider: CGDataProviderRef; {const} decode: {variable-size-array} Float32Ptr; shouldInterpolate: CBool ): CGImageRef; external name '_CGImageMaskCreate';
  127. { Return a copy of `image'. Only the image structure itself is copied; the
  128. * underlying data is not. }
  129. function CGImageCreateCopy( image: CGImageRef ): CGImageRef; external name '_CGImageCreateCopy';
  130. { Create an image from `source', a data provider of JPEG-encoded data. }
  131. function CGImageCreateWithJPEGDataProvider( source: CGDataProviderRef; {const} decode: {variable-size-array} Float32Ptr; shouldInterpolate: CBool; intent: CGColorRenderingIntent ): CGImageRef; external name '_CGImageCreateWithJPEGDataProvider'; (* AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER *)
  132. { Create an image using `source', a data provider for PNG-encoded data. }
  133. function CGImageCreateWithPNGDataProvider( source: CGDataProviderRef; {const} decode: {variable-size-array} Float32Ptr; shouldInterpolate: CBool; intent: CGColorRenderingIntent ): CGImageRef; external name '_CGImageCreateWithPNGDataProvider'; (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER *)
  134. { Create an image using the data contained within the subrectangle `rect'
  135. * of `image'.
  136. *
  137. * The new image is created by
  138. * 1) adjusting `rect' to integral bounds by calling "CGRectIntegral";
  139. * 2) intersecting the result with a rectangle with origin (0, 0) and
  140. * size equal to the size of `image';
  141. * 3) referencing the pixels within the resulting rectangle, treating the
  142. * first pixel of the image data as the origin of the image.
  143. * If the resulting rectangle is the null rectangle, this function returns
  144. * NULL.
  145. *
  146. * If W and H are the width and height of image, respectively, then the
  147. * point (0,0) corresponds to the first pixel of the image data; the point
  148. * (W-1, 0) is the last pixel of the first row of the image data; (0, H-1)
  149. * is the first pixel of the last row of the image data; and (W-1, H-1) is
  150. * the last pixel of the last row of the image data.
  151. *
  152. * The resulting image retains a reference to the original image, so you
  153. * may release the original image after calling this function. }
  154. function CGImageCreateWithImageInRect( image: CGImageRef; rect: CGRect ): CGImageRef; external name '_CGImageCreateWithImageInRect'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  155. { Create a new image from `image' masked by `mask', which may be an image
  156. * mask or an image.
  157. *
  158. * If `mask' is an image mask, then it indicates which parts of the context
  159. * are to be painted with the image when drawn in a context, and which are
  160. * to be masked out (left unchanged). The source samples of the image mask
  161. * determine which areas are painted, acting as an "inverse alpha": if the
  162. * value of a source sample in the image mask is S, then the corresponding
  163. * region in `image' is blended with the destination using an alpha of
  164. * (1-S). (For example, if S is 1, then the region is not painted, while
  165. * if S is 0, the region is fully painted.)
  166. *
  167. * If `mask' is an image, then it serves as alpha mask for blending the
  168. * image onto the destination. The source samples of `mask' determine
  169. * which areas are painted: if the value of the source sample in mask is S,
  170. * then the corresponding region in image is blended with the destination
  171. * with an alpha of S. (For example, if S is 0, then the region is not
  172. * painted, while if S is 1, the region is fully painted.)
  173. *
  174. * The parameter `image' may not be an image mask and may not have an image
  175. * mask or masking color associated with it.
  176. *
  177. * If `mask' is an image, then it must be in the DeviceGray color space,
  178. * may not have alpha, and may not itself be masked by an image mask
  179. * or a masking color. }
  180. function CGImageCreateWithMask( image: CGImageRef; mask: CGImageRef ): CGImageRef; external name '_CGImageCreateWithMask'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  181. { Create a new image from `image' masked by `components', an array of 2N
  182. * values ( min[1], max[1], ... min[N], max[N] ) where N is the number of
  183. * components in color space of `image'. Any image sample with color value
  184. * (c[1], ... c[N]) where min[i] <= c[i] <= max[i] for 1 <= i <= N is
  185. * masked out (that is, not painted).
  186. *
  187. * Each value in `components' must be a valid image sample value: if
  188. * `image' has integral pixel components, then each value of must be in the
  189. * range [0 .. 2**bitsPerComponent - 1] (where `bitsPerComponent' is the
  190. * number of bits/component of `image'); if `image' has floating-point
  191. * pixel components, then each value may be any floating-point number which
  192. * is a valid color component.
  193. *
  194. * The parameter `image' may not be an image mask, and may not already have
  195. * an image mask or masking color associated with it. }
  196. function CGImageCreateWithMaskingColors( image: CGImageRef; {const} components: {variable-size-array} Float32Ptr ): CGImageRef; external name '_CGImageCreateWithMaskingColors'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  197. { Create a copy of `image', replacing the image's colorspace with
  198. * `colorspace'. Returns NULL if `image' is an image mask, or if the
  199. * number of components of `colorspace' isn't the same as the number of
  200. * components of the colorspace of `image'. }
  201. function CGImageCreateCopyWithColorSpace( image: CGImageRef; colorspace: CGColorSpaceRef ): CGImageRef; external name '_CGImageCreateCopyWithColorSpace'; (* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
  202. { Equivalent to `CFRetain(image)'. }
  203. function CGImageRetain( image: CGImageRef ): CGImageRef; external name '_CGImageRetain';
  204. { Equivalent to `CFRelease(image)'. }
  205. procedure CGImageRelease( image: CGImageRef ); external name '_CGImageRelease';
  206. { Return true if `image' is an image mask, false otherwise. }
  207. function CGImageIsMask( image: CGImageRef ): CBool; external name '_CGImageIsMask';
  208. { Return the width of `image'. }
  209. function CGImageGetWidth( image: CGImageRef ): size_t; external name '_CGImageGetWidth';
  210. { Return the height of `image'. }
  211. function CGImageGetHeight( image: CGImageRef ): size_t; external name '_CGImageGetHeight';
  212. { Return the number of bits/component of `image'. }
  213. function CGImageGetBitsPerComponent( image: CGImageRef ): size_t; external name '_CGImageGetBitsPerComponent';
  214. { Return the number of bits/pixel of `image'. }
  215. function CGImageGetBitsPerPixel( image: CGImageRef ): size_t; external name '_CGImageGetBitsPerPixel';
  216. { Return the number of bytes/row of `image'. }
  217. function CGImageGetBytesPerRow( image: CGImageRef ): size_t; external name '_CGImageGetBytesPerRow';
  218. { Return the colorspace of `image', or NULL if `image' is an image
  219. * mask. }
  220. function CGImageGetColorSpace( image: CGImageRef ): CGColorSpaceRef; external name '_CGImageGetColorSpace';
  221. { Return the alpha info of `image'. }
  222. function CGImageGetAlphaInfo( image: CGImageRef ): CGImageAlphaInfo; external name '_CGImageGetAlphaInfo';
  223. { Return the data provider of `image'. }
  224. function CGImageGetDataProvider( image: CGImageRef ): CGDataProviderRef; external name '_CGImageGetDataProvider';
  225. { Return the decode array of `image'. }
  226. function CGImageGetDecode( image: CGImageRef ): Float32Ptr; external name '_CGImageGetDecode';
  227. { Return the interpolation parameter of `image'. }
  228. function CGImageGetShouldInterpolate( image: CGImageRef ): CBool; external name '_CGImageGetShouldInterpolate';
  229. { Return the rendering intent of `image'. }
  230. function CGImageGetRenderingIntent( image: CGImageRef ): CGColorRenderingIntent; external name '_CGImageGetRenderingIntent';
  231. { Return the bitmap info of `image'. }
  232. function CGImageGetBitmapInfo( image: CGImageRef ): CGBitmapInfo; external name '_CGImageGetBitmapInfo'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  233. end.