summaryrefslogtreecommitdiff
path: root/doc/public/xml/cairo-image.xml
blob: 9c4688247eb5d00c4e2ffa9b5a7a13772ff9a2bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="cairo-Image-Surfaces">
<refmeta>
<refentrytitle role="top_of_page" id="cairo-Image-Surfaces.top_of_page">Image Surfaces</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>
  CAIRO Library
</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Image Surfaces</refname>
<refpurpose>Rendering to memory buffers</refpurpose>
</refnamediv>

<refsynopsisdiv id="cairo-Image-Surfaces.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>#define             <link linkend="CAIRO-HAS-IMAGE-SURFACE:CAPS">CAIRO_HAS_IMAGE_SURFACE</link>
enum                <link linkend="cairo-format-t">cairo_format_t</link>;
<link linkend="int"><returnvalue>int</returnvalue></link>                 <link linkend="cairo-format-stride-for-width">cairo_format_stride_for_width</link>       (<parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>);
<link linkend="cairo-surface-t"><returnvalue>cairo_surface_t</returnvalue></link> *   <link linkend="cairo-image-surface-create">cairo_image_surface_create</link>          (<parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> height</parameter>);
<link linkend="cairo-surface-t"><returnvalue>cairo_surface_t</returnvalue></link> *   <link linkend="cairo-image-surface-create-for-data">cairo_image_surface_create_for_data</link> (<parameter>unsigned <link linkend="char"><type>char</type></link> *data</parameter>,
                                                         <parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> height</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> stride</parameter>);
unsigned <link linkend="char"><returnvalue>char</returnvalue></link> *     <link linkend="cairo-image-surface-get-data">cairo_image_surface_get_data</link>        (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);
<link linkend="cairo-format-t"><returnvalue>cairo_format_t</returnvalue></link>      <link linkend="cairo-image-surface-get-format">cairo_image_surface_get_format</link>      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);
<link linkend="int"><returnvalue>int</returnvalue></link>                 <link linkend="cairo-image-surface-get-width">cairo_image_surface_get_width</link>       (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);
<link linkend="int"><returnvalue>int</returnvalue></link>                 <link linkend="cairo-image-surface-get-height">cairo_image_surface_get_height</link>      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);
<link linkend="int"><returnvalue>int</returnvalue></link>                 <link linkend="cairo-image-surface-get-stride">cairo_image_surface_get_stride</link>      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);
</synopsis>
</refsynopsisdiv>

<refsect1 id="cairo-Image-Surfaces.description" role="desc">
<title role="desc.title">Description</title>
<para>
Image surfaces provide the ability to render to memory buffers
either allocated by cairo or by the calling code.  The supported
image formats are those defined in <link linkend="cairo-format-t"><type>cairo_format_t</type></link>.
</para>
</refsect1>
<refsect1 id="cairo-Image-Surfaces.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="CAIRO-HAS-IMAGE-SURFACE:CAPS" role="macro">
<title>CAIRO_HAS_IMAGE_SURFACE</title>
<indexterm zone="CAIRO-HAS-IMAGE-SURFACE:CAPS"><primary sortas="HAS_IMAGE_SURFACE">CAIRO_HAS_IMAGE_SURFACE</primary></indexterm>
<programlisting>#define CAIRO_HAS_IMAGE_SURFACE 1
</programlisting>
<para>
Defined if the image surface backend is available.
The image surface backend is always built in.
This macro was added for completeness in cairo 1.8.
</para>
<para>
<parameter>Since</parameter>: 1.8
</para></refsect2>
<refsect2 id="cairo-format-t" role="enum">
<title>enum cairo_format_t</title>
<indexterm zone="cairo-format-t"><primary sortas="format_t">cairo_format_t</primary></indexterm>
<programlisting>typedef enum _cairo_format {
    CAIRO_FORMAT_INVALID   = -1,
    CAIRO_FORMAT_ARGB32    = 0,
    CAIRO_FORMAT_RGB24     = 1,
    CAIRO_FORMAT_A8        = 2,
    CAIRO_FORMAT_A1        = 3,
    CAIRO_FORMAT_RGB16_565 = 4
} cairo_format_t;
</programlisting>
<para>
<link linkend="cairo-format-t"><type>cairo_format_t</type></link> is used to identify the memory format of
image data.
</para>
<para>
New entries may be added in future versions.
</para><variablelist role="enum">
<varlistentry id="CAIRO-FORMAT-INVALID:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_INVALID</literal></term>
<listitem><simpara>no such format exists or is supported.
</simpara></listitem>
</varlistentry>
<varlistentry id="CAIRO-FORMAT-ARGB32:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_ARGB32</literal></term>
<listitem><simpara>each pixel is a 32-bit quantity, with
  alpha in the upper 8 bits, then red, then green, then blue.
  The 32-bit quantities are stored native-endian. Pre-multiplied
  alpha is used. (That is, 50% transparent red is 0x80800000,
  not 0x80ff0000.)
</simpara></listitem>
</varlistentry>
<varlistentry id="CAIRO-FORMAT-RGB24:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_RGB24</literal></term>
<listitem><simpara>each pixel is a 32-bit quantity, with
  the upper 8 bits unused. Red, Green, and Blue are stored
  in the remaining 24 bits in that order.
</simpara></listitem>
</varlistentry>
<varlistentry id="CAIRO-FORMAT-A8:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_A8</literal></term>
<listitem><simpara>each pixel is a 8-bit quantity holding
  an alpha value.
</simpara></listitem>
</varlistentry>
<varlistentry id="CAIRO-FORMAT-A1:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_A1</literal></term>
<listitem><simpara>each pixel is a 1-bit quantity holding
  an alpha value. Pixels are packed together into 32-bit
  quantities. The ordering of the bits matches the
  endianess of the platform. On a big-endian machine, the
  first pixel is in the uppermost bit, on a little-endian
  machine the first pixel is in the least-significant bit.
</simpara></listitem>
</varlistentry>
<varlistentry id="CAIRO-FORMAT-RGB16-565:CAPS" role="constant">
<term><literal>CAIRO_FORMAT_RGB16_565</literal></term>
<listitem><simpara>each pixel is a 16-bit quantity
  with red in the upper 5 bits, then green in the middle
  6 bits, and blue in the lower 5 bits.
</simpara></listitem>
</varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-format-stride-for-width" role="function" condition="since:1.6">
<title>cairo_format_stride_for_width ()</title>
<indexterm zone="cairo-format-stride-for-width" role="1.6"><primary sortas="format_stride_for_width">cairo_format_stride_for_width</primary></indexterm>
<programlisting><link linkend="int"><returnvalue>int</returnvalue></link>                 cairo_format_stride_for_width       (<parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>);</programlisting>
<para>
This function provides a stride value that will respect all
alignment requirements of the accelerated image-rendering code
within cairo. Typical usage will be of the form:
</para>
<para>
<informalexample><programlisting>
int stride;
unsigned char *data;
<link linkend="cairo-surface-t">cairo_surface_t</link> *surface;

stride = cairo_format_stride_for_width (format, width);
data = malloc (stride * height);
surface = cairo_image_surface_create_for_data (data, format,
					  width, height,
					  stride);
</programlisting></informalexample>
</para><variablelist role="params">
<varlistentry><term><parameter>format</parameter>&#160;:</term>
<listitem><simpara>A <link linkend="cairo-format-t"><type>cairo_format_t</type></link> value
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>width</parameter>&#160;:</term>
<listitem><simpara>The desired width of an image surface to be created.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the appropriate stride to use given the desired
format and width, or -1 if either the format is invalid or the width
too large.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 1.6</para></refsect2>
<refsect2 id="cairo-image-surface-create" role="function">
<title>cairo_image_surface_create ()</title>
<indexterm zone="cairo-image-surface-create"><primary sortas="image_surface_create">cairo_image_surface_create</primary></indexterm>
<programlisting><link linkend="cairo-surface-t"><returnvalue>cairo_surface_t</returnvalue></link> *   cairo_image_surface_create          (<parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> height</parameter>);</programlisting>
<para>
Creates an image surface of the specified format and
dimensions. Initially the surface contents are all
0. (Specifically, within each pixel, each color or alpha channel
belonging to format will be 0. The contents of bits within a pixel,
but not belonging to the given format are undefined).
</para><variablelist role="params">
<varlistentry><term><parameter>format</parameter>&#160;:</term>
<listitem><simpara>format of pixels in the surface to create
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>width</parameter>&#160;:</term>
<listitem><simpara>width of the surface, in pixels
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>height</parameter>&#160;:</term>
<listitem><simpara>height of the surface, in pixels
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a pointer to the newly created surface. The caller
owns the surface and should call <link linkend="cairo-surface-destroy"><function>cairo_surface_destroy()</function></link> when done
with it.

This function always returns a valid pointer, but it will return a
pointer to a "nil" surface if an error such as out of memory
occurs. You can use <link linkend="cairo-surface-status"><function>cairo_surface_status()</function></link> to check for this.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-image-surface-create-for-data" role="function">
<title>cairo_image_surface_create_for_data ()</title>
<indexterm zone="cairo-image-surface-create-for-data"><primary sortas="image_surface_create_for_data">cairo_image_surface_create_for_data</primary></indexterm>
<programlisting><link linkend="cairo-surface-t"><returnvalue>cairo_surface_t</returnvalue></link> *   cairo_image_surface_create_for_data (<parameter>unsigned <link linkend="char"><type>char</type></link> *data</parameter>,
                                                         <parameter><link linkend="cairo-format-t"><type>cairo_format_t</type></link> format</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> width</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> height</parameter>,
                                                         <parameter><link linkend="int"><type>int</type></link> stride</parameter>);</programlisting>
<para>
Creates an image surface for the provided pixel data. The output
buffer must be kept around until the <link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> is destroyed
or <link linkend="cairo-surface-finish"><function>cairo_surface_finish()</function></link> is called on the surface.  The initial
contents of <parameter>data</parameter> will be used as the initial image contents; you
must explicitly clear the buffer, using, for example,
<link linkend="cairo-rectangle"><function>cairo_rectangle()</function></link> and <link linkend="cairo-fill"><function>cairo_fill()</function></link> if you want it cleared.
</para>
<para>
Note that the stride may be larger than
width*bytes_per_pixel to provide proper alignment for each pixel
and row. This alignment is required to allow high-performance rendering
within cairo. The correct way to obtain a legal stride value is to
call <link linkend="cairo-format-stride-for-width"><function>cairo_format_stride_for_width()</function></link> with the desired format and
maximum image width value, and then use the resulting stride value
to allocate the data and to create the image surface. See
<link linkend="cairo-format-stride-for-width"><function>cairo_format_stride_for_width()</function></link> for example code.
</para><variablelist role="params">
<varlistentry><term><parameter>data</parameter>&#160;:</term>
<listitem><simpara>a pointer to a buffer supplied by the application in which
    to write contents. This pointer must be suitably aligned for any
    kind of variable, (for example, a pointer returned by malloc).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>format</parameter>&#160;:</term>
<listitem><simpara>the format of pixels in the buffer
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>width</parameter>&#160;:</term>
<listitem><simpara>the width of the image to be stored in the buffer
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>height</parameter>&#160;:</term>
<listitem><simpara>the height of the image to be stored in the buffer
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>stride</parameter>&#160;:</term>
<listitem><simpara>the number of bytes between the start of rows in the
    buffer as allocated. This value should always be computed by
    <link linkend="cairo-format-stride-for-width"><function>cairo_format_stride_for_width()</function></link> before allocating the data
    buffer.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a pointer to the newly created surface. The caller
owns the surface and should call <link linkend="cairo-surface-destroy"><function>cairo_surface_destroy()</function></link> when done
with it.

This function always returns a valid pointer, but it will return a
pointer to a "nil" surface in the case of an error such as out of
memory or an invalid stride value. In case of invalid stride value
the error status of the returned surface will be
<link linkend="CAIRO-STATUS-INVALID-STRIDE:CAPS"><literal>CAIRO_STATUS_INVALID_STRIDE</literal></link>.  You can use
<link linkend="cairo-surface-status"><function>cairo_surface_status()</function></link> to check for this.

See <link linkend="cairo-surface-set-user-data"><function>cairo_surface_set_user_data()</function></link> for a means of attaching a
destroy-notification fallback to the surface if necessary.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-image-surface-get-data" role="function" condition="since:1.2">
<title>cairo_image_surface_get_data ()</title>
<indexterm zone="cairo-image-surface-get-data" role="1.2"><primary sortas="image_surface_get_data">cairo_image_surface_get_data</primary></indexterm>
<programlisting>unsigned <link linkend="char"><returnvalue>char</returnvalue></link> *     cairo_image_surface_get_data        (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);</programlisting>
<para>
Get a pointer to the data of the image surface, for direct
inspection or modification.
</para><variablelist role="params">
<varlistentry><term><parameter>surface</parameter>&#160;:</term>
<listitem><simpara>a <link linkend="cairo-image-surface-t"><type>cairo_image_surface_t</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a pointer to the image data of this surface or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
if <parameter>surface</parameter> is not an image surface, or if <link linkend="cairo-surface-finish"><function>cairo_surface_finish()</function></link>
has been called.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 1.2</para></refsect2>
<refsect2 id="cairo-image-surface-get-format" role="function" condition="since:1.2">
<title>cairo_image_surface_get_format ()</title>
<indexterm zone="cairo-image-surface-get-format" role="1.2"><primary sortas="image_surface_get_format">cairo_image_surface_get_format</primary></indexterm>
<programlisting><link linkend="cairo-format-t"><returnvalue>cairo_format_t</returnvalue></link>      cairo_image_surface_get_format      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);</programlisting>
<para>
Get the format of the surface.
</para><variablelist role="params">
<varlistentry><term><parameter>surface</parameter>&#160;:</term>
<listitem><simpara>a <link linkend="cairo-image-surface-t"><type>cairo_image_surface_t</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the format of the surface

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 1.2</para></refsect2>
<refsect2 id="cairo-image-surface-get-width" role="function">
<title>cairo_image_surface_get_width ()</title>
<indexterm zone="cairo-image-surface-get-width"><primary sortas="image_surface_get_width">cairo_image_surface_get_width</primary></indexterm>
<programlisting><link linkend="int"><returnvalue>int</returnvalue></link>                 cairo_image_surface_get_width       (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);</programlisting>
<para>
Get the width of the image surface in pixels.
</para><variablelist role="params">
<varlistentry><term><parameter>surface</parameter>&#160;:</term>
<listitem><simpara>a <link linkend="cairo-image-surface-t"><type>cairo_image_surface_t</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the width of the surface in pixels.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-image-surface-get-height" role="function">
<title>cairo_image_surface_get_height ()</title>
<indexterm zone="cairo-image-surface-get-height"><primary sortas="image_surface_get_height">cairo_image_surface_get_height</primary></indexterm>
<programlisting><link linkend="int"><returnvalue>int</returnvalue></link>                 cairo_image_surface_get_height      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);</programlisting>
<para>
Get the height of the image surface in pixels.
</para><variablelist role="params">
<varlistentry><term><parameter>surface</parameter>&#160;:</term>
<listitem><simpara>a <link linkend="cairo-image-surface-t"><type>cairo_image_surface_t</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the height of the surface in pixels.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="cairo-image-surface-get-stride" role="function" condition="since:1.2">
<title>cairo_image_surface_get_stride ()</title>
<indexterm zone="cairo-image-surface-get-stride" role="1.2"><primary sortas="image_surface_get_stride">cairo_image_surface_get_stride</primary></indexterm>
<programlisting><link linkend="int"><returnvalue>int</returnvalue></link>                 cairo_image_surface_get_stride      (<parameter><link linkend="cairo-surface-t"><type>cairo_surface_t</type></link> *surface</parameter>);</programlisting>
<para>
Get the stride of the image surface in bytes
</para><variablelist role="params">
<varlistentry><term><parameter>surface</parameter>&#160;:</term>
<listitem><simpara>a <link linkend="cairo-image-surface-t"><type>cairo_image_surface_t</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the stride of the image surface in bytes (or 0 if
<parameter>surface</parameter> is not an image surface). The stride is the distance in
bytes from the beginning of one row of the image data to the
beginning of the next row.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 1.2</para></refsect2>

</refsect1>
<refsect1 id="cairo-Image-Surfaces.see-also">
<title>See Also</title>
<link linkend="cairo-surface-t"><type>cairo_surface_t</type></link>
</refsect1>

</refentry>