]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf.h
a61dc9366046ed737bfd0465f7b88834718c8c12
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf.h
1 /* GdkPixbuf library - Main header file
2  *
3  * Copyright (C) 1999 The Free Software Foundation
4  *
5  * Authors: Mark Crichton <crichton@gimp.org>
6  *          Miguel de Icaza <miguel@gnu.org>
7  *          Federico Mena-Quintero <federico@gimp.org>
8  *          Havoc Pennington <hp@redhat.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #ifndef GDK_PIXBUF_H
27 #define GDK_PIXBUF_H
28
29 #include <glib.h>
30 #include <gdk-pixbuf/gdk-pixbuf-features.h>
31 #include <gobject/gobject.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 \f
38
39 /* Alpha compositing mode */
40 typedef enum
41 {
42   GDK_PIXBUF_ALPHA_BILEVEL,
43   GDK_PIXBUF_ALPHA_FULL
44 } GdkPixbufAlphaMode;
45
46 /* Color spaces; right now only RGB is supported.
47  * Note that these values are encoded in inline pixbufs
48  * as ints, so don't reorder them
49  */
50 typedef enum {
51         GDK_COLORSPACE_RGB
52 } GdkColorspace;
53
54 /* All of these are opaque structures */
55 typedef struct _GdkPixbuf GdkPixbuf;
56 typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
57 typedef struct _GdkPixbufFrame GdkPixbufFrame;
58
59 #define GDK_TYPE_PIXBUF              (gdk_pixbuf_get_type ())
60 #define GDK_PIXBUF(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF, GdkPixbuf))
61 #define GDK_IS_PIXBUF(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF))
62
63 #define GDK_TYPE_PIXBUF_ANIMATION              (gdk_pixbuf_animation_get_type ())
64 #define GDK_PIXBUF_ANIMATION(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimation))
65 #define GDK_IS_PIXBUF_ANIMATION(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION))
66
67
68 /* Handler that must free the pixel array */
69 typedef void (* GdkPixbufDestroyNotify) (guchar *pixels, gpointer data);
70
71 #define GDK_PIXBUF_ERROR gdk_pixbuf_error_quark ()
72
73 typedef enum {
74         /* some kind of failure reading or writing files */
75         GDK_PIXBUF_ERROR_IO,
76         /* bad option value passed to save routine */
77         GDK_PIXBUF_ERROR_BAD_OPTION_VALUE,
78         /* unsupported image type (sort of an ENOSYS) */
79         GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
80         GDK_PIXBUF_ERROR_FAILED
81 } GdkPixbufErrorType;
82
83 GQuark gdk_pixbuf_error_quark () G_GNUC_CONST;
84
85 \f
86
87 GType gdk_pixbuf_get_type (void) G_GNUC_CONST;
88
89 /* Reference counting */
90
91 GdkPixbuf *gdk_pixbuf_ref      (GdkPixbuf *pixbuf);
92 void       gdk_pixbuf_unref    (GdkPixbuf *pixbuf);
93
94 /* GdkPixbuf accessors */
95
96 GdkColorspace gdk_pixbuf_get_colorspace      (const GdkPixbuf *pixbuf);
97 int           gdk_pixbuf_get_n_channels      (const GdkPixbuf *pixbuf);
98 gboolean      gdk_pixbuf_get_has_alpha       (const GdkPixbuf *pixbuf);
99 int           gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf);
100 guchar       *gdk_pixbuf_get_pixels          (const GdkPixbuf *pixbuf);
101 int           gdk_pixbuf_get_width           (const GdkPixbuf *pixbuf);
102 int           gdk_pixbuf_get_height          (const GdkPixbuf *pixbuf);
103 int           gdk_pixbuf_get_rowstride       (const GdkPixbuf *pixbuf);
104
105 \f
106
107 /* Create a blank pixbuf with an optimal rowstride and a new buffer */
108 GdkPixbuf *gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample,
109                            int width, int height);
110
111 /* Copy a pixbuf */
112
113 GdkPixbuf *gdk_pixbuf_copy (const GdkPixbuf *pixbuf);
114
115 /* Simple loading */
116
117 GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename);
118
119 GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data,
120                                      GdkColorspace colorspace,
121                                      gboolean has_alpha,
122                                      int bits_per_sample,
123                                      int width, int height,
124                                      int rowstride,
125                                      GdkPixbufDestroyNotify destroy_fn,
126                                      gpointer destroy_fn_data);
127
128 GdkPixbuf *gdk_pixbuf_new_from_xpm_data (const char **data);
129
130 /* Read an inline pixbuf */
131 GdkPixbuf *gdk_pixbuf_new_from_inline   (const guchar *inline_pixbuf,
132                                          gboolean      copy_pixels,
133                                          int           length);
134
135
136 /* Saving */
137
138 gboolean gdk_pixbuf_save           (GdkPixbuf  *pixbuf, 
139                                     const char *filename, 
140                                     const char *format, 
141                                     GError    **err,
142                                     ...);
143
144 gboolean gdk_pixbuf_savev          (GdkPixbuf  *pixbuf, 
145                                     const char *filename, 
146                                     const char *format,
147                                     char      **option_keys,
148                                     char      **option_values,
149                                     GError    **err);
150
151 /* Adding an alpha channel */
152 GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color,
153                                  guchar r, guchar g, guchar b);
154
155 /* Copy an area of a pixbuf onto another one */
156 void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf,
157                            int src_x, int src_y,
158                            int width, int height,
159                            GdkPixbuf *dest_pixbuf,
160                            int dest_x, int dest_y);
161
162 /* Brighten/darken and optionally make it pixelated-looking */
163 void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src,
164                                        GdkPixbuf       *dest,
165                                        gfloat           saturation,
166                                        gboolean         pixelate);
167
168 \f
169
170 /* Rendering to a drawable */
171 \f
172
173 /* Scaling */
174
175 /* Interpolation modes */
176 typedef enum {
177         GDK_INTERP_NEAREST,
178         GDK_INTERP_TILES,
179         GDK_INTERP_BILINEAR,
180         GDK_INTERP_HYPER
181 } GdkInterpType;
182
183 void gdk_pixbuf_scale           (const GdkPixbuf *src,
184                                  GdkPixbuf       *dest,
185                                  int              dest_x,
186                                  int              dest_y,
187                                  int              dest_width,
188                                  int              dest_height,
189                                  double           offset_x,
190                                  double           offset_y,
191                                  double           scale_x,
192                                  double           scale_y,
193                                  GdkInterpType    interp_type);
194 void gdk_pixbuf_composite       (const GdkPixbuf *src,
195                                  GdkPixbuf       *dest,
196                                  int              dest_x,
197                                  int              dest_y,
198                                  int              dest_width,
199                                  int              dest_height,
200                                  double           offset_x,
201                                  double           offset_y,
202                                  double           scale_x,
203                                  double           scale_y,
204                                  GdkInterpType    interp_type,
205                                  int              overall_alpha);
206 void gdk_pixbuf_composite_color (const GdkPixbuf *src,
207                                  GdkPixbuf       *dest,
208                                  int              dest_x,
209                                  int              dest_y,
210                                  int              dest_width,
211                                  int              dest_height,
212                                  double           offset_x,
213                                  double           offset_y,
214                                  double           scale_x,
215                                  double           scale_y,
216                                  GdkInterpType    interp_type,
217                                  int              overall_alpha,
218                                  int              check_x,
219                                  int              check_y,
220                                  int              check_size,
221                                  guint32          color1,
222                                  guint32          color2);
223
224 GdkPixbuf *gdk_pixbuf_scale_simple           (const GdkPixbuf *src,
225                                               int              dest_width,
226                                               int              dest_height,
227                                               GdkInterpType    interp_type);
228
229 GdkPixbuf *gdk_pixbuf_composite_color_simple (const GdkPixbuf *src,
230                                               int              dest_width,
231                                               int              dest_height,
232                                               GdkInterpType    interp_type,
233                                               int              overall_alpha,
234                                               int              check_size,
235                                               guint32          color1,
236                                               guint32          color2);
237
238 \f
239
240 /* Animation support */
241
242 /* GIF-like animation overlay modes for frames */
243 typedef enum {
244         GDK_PIXBUF_FRAME_RETAIN,
245         GDK_PIXBUF_FRAME_DISPOSE,
246         GDK_PIXBUF_FRAME_REVERT
247 } GdkPixbufFrameAction;
248
249 GType               gdk_pixbuf_animation_get_type        (void) G_GNUC_CONST;
250
251 GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file   (const char         *filename);
252
253 GdkPixbufAnimation *gdk_pixbuf_animation_ref             (GdkPixbufAnimation *animation);
254 void                gdk_pixbuf_animation_unref           (GdkPixbufAnimation *animation);
255
256 int                 gdk_pixbuf_animation_get_width       (GdkPixbufAnimation *animation);
257 int                 gdk_pixbuf_animation_get_height      (GdkPixbufAnimation *animation);
258 GList              *gdk_pixbuf_animation_get_frames      (GdkPixbufAnimation *animation);
259 int                 gdk_pixbuf_animation_get_num_frames  (GdkPixbufAnimation *animation);
260
261 /* Frame accessors */
262
263 GdkPixbuf           *gdk_pixbuf_frame_get_pixbuf     (GdkPixbufFrame *frame);
264 int                  gdk_pixbuf_frame_get_x_offset   (GdkPixbufFrame *frame);
265 int                  gdk_pixbuf_frame_get_y_offset   (GdkPixbufFrame *frame);
266 int                  gdk_pixbuf_frame_get_delay_time (GdkPixbufFrame *frame);
267 GdkPixbufFrameAction gdk_pixbuf_frame_get_action     (GdkPixbufFrame *frame);
268
269
270 /* General (presently empty) initialization hooks, primarily for gnome-libs */
271 void gdk_pixbuf_preinit  (gpointer app, gpointer modinfo);
272 void gdk_pixbuf_postinit (gpointer app, gpointer modinfo);
273 /* A more user-friendly init function */
274 void gdk_pixbuf_init     (void);
275
276 \f
277
278 #ifdef __cplusplus
279 }
280 #endif
281
282 #endif