Merged pidgin/main into default
[pidgin-git.git] / libpurple / image.h
blobcb4dfb3f5a06483fce1c04978777fd3547bdc69d
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef PURPLE_IMAGE_H
23 #define PURPLE_IMAGE_H
25 /**
26 * SECTION:image
27 * @include:image.h
28 * @section_id: libpurple-image
29 * @short_description: implementation-independent image data container
30 * @title: Images
32 * #PurpleImage object is a container for raw image data. It doesn't manipulate
33 * image data, just stores it in its binary format - png, jpeg etc. Thus, it's
34 * totally independent from the UI.
36 * This class also provides certain file-related features, like: friendly
37 * filenames (not necessarily real filename for displaying); remote images
38 * (which data is not yet loaded) or guessing file format from its header.
41 #include <glib-object.h>
43 typedef struct _PurpleImage PurpleImage;
44 typedef struct _PurpleImageClass PurpleImageClass;
46 #define PURPLE_TYPE_IMAGE (purple_image_get_type())
47 #define PURPLE_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_IMAGE, PurpleImage))
48 #define PURPLE_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_IMAGE, PurpleImageClass))
49 #define PURPLE_IS_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_IMAGE))
50 #define PURPLE_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_IMAGE))
51 #define PURPLE_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_IMAGE, PurpleImageClass))
53 /**
54 * PurpleImage:
56 * An image data container.
58 struct _PurpleImage {
59 /*< private >*/
60 GObject parent;
63 struct _PurpleImageClass {
64 GObjectClass parent_class;
66 void (*purple_reserved1)(void);
67 void (*purple_reserved2)(void);
68 void (*purple_reserved3)(void);
69 void (*purple_reserved4)(void);
72 G_BEGIN_DECLS
74 /**
75 * purple_image_get_type:
77 * Returns: the #GType for an image.
79 GType purple_image_get_type(void);
81 /**
82 * purple_image_new_from_bytes:
83 * @bytes: (transfer none): A #GBytes containing the raw image data.
85 * Loads a raw image data as a new #PurpleImage object.
87 * Returns: the new #PurpleImage.
89 PurpleImage *purple_image_new_from_bytes(GBytes *bytes);
91 /**
92 * purple_image_new_from_file:
93 * @path: the path to the image file.
94 * @error: (optional) (out): An optional return address for a #GError
96 * Loads an image file as a new #PurpleImage object. The @path must exists, be
97 * readable and should point to a valid image file. If you don't set @be_eager
98 * parameter, there will be a risk that file will be removed from disk before
99 * you access its data.
101 * Returns: the new #PurpleImage.
103 PurpleImage *purple_image_new_from_file(const gchar *path, GError **error);
106 * purple_image_new_from_data:
107 * @data: the pointer to the image data buffer.
108 * @length: the length of @data.
110 * Creates a new #PurpleImage object with contents of @data buffer.
112 * The @data buffer is owned by #PurpleImage object, so you might want
113 * to #g_memdup it first.
115 * Returns: the new #PurpleImage.
117 PurpleImage *purple_image_new_from_data(const guint8 *data, gsize length);
120 * purple_image_new_take_data:
121 * @data: (transfer full): the pointer to the image data buffer.
122 * @length: the length of @data.
124 * Creates a new #PurpleImage object with contents of @data buffer.
126 * The @data buffer is owned by #PurpleImage object, so you might want
127 * to #g_memdup it first.
129 * Returns: the new #PurpleImage.
131 PurpleImage *purple_image_new_take_data(guint8 *data, gsize length);
134 * purple_image_save:
135 * @image: the image.
136 * @path: destination of a saved image file.
138 * Saves an @image to the disk.
140 * Returns: %TRUE if succeeded, %FALSE otherwise.
142 gboolean purple_image_save(PurpleImage *image, const gchar *path);
145 * purple_image_get_contents:
146 * @image: The #PurpleImage.
148 * Returns a new reference to the #GBytes that contains the image data.
150 * Returns: (transfer full): A #GBytes containing the image data.
152 GBytes *purple_image_get_contents(const PurpleImage *image);
156 * purple_image_get_path:
157 * @image: the image.
159 * Returns the physical path of the @image file. It is set only, if the @image is
160 * really backed by an existing file. In the other case it returns %NULL.
162 * Returns: the physical path of the @image, or %NULL.
164 const gchar *purple_image_get_path(PurpleImage *image);
167 * purple_image_get_data_size:
168 * @image: the image.
170 * Returns the size of @image's data.
172 * Returns: the size of data, or 0 in case of failure.
174 gsize purple_image_get_data_size(PurpleImage *image);
177 * purple_image_get_data:
178 * @image: the image.
180 * Returns the pointer to the buffer containing image data.
182 * Returns: (transfer none): the @image data.
184 gconstpointer purple_image_get_data(PurpleImage *image);
187 * purple_image_get_extension:
188 * @image: the image.
190 * Guesses the @image format based on its contents.
192 * Returns: (transfer none): the file extension suitable for @image format.
194 const gchar *purple_image_get_extension(PurpleImage *image);
197 * purple_image_get_mimetype:
198 * @image: the image.
200 * Guesses the @image mime-type based on its contents.
202 * Returns: (transfer none): the mime-type suitable for @image format.
204 const gchar *purple_image_get_mimetype(PurpleImage *image);
207 * purple_image_generate_filename:
208 * @image: the image.
210 * Calculates almost-unique filename by computing checksum from file contents
211 * and appending a suitable extension. You should not assume the checksum
212 * is SHA-1, because it may change in the future.
214 * Returns: (transfer none): the generated file name.
216 const gchar *purple_image_generate_filename(PurpleImage *image);
219 * purple_image_set_friendly_filename:
220 * @image: the image.
221 * @filename: the friendly filename.
223 * Sets the "friendly filename" for the @image. This don't have to be a real
224 * name, because it's used for displaying or as a default file name when the
225 * user wants to save the @image to the disk.
227 * The provided @filename may either be a full path, or contain
228 * filesystem-unfriendly characters, because it will be reformatted.
230 void purple_image_set_friendly_filename(PurpleImage *image, const gchar *filename);
233 * purple_image_get_friendly_filename:
234 * @image: the image.
236 * Returns the "friendly filename" for the @image, to be displayed or used as
237 * a default name when saving a file to the disk.
238 * See #purple_image_set_friendly_filename.
240 * If the friendly filename was not set, it will be generated with
241 * #purple_image_generate_filename.
243 * Returns: (transfer none): the friendly filename.
245 const gchar *purple_image_get_friendly_filename(PurpleImage *image);
247 G_END_DECLS
249 #endif /* PURPLE_IMAGE_H */