CGImage.pas 12 KB

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