]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-core.h
2.13.3
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-core.h
1 /* GdkPixbuf library - GdkPixbuf data structure
2  *
3  * Copyright (C) 2003 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 #if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION)
27 #error "Only <gdk-pixbuf/gdk-pixbuf.h> can be included directly."
28 #endif
29
30 #ifndef GDK_PIXBUF_CORE_H
31 #define GDK_PIXBUF_CORE_H
32
33 #include <glib.h>
34 #include <glib-object.h>
35 #include <gio/gio.h>
36
37 G_BEGIN_DECLS
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
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
62 /* Handler that must free the pixel array */
63 typedef void (* GdkPixbufDestroyNotify) (guchar *pixels, gpointer data);
64
65 #define GDK_PIXBUF_ERROR gdk_pixbuf_error_quark ()
66
67 typedef enum {
68         /* image data hosed */
69         GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
70         /* no mem to load image */
71         GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
72         /* bad option passed to save routine */
73         GDK_PIXBUF_ERROR_BAD_OPTION,
74         /* unsupported image type (sort of an ENOSYS) */
75         GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
76         /* unsupported operation (load, save) for image type */
77         GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
78         GDK_PIXBUF_ERROR_FAILED
79 } GdkPixbufError;
80
81 GQuark gdk_pixbuf_error_quark (void);
82
83 \f
84
85 GType gdk_pixbuf_get_type (void) G_GNUC_CONST;
86
87 /* Reference counting */
88
89 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
90 GdkPixbuf *gdk_pixbuf_ref      (GdkPixbuf *pixbuf);
91 void       gdk_pixbuf_unref    (GdkPixbuf *pixbuf);
92 #endif
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 /* Create a pixbuf which points to the pixels of another pixbuf */
116 GdkPixbuf *gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf,
117                                      int        src_x,
118                                      int        src_y,
119                                      int        width,
120                                      int        height);
121
122 /* Simple loading */
123
124 #ifdef G_OS_WIN32
125 /* DLL ABI stability hack. */
126 #define gdk_pixbuf_new_from_file gdk_pixbuf_new_from_file_utf8
127 #define gdk_pixbuf_new_from_file_at_size gdk_pixbuf_new_from_file_at_size_utf8
128 #define gdk_pixbuf_new_from_file_at_scale gdk_pixbuf_new_from_file_at_scale_utf8
129 #endif
130
131 GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename,
132                                      GError    **error);
133 GdkPixbuf *gdk_pixbuf_new_from_file_at_size (const char *filename,
134                                              int         width, 
135                                              int         height,
136                                              GError    **error);
137 GdkPixbuf *gdk_pixbuf_new_from_file_at_scale (const char *filename,
138                                               int         width, 
139                                               int         height,
140                                               gboolean    preserve_aspect_ratio,
141                                               GError    **error);
142
143 GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data,
144                                      GdkColorspace colorspace,
145                                      gboolean has_alpha,
146                                      int bits_per_sample,
147                                      int width, int height,
148                                      int rowstride,
149                                      GdkPixbufDestroyNotify destroy_fn,
150                                      gpointer destroy_fn_data);
151
152 GdkPixbuf *gdk_pixbuf_new_from_xpm_data (const char **data);
153 GdkPixbuf* gdk_pixbuf_new_from_inline   (gint          data_length,
154                                          const guint8 *data,
155                                          gboolean      copy_pixels,
156                                          GError      **error);
157        
158 /* Mutations */
159 void       gdk_pixbuf_fill              (GdkPixbuf    *pixbuf,
160                                          guint32       pixel);
161
162 /* Saving */
163
164 #ifdef G_OS_WIN32
165 /* DLL ABI stability hack. */
166 #define gdk_pixbuf_save gdk_pixbuf_save_utf8
167 #define gdk_pixbuf_savev gdk_pixbuf_savev_utf8
168 #endif
169
170 gboolean gdk_pixbuf_save           (GdkPixbuf  *pixbuf, 
171                                     const char *filename, 
172                                     const char *type, 
173                                     GError    **error,
174                                     ...) G_GNUC_NULL_TERMINATED;
175
176 gboolean gdk_pixbuf_savev          (GdkPixbuf  *pixbuf, 
177                                     const char *filename, 
178                                     const char *type,
179                                     char      **option_keys,
180                                     char      **option_values,
181                                     GError    **error);
182
183 /* Saving to a callback function */
184
185 typedef gboolean (*GdkPixbufSaveFunc)   (const gchar *buf,
186                                          gsize count,
187                                          GError **error,
188                                          gpointer data);
189
190 gboolean gdk_pixbuf_save_to_callback    (GdkPixbuf  *pixbuf,
191                                          GdkPixbufSaveFunc save_func,
192                                          gpointer user_data,
193                                          const char *type, 
194                                          GError    **error,
195                                          ...) G_GNUC_NULL_TERMINATED;
196
197 gboolean gdk_pixbuf_save_to_callbackv   (GdkPixbuf  *pixbuf, 
198                                          GdkPixbufSaveFunc save_func,
199                                          gpointer user_data,
200                                          const char *type,
201                                          char      **option_keys,
202                                          char      **option_values,
203                                          GError    **error);
204
205 /* Saving into a newly allocated char array */
206
207 gboolean gdk_pixbuf_save_to_buffer      (GdkPixbuf  *pixbuf,
208                                          gchar     **buffer,
209                                          gsize      *buffer_size,
210                                          const char *type, 
211                                          GError    **error,
212                                          ...) G_GNUC_NULL_TERMINATED;
213
214 gboolean gdk_pixbuf_save_to_bufferv     (GdkPixbuf  *pixbuf,
215                                          gchar     **buffer,
216                                          gsize      *buffer_size,
217                                          const char *type, 
218                                          char      **option_keys,
219                                          char      **option_values,
220                                          GError    **error);
221
222 GdkPixbuf *gdk_pixbuf_new_from_stream   (GInputStream   *stream,
223                                          GCancellable   *cancellable,
224                                          GError        **error);
225
226 GdkPixbuf *gdk_pixbuf_new_from_stream_at_scale   (GInputStream   *stream,
227                                                   gint            width,
228                                                   gint            height,
229                                                   gboolean        preserve_aspect_ratio,
230                                                   GCancellable   *cancellable,
231                                                   GError        **error);
232
233 gboolean   gdk_pixbuf_save_to_stream    (GdkPixbuf      *pixbuf,
234                                          GOutputStream  *stream,
235                                          const char     *type,
236                                          GCancellable   *cancellable,
237                                          GError        **error,
238                                          ...);
239
240 /* Adding an alpha channel */
241 GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color,
242                                  guchar r, guchar g, guchar b);
243
244 /* Copy an area of a pixbuf onto another one */
245 void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf,
246                            int src_x, int src_y,
247                            int width, int height,
248                            GdkPixbuf *dest_pixbuf,
249                            int dest_x, int dest_y);
250
251 /* Brighten/darken and optionally make it pixelated-looking */
252 void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src,
253                                        GdkPixbuf       *dest,
254                                        gfloat           saturation,
255                                        gboolean         pixelate);
256
257 /* Transform an image to agree with its embedded orientation option / tag */
258 GdkPixbuf *gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src);
259
260 G_CONST_RETURN gchar * gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
261                                               const gchar *key);
262
263
264 G_END_DECLS
265
266
267 #endif /* GDK_PIXBUF_CORE_H */