1 { CoreGraphics - CGBitmapContext.h
2    Copyright (c) 2000-2011 Apple Inc.
3    All rights reserved. }
4 {       Pascal Translation Updated:  Jonas Maebe, <jonas@freepascal.org>, October 2009 }
5 {       Pascal Translation Updated:  Jonas Maebe, <jonas@freepascal.org>, October 2012 }
6 {       Pascal Translation Updated:  Jonas Maebe, <jonas@freepascal.org>, August 2015 }
7 {
8     Modified for use with Free Pascal
9     Version 308
10     Please report any bugs to <gpc@microbizz.nl>
11 }
12 
13 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
14 {$mode macpas}
15 {$modeswitch cblocks}
16 {$packenum 1}
17 {$macro on}
18 {$inline on}
19 {$calling mwpascal}
20 
21 unit CGBitmapContext;
22 interface
23 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
24 {$setc GAP_INTERFACES_VERSION := $0308}
25 
26 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
27     {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
28 {$endc}
29 
30 {$ifc defined CPUPOWERPC and defined CPUI386}
31 	{$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
32 {$endc}
33 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
34 	{$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
35 {$endc}
36 
37 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
38 	{$setc __ppc__ := 1}
39 {$elsec}
40 	{$setc __ppc__ := 0}
41 {$endc}
42 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
43 	{$setc __ppc64__ := 1}
44 {$elsec}
45 	{$setc __ppc64__ := 0}
46 {$endc}
47 {$ifc not defined __i386__ and defined CPUI386}
48 	{$setc __i386__ := 1}
49 {$elsec}
50 	{$setc __i386__ := 0}
51 {$endc}
52 {$ifc not defined __x86_64__ and defined CPUX86_64}
53 	{$setc __x86_64__ := 1}
54 {$elsec}
55 	{$setc __x86_64__ := 0}
56 {$endc}
57 {$ifc not defined __arm__ and defined CPUARM}
58 	{$setc __arm__ := 1}
59 {$elsec}
60 	{$setc __arm__ := 0}
61 {$endc}
62 {$ifc not defined __arm64__ and defined CPUAARCH64}
63   {$setc __arm64__ := 1}
64 {$elsec}
65   {$setc __arm64__ := 0}
66 {$endc}
67 
68 {$ifc defined cpu64}
69   {$setc __LP64__ := 1}
70 {$elsec}
71   {$setc __LP64__ := 0}
72 {$endc}
73 
74 
75 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
76 	{$error Conflicting definitions for __ppc__ and __i386__}
77 {$endc}
78 
79 {$ifc defined __ppc__ and __ppc__}
80 	{$setc TARGET_CPU_PPC := TRUE}
81 	{$setc TARGET_CPU_PPC64 := FALSE}
82 	{$setc TARGET_CPU_X86 := FALSE}
83 	{$setc TARGET_CPU_X86_64 := FALSE}
84 	{$setc TARGET_CPU_ARM := FALSE}
85 	{$setc TARGET_CPU_ARM64 := FALSE}
86 	{$setc TARGET_OS_MAC := TRUE}
87 	{$setc TARGET_OS_IPHONE := FALSE}
88 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
89 	{$setc TARGET_OS_EMBEDDED := FALSE}
90 {$elifc defined __ppc64__ and __ppc64__}
91 	{$setc TARGET_CPU_PPC := FALSE}
92 	{$setc TARGET_CPU_PPC64 := TRUE}
93 	{$setc TARGET_CPU_X86 := FALSE}
94 	{$setc TARGET_CPU_X86_64 := FALSE}
95 	{$setc TARGET_CPU_ARM := FALSE}
96 	{$setc TARGET_CPU_ARM64 := FALSE}
97 	{$setc TARGET_OS_MAC := TRUE}
98 	{$setc TARGET_OS_IPHONE := FALSE}
99 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
100 	{$setc TARGET_OS_EMBEDDED := FALSE}
101 {$elifc defined __i386__ and __i386__}
102 	{$setc TARGET_CPU_PPC := FALSE}
103 	{$setc TARGET_CPU_PPC64 := FALSE}
104 	{$setc TARGET_CPU_X86 := TRUE}
105 	{$setc TARGET_CPU_X86_64 := FALSE}
106 	{$setc TARGET_CPU_ARM := FALSE}
107 	{$setc TARGET_CPU_ARM64 := FALSE}
108 {$ifc defined iphonesim}
109  	{$setc TARGET_OS_MAC := FALSE}
110 	{$setc TARGET_OS_IPHONE := TRUE}
111 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
112 {$elsec}
113 	{$setc TARGET_OS_MAC := TRUE}
114 	{$setc TARGET_OS_IPHONE := FALSE}
115 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
116 {$endc}
117 	{$setc TARGET_OS_EMBEDDED := FALSE}
118 {$elifc defined __x86_64__ and __x86_64__}
119 	{$setc TARGET_CPU_PPC := FALSE}
120 	{$setc TARGET_CPU_PPC64 := FALSE}
121 	{$setc TARGET_CPU_X86 := FALSE}
122 	{$setc TARGET_CPU_X86_64 := TRUE}
123 	{$setc TARGET_CPU_ARM := FALSE}
124 	{$setc TARGET_CPU_ARM64 := FALSE}
125 {$ifc defined iphonesim}
126  	{$setc TARGET_OS_MAC := FALSE}
127 	{$setc TARGET_OS_IPHONE := TRUE}
128 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
129 {$elsec}
130 	{$setc TARGET_OS_MAC := TRUE}
131 	{$setc TARGET_OS_IPHONE := FALSE}
132 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
133 {$endc}
134 	{$setc TARGET_OS_EMBEDDED := FALSE}
135 {$elifc defined __arm__ and __arm__}
136 	{$setc TARGET_CPU_PPC := FALSE}
137 	{$setc TARGET_CPU_PPC64 := FALSE}
138 	{$setc TARGET_CPU_X86 := FALSE}
139 	{$setc TARGET_CPU_X86_64 := FALSE}
140 	{$setc TARGET_CPU_ARM := TRUE}
141 	{$setc TARGET_CPU_ARM64 := FALSE}
142 	{$setc TARGET_OS_MAC := FALSE}
143 	{$setc TARGET_OS_IPHONE := TRUE}
144 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
145 	{$setc TARGET_OS_EMBEDDED := TRUE}
146 {$elifc defined __arm64__ and __arm64__}
147 	{$setc TARGET_CPU_PPC := FALSE}
148 	{$setc TARGET_CPU_PPC64 := FALSE}
149 	{$setc TARGET_CPU_X86 := FALSE}
150 	{$setc TARGET_CPU_X86_64 := FALSE}
151 	{$setc TARGET_CPU_ARM := FALSE}
152 	{$setc TARGET_CPU_ARM64 := TRUE}
153 {$ifc defined ios}
154 	{$setc TARGET_OS_MAC := FALSE}
155 	{$setc TARGET_OS_IPHONE := TRUE}
156 	{$setc TARGET_OS_EMBEDDED := TRUE}
157 {$elsec}
158 	{$setc TARGET_OS_MAC := TRUE}
159 	{$setc TARGET_OS_IPHONE := FALSE}
160 	{$setc TARGET_OS_EMBEDDED := FALSE}
161 {$endc}
162 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
163 {$elsec}
164 	{$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
165 {$endc}
166 
167 {$ifc defined __LP64__ and __LP64__ }
168   {$setc TARGET_CPU_64 := TRUE}
169 {$elsec}
170   {$setc TARGET_CPU_64 := FALSE}
171 {$endc}
172 
173 {$ifc defined FPC_BIG_ENDIAN}
174 	{$setc TARGET_RT_BIG_ENDIAN := TRUE}
175 	{$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
176 {$elifc defined FPC_LITTLE_ENDIAN}
177 	{$setc TARGET_RT_BIG_ENDIAN := FALSE}
178 	{$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
179 {$elsec}
180 	{$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
181 {$endc}
182 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
183 {$setc CALL_NOT_IN_CARBON := FALSE}
184 {$setc OLDROUTINENAMES := FALSE}
185 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
186 {$setc OPAQUE_UPP_TYPES := TRUE}
187 {$setc OTCARBONAPPLICATION := TRUE}
188 {$setc OTKERNEL := FALSE}
189 {$setc PM_USE_SESSION_APIS := TRUE}
190 {$setc TARGET_API_MAC_CARBON := TRUE}
191 {$setc TARGET_API_MAC_OS8 := FALSE}
192 {$setc TARGET_API_MAC_OSX := TRUE}
193 {$setc TARGET_CARBON := TRUE}
194 {$setc TARGET_CPU_68K := FALSE}
195 {$setc TARGET_CPU_MIPS := FALSE}
196 {$setc TARGET_CPU_SPARC := FALSE}
197 {$setc TARGET_OS_UNIX := FALSE}
198 {$setc TARGET_OS_WIN32 := FALSE}
199 {$setc TARGET_RT_MAC_68881 := FALSE}
200 {$setc TARGET_RT_MAC_CFM := FALSE}
201 {$setc TARGET_RT_MAC_MACHO := TRUE}
202 {$setc TYPED_FUNCTION_POINTERS := TRUE}
203 {$setc TYPE_BOOL := FALSE}
204 {$setc TYPE_EXTENDED := FALSE}
205 {$setc TYPE_LONGLONG := TRUE}
206 uses MacTypes,CGColorSpace,CGImage,CGBase,CGContext;
207 {$endc} {not MACOSALLINCLUDE}
208 
209 {$ALIGN POWER}
210 
211 
212 { The callback for releasing the data supplied to
213    `CGBitmapContextCreateWithData'. }
214 
215 type
216 	CGBitmapContextReleaseDataCallback = procedure( releaseInfo: UnivPtr; data: UnivPtr );
217 
218 { Create a bitmap context. The context draws into a bitmap which is `width'
219    pixels wide and `height' pixels high. The number of components for each
220    pixel is specified by `space', which may also specify a destination color
221    profile. The number of bits for each component of a pixel is specified by
222    `bitsPerComponent'. The number of bytes per pixel is equal to
223    `(bitsPerComponent * number of components + 7)/8'. Each row of the bitmap
224    consists of `bytesPerRow' bytes, which must be at least `width * bytes
225    per pixel' bytes; in addition, `bytesPerRow' must be an integer multiple
226    of the number of bytes per pixel. `data', if non-NULL, points to a block
227    of memory at least `bytesPerRow * height' bytes. If `data' is NULL, the
228    context will allocate the data itself; this data will be freed when the
229    context is deallocated. `bitmapInfo' specifies whether the bitmap should
230    contain an alpha channel and how it's to be generated, along with whether
231    the components are floating-point or integer. If `releaseCallback' is
232    non-NULL, it is called when the context is freed with `releaseInfo' and
233    `data' as arguments. }
234 
CGBitmapContextCreateWithDatanull235 function CGBitmapContextCreateWithData( data: univPtr; width: size_t; height: size_t; bitsPerComponent: size_t; bytesPerRow: size_t; colorspace: CGColorSpaceRef; bitmapInfo: CGBitmapInfo; releaseCallback: CGBitmapContextReleaseDataCallback; releaseInfo: UnivPtr ): CGContextRef; external name '_CGBitmapContextCreateWithData';
236 (* CG_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_4_0) *)
237 
238 { Create a bitmap context. The context draws into a bitmap which is `width'
239    pixels wide and `height' pixels high. The number of components for each
240    pixel is specified by `space', which may also specify a destination color
241    profile. The number of bits for each component of a pixel is specified by
242    `bitsPerComponent'. The number of bytes per pixel is equal to
243    `(bitsPerComponent * number of components + 7)/8'. Each row of the bitmap
244    consists of `bytesPerRow' bytes, which must be at least `width * bytes
245    per pixel' bytes; in addition, `bytesPerRow' must be an integer multiple
246    of the number of bytes per pixel. `data', if non-NULL, points to a block
247    of memory at least `bytesPerRow * height' bytes. If `data' is NULL, the
248    data for context is allocated automatically and freed when the context is
249    deallocated. `bitmapInfo' specifies whether the bitmap should contain an
250    alpha channel and how it's to be generated, along with whether the
251    components are floating-point or integer. }
252 
CGBitmapContextCreatenull253 function CGBitmapContextCreate( data: UnivPtr; width: size_t; height: size_t; bitsPerComponent: size_t; bytesPerRow: size_t; colorspace: CGColorSpaceRef; bitmapInfo: CGBitmapInfo ): CGContextRef; external name '_CGBitmapContextCreate';
254 (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
255 
256 { Return the data associated with the bitmap context `context', or NULL if
257    `context' is not a bitmap context. }
258 
CGBitmapContextGetDatanull259 function CGBitmapContextGetData( context: CGContextRef ): UnivPtr; external name '_CGBitmapContextGetData';
260 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
261 
262 { Return the width of the bitmap context `context', or 0 if `context' is
263    not a bitmap context. }
264 
CGBitmapContextGetWidthnull265 function CGBitmapContextGetWidth( context: CGContextRef ): size_t; external name '_CGBitmapContextGetWidth';
266 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
267 
268 { Return the height of the bitmap context `context', or 0 if `context' is
269    not a bitmap context. }
270 
CGBitmapContextGetHeightnull271 function CGBitmapContextGetHeight( context: CGContextRef ): size_t; external name '_CGBitmapContextGetHeight';
272 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
273 
274 { Return the bits per component of the bitmap context `context', or 0 if
275    `context' is not a bitmap context. }
276 
CGBitmapContextGetBitsPerComponentnull277 function CGBitmapContextGetBitsPerComponent( context: CGContextRef ): size_t; external name '_CGBitmapContextGetBitsPerComponent';
278 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
279 
280 { Return the bits per pixel of the bitmap context `context', or 0 if
281    `context' is not a bitmap context. }
282 
CGBitmapContextGetBitsPerPixelnull283 function CGBitmapContextGetBitsPerPixel( context: CGContextRef ): size_t; external name '_CGBitmapContextGetBitsPerPixel';
284 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
285 
286 { Return the bytes per row of the bitmap context `context', or 0 if
287    `context' is not a bitmap context. }
288 
CGBitmapContextGetBytesPerRownull289 function CGBitmapContextGetBytesPerRow( context: CGContextRef ): size_t; external name '_CGBitmapContextGetBytesPerRow';
290 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
291 
292 { Return the color space of the bitmap context `context', or NULL if
293    `context' is not a bitmap context. }
294 
CGBitmapContextGetColorSpacenull295 function CGBitmapContextGetColorSpace( context: CGContextRef ): CGColorSpaceRef; external name '_CGBitmapContextGetColorSpace';
296 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
297 
298 { Return the alpha info of the bitmap context `context', or
299    "kCGImageAlphaNone" if `context' is not a bitmap context. }
300 
CGBitmapContextGetAlphaInfonull301 function CGBitmapContextGetAlphaInfo( context: CGContextRef ): CGImageAlphaInfo; external name '_CGBitmapContextGetAlphaInfo';
302 (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
303 
304 { Return the bitmap info of the bitmap context `context', or 0 if `context'
305    is not a bitmap context. }
306 
CGBitmapContextGetBitmapInfonull307 function CGBitmapContextGetBitmapInfo( context: CGContextRef ): CGBitmapInfo; external name '_CGBitmapContextGetBitmapInfo';
308 (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0) *)
309 
310 { Return an image containing a snapshot of the bitmap context `context'. If
311    context is not a bitmap context, or if the image cannot be created for
312    any reason, this function returns NULL. This is a "copy" operation ---
313    subsequent changes to context will not affect the contents of the
314    returned image.
315 
316    Note that in some cases the copy will actually follow "copy-on-write"
317    semantics, so that the actual physical copy of the bits will only occur
318    if the underlying data in the bitmap context is modified. As a
319    consequence, you may wish to use the resulting image and release it
320    before performing more drawing into the bitmap context; in this way, the
321    actual physical copy of the data may be avoided. }
322 
CGBitmapContextCreateImagenull323 function CGBitmapContextCreateImage( context: CGContextRef ): CGImageRef; external name '_CGBitmapContextCreateImage';
324 (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0) *)
325 
326 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
327 
328 end.
329 {$endc} {not MACOSALLINCLUDE}
330