]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf.h
New public API to save pixbufs to non-file locations. (#82203, Tim Evans)
[~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 <glib-object.h>
32
33 G_BEGIN_DECLS
34
35 \f
36
37 /* Alpha compositing mode */
38 typedef enum
39 {
40         GDK_PIXBUF_ALPHA_BILEVEL,
41         GDK_PIXBUF_ALPHA_FULL
42 } GdkPixbufAlphaMode;
43
44 /* Color spaces; right now only RGB is supported.
45  * Note that these values are encoded in inline pixbufs
46  * as ints, so don't reorder them
47  */
48 typedef enum {
49         GDK_COLORSPACE_RGB
50 } GdkColorspace;
51
52 /* All of these are opaque structures */
53 typedef struct _GdkPixbuf GdkPixbuf;
54 typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
55 typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
56
57 #define GDK_TYPE_PIXBUF              (gdk_pixbuf_get_type ())
58 #define GDK_PIXBUF(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF, GdkPixbuf))
59 #define GDK_IS_PIXBUF(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF))
60
61 #define GDK_TYPE_PIXBUF_ANIMATION              (gdk_pixbuf_animation_get_type ())
62 #define GDK_PIXBUF_ANIMATION(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimation))
63 #define GDK_IS_PIXBUF_ANIMATION(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION))
64
65 #define GDK_TYPE_PIXBUF_ANIMATION_ITER              (gdk_pixbuf_animation_iter_get_type ())
66 #define GDK_PIXBUF_ANIMATION_ITER(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIter))
67 #define GDK_IS_PIXBUF_ANIMATION_ITER(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION_ITER))
68
69 /* Handler that must free the pixel array */
70 typedef void (* GdkPixbufDestroyNotify) (guchar *pixels, gpointer data);
71
72 #define GDK_PIXBUF_ERROR gdk_pixbuf_error_quark ()
73
74 typedef enum {
75         /* image data hosed */
76         GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
77         /* no mem to load image */
78         GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
79         /* bad option passed to save routine */
80         GDK_PIXBUF_ERROR_BAD_OPTION,
81         /* unsupported image type (sort of an ENOSYS) */
82         GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
83         /* unsupported operation (load, save) for image type */
84         GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
85         GDK_PIXBUF_ERROR_FAILED
86 } GdkPixbufError;
87
88 GQuark gdk_pixbuf_error_quark (void) G_GNUC_CONST;
89
90 \f
91
92 GType gdk_pixbuf_get_type (void) G_GNUC_CONST;
93
94 /* Reference counting */
95
96 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
97 GdkPixbuf *gdk_pixbuf_ref      (GdkPixbuf *pixbuf);
98 void       gdk_pixbuf_unref    (GdkPixbuf *pixbuf);
99 #endif
100
101 /* GdkPixbuf accessors */
102
103 GdkColorspace gdk_pixbuf_get_colorspace      (const GdkPixbuf *pixbuf);
104 int           gdk_pixbuf_get_n_channels      (const GdkPixbuf *pixbuf);
105 gboolean      gdk_pixbuf_get_has_alpha       (const GdkPixbuf *pixbuf);
106 int           gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf);
107 guchar       *gdk_pixbuf_get_pixels          (const GdkPixbuf *pixbuf);
108 int           gdk_pixbuf_get_width           (const GdkPixbuf *pixbuf);
109 int           gdk_pixbuf_get_height          (const GdkPixbuf *pixbuf);
110 int           gdk_pixbuf_get_rowstride       (const GdkPixbuf *pixbuf);
111
112 \f
113
114 /* Create a blank pixbuf with an optimal rowstride and a new buffer */
115 GdkPixbuf *gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample,
116                            int width, int height);
117
118 /* Copy a pixbuf */
119
120 GdkPixbuf *gdk_pixbuf_copy (const GdkPixbuf *pixbuf);
121
122 /* Create a pixbuf which points to the pixels of another pixbuf */
123 GdkPixbuf *gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
124                                      int        src_x,
125                                      int        src_y,
126                                      int        width,
127                                      int        height);
128
129 /* Simple loading */
130
131 GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename,
132                                      GError    **error);
133
134 GdkPixbuf *gdk_pixbuf_new_from_file_at_size (const char *filename,
135                                              int         width, 
136                                              int         height,
137                                              GError    **error);
138
139 GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data,
140                                      GdkColorspace colorspace,
141                                      gboolean has_alpha,
142                                      int bits_per_sample,
143                                      int width, int height,
144                                      int rowstride,
145                                      GdkPixbufDestroyNotify destroy_fn,
146                                      gpointer destroy_fn_data);
147
148 GdkPixbuf *gdk_pixbuf_new_from_xpm_data (const char **data);
149 GdkPixbuf* gdk_pixbuf_new_from_inline   (gint          data_length,
150                                          const guint8 *data,
151                                          gboolean      copy_pixels,
152                                          GError      **error);
153        
154 /* Mutations */
155 void       gdk_pixbuf_fill              (GdkPixbuf    *pixbuf,
156                                          guint32       pixel);
157
158 /* Saving */
159
160 gboolean gdk_pixbuf_save           (GdkPixbuf  *pixbuf, 
161                                     const char *filename, 
162                                     const char *type, 
163                                     GError    **error,
164                                     ...);
165
166 gboolean gdk_pixbuf_savev          (GdkPixbuf  *pixbuf, 
167                                     const char *filename, 
168                                     const char *type,
169                                     char      **option_keys,
170                                     char      **option_values,
171                                     GError    **error);
172
173 /* Saving to a callback function */
174
175 typedef gboolean (*GdkPixbufSaveFunc)   (const gchar *buf,
176                                          gsize count,
177                                          GError **error,
178                                          gpointer data);
179
180 gboolean gdk_pixbuf_save_to_callback    (GdkPixbuf  *pixbuf,
181                                          GdkPixbufSaveFunc save_func,
182                                          gpointer user_data,
183                                          const char *type, 
184                                          GError    **error,
185                                          ...);
186
187 gboolean gdk_pixbuf_save_to_callbackv   (GdkPixbuf  *pixbuf, 
188                                          GdkPixbufSaveFunc save_func,
189                                          gpointer user_data,
190                                          const char *type,
191                                          char      **option_keys,
192                                          char      **option_values,
193                                          GError    **error);
194
195 /* Saving into a newly allocated char array */
196
197 gboolean gdk_pixbuf_save_to_buffer      (GdkPixbuf  *pixbuf,
198                                          gchar     **buffer,
199                                          gsize      *buffer_size,
200                                          const char *type, 
201                                          GError    **error,
202                                          ...);
203
204 gboolean gdk_pixbuf_save_to_bufferv     (GdkPixbuf  *pixbuf,
205                                          gchar     **buffer,
206                                          gsize      *buffer_size,
207                                          const char *type, 
208                                          char      **option_keys,
209                                          char      **option_values,
210                                          GError    **error);
211
212 /* Adding an alpha channel */
213 GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color,
214                                  guchar r, guchar g, guchar b);
215
216 /* Copy an area of a pixbuf onto another one */
217 void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf,
218                            int src_x, int src_y,
219                            int width, int height,
220                            GdkPixbuf *dest_pixbuf,
221                            int dest_x, int dest_y);
222
223 /* Brighten/darken and optionally make it pixelated-looking */
224 void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src,
225                                        GdkPixbuf       *dest,
226                                        gfloat           saturation,
227                                        gboolean         pixelate);
228
229 \f
230
231 /* Rendering to a drawable */
232 \f
233
234 /* Scaling */
235
236 /* Interpolation modes */
237 typedef enum {
238         GDK_INTERP_NEAREST,
239         GDK_INTERP_TILES,
240         GDK_INTERP_BILINEAR,
241         GDK_INTERP_HYPER
242 } GdkInterpType;
243
244 void gdk_pixbuf_scale           (const GdkPixbuf *src,
245                                  GdkPixbuf       *dest,
246                                  int              dest_x,
247                                  int              dest_y,
248                                  int              dest_width,
249                                  int              dest_height,
250                                  double           offset_x,
251                                  double           offset_y,
252                                  double           scale_x,
253                                  double           scale_y,
254                                  GdkInterpType    interp_type);
255 void gdk_pixbuf_composite       (const GdkPixbuf *src,
256                                  GdkPixbuf       *dest,
257                                  int              dest_x,
258                                  int              dest_y,
259                                  int              dest_width,
260                                  int              dest_height,
261                                  double           offset_x,
262                                  double           offset_y,
263                                  double           scale_x,
264                                  double           scale_y,
265                                  GdkInterpType    interp_type,
266                                  int              overall_alpha);
267 void gdk_pixbuf_composite_color (const GdkPixbuf *src,
268                                  GdkPixbuf       *dest,
269                                  int              dest_x,
270                                  int              dest_y,
271                                  int              dest_width,
272                                  int              dest_height,
273                                  double           offset_x,
274                                  double           offset_y,
275                                  double           scale_x,
276                                  double           scale_y,
277                                  GdkInterpType    interp_type,
278                                  int              overall_alpha,
279                                  int              check_x,
280                                  int              check_y,
281                                  int              check_size,
282                                  guint32          color1,
283                                  guint32          color2);
284
285 GdkPixbuf *gdk_pixbuf_scale_simple           (const GdkPixbuf *src,
286                                               int              dest_width,
287                                               int              dest_height,
288                                               GdkInterpType    interp_type);
289
290 GdkPixbuf *gdk_pixbuf_composite_color_simple (const GdkPixbuf *src,
291                                               int              dest_width,
292                                               int              dest_height,
293                                               GdkInterpType    interp_type,
294                                               int              overall_alpha,
295                                               int              check_size,
296                                               guint32          color1,
297                                               guint32          color2);
298
299 \f
300
301 /* Animation support */
302
303 GType               gdk_pixbuf_animation_get_type        (void) G_GNUC_CONST;
304
305 GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file   (const char         *filename,
306                                                           GError            **error);
307
308 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
309 GdkPixbufAnimation *gdk_pixbuf_animation_ref             (GdkPixbufAnimation *animation);
310 void                gdk_pixbuf_animation_unref           (GdkPixbufAnimation *animation);
311 #endif
312
313 int                 gdk_pixbuf_animation_get_width       (GdkPixbufAnimation *animation);
314 int                 gdk_pixbuf_animation_get_height      (GdkPixbufAnimation *animation);
315 gboolean            gdk_pixbuf_animation_is_static_image  (GdkPixbufAnimation *animation);
316 GdkPixbuf          *gdk_pixbuf_animation_get_static_image (GdkPixbufAnimation *animation);
317
318 GdkPixbufAnimationIter *gdk_pixbuf_animation_get_iter                        (GdkPixbufAnimation     *animation,
319                                                                               const GTimeVal         *start_time);
320 GType                   gdk_pixbuf_animation_iter_get_type                   (void) G_GNUC_CONST;
321 int                     gdk_pixbuf_animation_iter_get_delay_time             (GdkPixbufAnimationIter *iter);
322 GdkPixbuf              *gdk_pixbuf_animation_iter_get_pixbuf                 (GdkPixbufAnimationIter *iter);
323 gboolean                gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
324 gboolean                gdk_pixbuf_animation_iter_advance                    (GdkPixbufAnimationIter *iter,
325                                                                               const GTimeVal         *current_time);
326
327
328 \f
329
330 G_CONST_RETURN gchar * gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
331                                               const gchar *key);
332
333 \f
334
335 typedef struct _GdkPixbufFormat GdkPixbufFormat;
336  
337 GSList    *gdk_pixbuf_get_formats (void);
338 gchar     *gdk_pixbuf_format_get_name        (GdkPixbufFormat *format);
339 gchar     *gdk_pixbuf_format_get_description (GdkPixbufFormat *format);
340 gchar    **gdk_pixbuf_format_get_mime_types  (GdkPixbufFormat *format);
341 gchar    **gdk_pixbuf_format_get_extensions  (GdkPixbufFormat *format);
342 gboolean   gdk_pixbuf_format_is_writable     (GdkPixbufFormat *format);
343
344 GdkPixbufFormat *gdk_pixbuf_get_file_info (const gchar  *filename,
345                                            gint         *width, 
346                                            gint         *height);
347
348 G_END_DECLS
349
350 #include <gdk-pixbuf/gdk-pixbuf-loader.h>
351 #include <gdk-pixbuf/gdk-pixbuf-enum-types.h>
352
353 \f
354
355 #endif