]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf.h
82f0551bac90207758639a85ea05ed6b592d1813
[~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 /* Color spaces; right now only RGB is supported.
40  * Note that these values are encoded in inline pixbufs
41  * as ints, so don't reorder them
42  */
43 typedef enum {
44         GDK_COLORSPACE_RGB
45 } GdkColorspace;
46
47 /* All of these are opaque structures */
48 typedef struct _GdkPixbuf GdkPixbuf;
49 typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
50 typedef struct _GdkPixbufFrame GdkPixbufFrame;
51
52 #define GDK_TYPE_PIXBUF              (gdk_pixbuf_get_type ())
53 #define GDK_PIXBUF(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF, GdkPixbuf))
54 #define GDK_IS_PIXBUF(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF))
55
56 #define GDK_TYPE_PIXBUF_ANIMATION              (gdk_pixbuf_animation_get_type ())
57 #define GDK_PIXBUF_ANIMATION(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimation))
58 #define GDK_IS_PIXBUF_ANIMATION(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION))
59
60
61 /* Handler that must free the pixel array */
62 typedef void (* GdkPixbufDestroyNotify) (guchar *pixels, gpointer data);
63
64 #define GDK_PIXBUF_ERROR gdk_pixbuf_error_quark ()
65
66 typedef enum {
67         /* some kind of failure reading or writing files */
68         GDK_PIXBUF_ERROR_IO,
69         /* bad option value passed to save routine */
70         GDK_PIXBUF_ERROR_BAD_OPTION_VALUE,
71         /* unsupported image type (sort of an ENOSYS) */
72         GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
73         GDK_PIXBUF_ERROR_FAILED
74 } GdkPixbufErrorType;
75
76 GQuark gdk_pixbuf_error_quark () G_GNUC_CONST;
77
78 \f
79
80 GType gdk_pixbuf_get_type (void) G_GNUC_CONST;
81
82 /* Reference counting */
83
84 GdkPixbuf *gdk_pixbuf_ref      (GdkPixbuf *pixbuf);
85 void       gdk_pixbuf_unref    (GdkPixbuf *pixbuf);
86
87 /* GdkPixbuf accessors */
88
89 GdkColorspace gdk_pixbuf_get_colorspace      (const GdkPixbuf *pixbuf);
90 int           gdk_pixbuf_get_n_channels      (const GdkPixbuf *pixbuf);
91 gboolean      gdk_pixbuf_get_has_alpha       (const GdkPixbuf *pixbuf);
92 int           gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf);
93 guchar       *gdk_pixbuf_get_pixels          (const GdkPixbuf *pixbuf);
94 int           gdk_pixbuf_get_width           (const GdkPixbuf *pixbuf);
95 int           gdk_pixbuf_get_height          (const GdkPixbuf *pixbuf);
96 int           gdk_pixbuf_get_rowstride       (const GdkPixbuf *pixbuf);
97
98 \f
99
100 /* Create a blank pixbuf with an optimal rowstride and a new buffer */
101 GdkPixbuf *gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample,
102                            int width, int height);
103
104 /* Copy a pixbuf */
105
106 GdkPixbuf *gdk_pixbuf_copy (const GdkPixbuf *pixbuf);
107
108 /* Simple loading */
109
110 GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename);
111
112 GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data,
113                                      GdkColorspace colorspace,
114                                      gboolean has_alpha,
115                                      int bits_per_sample,
116                                      int width, int height,
117                                      int rowstride,
118                                      GdkPixbufDestroyNotify destroy_fn,
119                                      gpointer destroy_fn_data);
120
121 GdkPixbuf *gdk_pixbuf_new_from_xpm_data (const char **data);
122
123 /* Read an inline pixbuf */
124 GdkPixbuf *gdk_pixbuf_new_from_inline   (const guchar *inline_pixbuf,
125                                          gboolean      copy_pixels,
126                                          int           length);
127
128
129 /* Saving */
130
131 gboolean gdk_pixbuf_save           (GdkPixbuf  *pixbuf, 
132                                     const char *filename, 
133                                     const char *format, 
134                                     GError    **err,
135                                     ...);
136
137 gboolean gdk_pixbuf_savev          (GdkPixbuf  *pixbuf, 
138                                     const char *filename, 
139                                     const char *format,
140                                     char      **option_keys,
141                                     char      **option_values,
142                                     GError    **err);
143
144 /* Adding an alpha channel */
145 GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color,
146                                  guchar r, guchar g, guchar b);
147
148 /* Copy an area of a pixbuf onto another one */
149 void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf,
150                            int src_x, int src_y,
151                            int width, int height,
152                            GdkPixbuf *dest_pixbuf,
153                            int dest_x, int dest_y);
154
155 /* Brighten/darken and optionally make it pixelated-looking */
156 void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src,
157                                        GdkPixbuf       *dest,
158                                        gfloat           saturation,
159                                        gboolean         pixelate);
160
161 \f
162
163 /* Rendering to a drawable */
164 \f
165
166 /* Scaling */
167
168 /* Interpolation modes */
169 typedef enum {
170         GDK_INTERP_NEAREST,
171         GDK_INTERP_TILES,
172         GDK_INTERP_BILINEAR,
173         GDK_INTERP_HYPER
174 } GdkInterpType;
175
176 void gdk_pixbuf_scale           (const GdkPixbuf *src,
177                                  GdkPixbuf       *dest,
178                                  int              dest_x,
179                                  int              dest_y,
180                                  int              dest_width,
181                                  int              dest_height,
182                                  double           offset_x,
183                                  double           offset_y,
184                                  double           scale_x,
185                                  double           scale_y,
186                                  GdkInterpType    interp_type);
187 void gdk_pixbuf_composite       (const GdkPixbuf *src,
188                                  GdkPixbuf       *dest,
189                                  int              dest_x,
190                                  int              dest_y,
191                                  int              dest_width,
192                                  int              dest_height,
193                                  double           offset_x,
194                                  double           offset_y,
195                                  double           scale_x,
196                                  double           scale_y,
197                                  GdkInterpType    interp_type,
198                                  int              overall_alpha);
199 void gdk_pixbuf_composite_color (const GdkPixbuf *src,
200                                  GdkPixbuf       *dest,
201                                  int              dest_x,
202                                  int              dest_y,
203                                  int              dest_width,
204                                  int              dest_height,
205                                  double           offset_x,
206                                  double           offset_y,
207                                  double           scale_x,
208                                  double           scale_y,
209                                  GdkInterpType    interp_type,
210                                  int              overall_alpha,
211                                  int              check_x,
212                                  int              check_y,
213                                  int              check_size,
214                                  guint32          color1,
215                                  guint32          color2);
216
217 GdkPixbuf *gdk_pixbuf_scale_simple           (const GdkPixbuf *src,
218                                               int              dest_width,
219                                               int              dest_height,
220                                               GdkInterpType    interp_type);
221
222 GdkPixbuf *gdk_pixbuf_composite_color_simple (const GdkPixbuf *src,
223                                               int              dest_width,
224                                               int              dest_height,
225                                               GdkInterpType    interp_type,
226                                               int              overall_alpha,
227                                               int              check_size,
228                                               guint32          color1,
229                                               guint32          color2);
230
231 \f
232
233 /* Animation support */
234
235 /* GIF-like animation overlay modes for frames */
236 typedef enum {
237         GDK_PIXBUF_FRAME_RETAIN,
238         GDK_PIXBUF_FRAME_DISPOSE,
239         GDK_PIXBUF_FRAME_REVERT
240 } GdkPixbufFrameAction;
241
242 GType               gdk_pixbuf_animation_get_type        (void) G_GNUC_CONST;
243
244 GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file   (const char         *filename);
245
246 GdkPixbufAnimation *gdk_pixbuf_animation_ref             (GdkPixbufAnimation *animation);
247 void                gdk_pixbuf_animation_unref           (GdkPixbufAnimation *animation);
248
249 int                 gdk_pixbuf_animation_get_width       (GdkPixbufAnimation *animation);
250 int                 gdk_pixbuf_animation_get_height      (GdkPixbufAnimation *animation);
251 GList              *gdk_pixbuf_animation_get_frames      (GdkPixbufAnimation *animation);
252 int                 gdk_pixbuf_animation_get_num_frames  (GdkPixbufAnimation *animation);
253
254 /* Frame accessors */
255
256 GdkPixbuf           *gdk_pixbuf_frame_get_pixbuf     (GdkPixbufFrame *frame);
257 int                  gdk_pixbuf_frame_get_x_offset   (GdkPixbufFrame *frame);
258 int                  gdk_pixbuf_frame_get_y_offset   (GdkPixbufFrame *frame);
259 int                  gdk_pixbuf_frame_get_delay_time (GdkPixbufFrame *frame);
260 GdkPixbufFrameAction gdk_pixbuf_frame_get_action     (GdkPixbufFrame *frame);
261
262
263 /* General (presently empty) initialization hooks, primarily for gnome-libs */
264 void gdk_pixbuf_preinit  (gpointer app, gpointer modinfo);
265 void gdk_pixbuf_postinit (gpointer app, gpointer modinfo);
266 /* A more user-friendly init function */
267 void gdk_pixbuf_init     (void);
268
269 \f
270
271 #ifdef __cplusplus
272 }
273 #endif
274
275 #endif