1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5 * Copyright (C) 2007 Sven Neumann <sven@gimp.org>
6 * 2010-2012 Michael Natterer <mitch@gimp.org>
8 * This library is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 3 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see
20 * <https://www.gnu.org/licenses/>.
23 #ifndef __GIMP_CAIRO_H__
24 #define __GIMP_CAIRO_H__
27 void gimp_cairo_set_source_rgb (cairo_t
*cr
,
28 const GimpRGB
*color
);
29 void gimp_cairo_set_source_rgba (cairo_t
*cr
,
30 const GimpRGB
*color
);
32 cairo_pattern_t
* gimp_cairo_checkerboard_create (cairo_t
*cr
,
37 const Babl
* gimp_cairo_surface_get_format (cairo_surface_t
*surface
);
38 GeglBuffer
* gimp_cairo_surface_create_buffer (cairo_surface_t
*surface
);
41 /* some useful macros for writing directly to a Cairo surface */
44 * GIMP_CAIRO_RGB24_SET_PIXEL:
45 * @d: pointer to the destination buffer
50 * Sets a single pixel in an Cairo image surface in %CAIRO_FORMAT_RGB24.
54 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
55 #define GIMP_CAIRO_RGB24_SET_PIXEL(d, r, g, b) \
56 G_STMT_START { d[0] = (b); d[1] = (g); d[2] = (r); } G_STMT_END
58 #define GIMP_CAIRO_RGB24_SET_PIXEL(d, r, g, b) \
59 G_STMT_START { d[1] = (r); d[2] = (g); d[3] = (b); } G_STMT_END
64 * GIMP_CAIRO_RGB24_GET_PIXEL:
65 * @s: pointer to the source buffer
70 * Gets a single pixel from a Cairo image surface in %CAIRO_FORMAT_RGB24.
74 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
75 #define GIMP_CAIRO_RGB24_GET_PIXEL(s, r, g, b) \
76 G_STMT_START { (b) = s[0]; (g) = s[1]; (r) = s[2]; } G_STMT_END
78 #define GIMP_CAIRO_RGB24_GET_PIXEL(s, r, g, b) \
79 G_STMT_START { (r) = s[1]; (g) = s[2]; (b) = s[3]; } G_STMT_END
84 * GIMP_CAIRO_ARGB32_SET_PIXEL:
85 * @d: pointer to the destination buffer
86 * @r: red component, not pre-multiplied
87 * @g: green component, not pre-multiplied
88 * @b: blue component, not pre-multiplied
91 * Sets a single pixel in an Cairo image surface in %CAIRO_FORMAT_ARGB32.
95 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
96 #define GIMP_CAIRO_ARGB32_SET_PIXEL(d, r, g, b, a) \
98 const guint tr = (a) * (r) + 0x80; \
99 const guint tg = (a) * (g) + 0x80; \
100 const guint tb = (a) * (b) + 0x80; \
101 (d)[0] = (((tb) >> 8) + (tb)) >> 8; \
102 (d)[1] = (((tg) >> 8) + (tg)) >> 8; \
103 (d)[2] = (((tr) >> 8) + (tr)) >> 8; \
107 #define GIMP_CAIRO_ARGB32_SET_PIXEL(d, r, g, b, a) \
109 const guint tr = (a) * (r) + 0x80; \
110 const guint tg = (a) * (g) + 0x80; \
111 const guint tb = (a) * (b) + 0x80; \
113 (d)[1] = (((tr) >> 8) + (tr)) >> 8; \
114 (d)[2] = (((tg) >> 8) + (tg)) >> 8; \
115 (d)[3] = (((tb) >> 8) + (tb)) >> 8; \
121 * GIMP_CAIRO_ARGB32_GET_PIXEL:
122 * @s: pointer to the source buffer
123 * @r: red component, not pre-multiplied
124 * @g: green component, not pre-multiplied
125 * @b: blue component, not pre-multiplied
126 * @a: alpha component
128 * Gets a single pixel from a Cairo image surface in %CAIRO_FORMAT_ARGB32.
132 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
133 #define GIMP_CAIRO_ARGB32_GET_PIXEL(s, r, g, b, a) \
135 const guint tb = (s)[0]; \
136 const guint tg = (s)[1]; \
137 const guint tr = (s)[2]; \
138 const guint ta = (s)[3]; \
139 (r) = (tr << 8) / (ta + 1); \
140 (g) = (tg << 8) / (ta + 1); \
141 (b) = (tb << 8) / (ta + 1); \
145 #define GIMP_CAIRO_ARGB32_GET_PIXEL(s, r, g, b, a) \
147 const guint ta = (s)[0]; \
148 const guint tr = (s)[1]; \
149 const guint tg = (s)[2]; \
150 const guint tb = (s)[3]; \
151 (r) = (tr << 8) / (ta + 1); \
152 (g) = (tg << 8) / (ta + 1); \
153 (b) = (tb << 8) / (ta + 1); \
159 #endif /* __GIMP_CAIRO_H__ */