Merged in default (pull request #594)
[pidgin-git.git] / libpurple / image.h
blobc65b7f7138fefdbfffaaa3d225361ef5db933517
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 #define PURPLE_TYPE_IMAGE purple_image_get_type()
45 struct _PurpleImageClass {
46 /*< private >*/
47 GObjectClass parent_class;
49 void (*purple_reserved1)(void);
50 void (*purple_reserved2)(void);
51 void (*purple_reserved3)(void);
52 void (*purple_reserved4)(void);
55 G_BEGIN_DECLS
57 /**
58 * purple_image_get_type:
60 * Returns: the #GType for an image.
62 G_DECLARE_DERIVABLE_TYPE(PurpleImage, purple_image, PURPLE, IMAGE, GObject)
64 /**
65 * purple_image_new_from_bytes:
66 * @bytes: (transfer none): A #GBytes containing the raw image data.
68 * Loads a raw image data as a new #PurpleImage object.
70 * Returns: the new #PurpleImage.
72 PurpleImage *purple_image_new_from_bytes(GBytes *bytes);
74 /**
75 * purple_image_new_from_file:
76 * @path: the path to the image file.
77 * @error: (optional) (out): An optional return address for a #GError
79 * Loads an image file as a new #PurpleImage object. The @path must exists, be
80 * readable and should point to a valid image file. If you don't set @be_eager
81 * parameter, there will be a risk that file will be removed from disk before
82 * you access its data.
84 * Returns: the new #PurpleImage.
86 PurpleImage *purple_image_new_from_file(const gchar *path, GError **error);
88 /**
89 * purple_image_new_from_data:
90 * @data: the pointer to the image data buffer.
91 * @length: the length of @data.
93 * Creates a new #PurpleImage object with contents of @data buffer.
95 * The @data buffer is owned by #PurpleImage object, so you might want
96 * to #g_memdup it first.
98 * Returns: the new #PurpleImage.
100 PurpleImage *purple_image_new_from_data(const guint8 *data, gsize length);
103 * purple_image_new_take_data:
104 * @data: (transfer full): the pointer to the image data buffer.
105 * @length: the length of @data.
107 * Creates a new #PurpleImage object with contents of @data buffer.
109 * The @data buffer is owned by #PurpleImage object, so you might want
110 * to #g_memdup it first.
112 * Returns: the new #PurpleImage.
114 PurpleImage *purple_image_new_take_data(guint8 *data, gsize length);
117 * purple_image_save:
118 * @image: the image.
119 * @path: destination of a saved image file.
121 * Saves an @image to the disk.
123 * Returns: %TRUE if succeeded, %FALSE otherwise.
125 gboolean purple_image_save(PurpleImage *image, const gchar *path);
128 * purple_image_get_contents:
129 * @image: The #PurpleImage.
131 * Returns a new reference to the #GBytes that contains the image data.
133 * Returns: (transfer full): A #GBytes containing the image data.
135 GBytes *purple_image_get_contents(PurpleImage *image);
139 * purple_image_get_path:
140 * @image: the image.
142 * Returns the physical path of the @image file. It is set only, if the @image is
143 * really backed by an existing file. In the other case it returns %NULL.
145 * Returns: the physical path of the @image, or %NULL.
147 const gchar *purple_image_get_path(PurpleImage *image);
150 * purple_image_get_data_size:
151 * @image: the image.
153 * Returns the size of @image's data.
155 * Returns: the size of data, or 0 in case of failure.
157 gsize purple_image_get_data_size(PurpleImage *image);
160 * purple_image_get_data:
161 * @image: the image.
163 * Returns the pointer to the buffer containing image data.
165 * Returns: (transfer none): the @image data.
167 gconstpointer purple_image_get_data(PurpleImage *image);
170 * purple_image_get_extension:
171 * @image: the image.
173 * Guesses the @image format based on its contents.
175 * Returns: (transfer none): the file extension suitable for @image format.
177 const gchar *purple_image_get_extension(PurpleImage *image);
180 * purple_image_get_mimetype:
181 * @image: the image.
183 * Guesses the @image mime-type based on its contents.
185 * Returns: (transfer none): the mime-type suitable for @image format.
187 const gchar *purple_image_get_mimetype(PurpleImage *image);
190 * purple_image_generate_filename:
191 * @image: the image.
193 * Calculates almost-unique filename by computing checksum from file contents
194 * and appending a suitable extension. You should not assume the checksum
195 * is SHA-1, because it may change in the future.
197 * Returns: (transfer none): the generated file name.
199 const gchar *purple_image_generate_filename(PurpleImage *image);
202 * purple_image_set_friendly_filename:
203 * @image: the image.
204 * @filename: the friendly filename.
206 * Sets the "friendly filename" for the @image. This don't have to be a real
207 * name, because it's used for displaying or as a default file name when the
208 * user wants to save the @image to the disk.
210 * The provided @filename may either be a full path, or contain
211 * filesystem-unfriendly characters, because it will be reformatted.
213 void purple_image_set_friendly_filename(PurpleImage *image, const gchar *filename);
216 * purple_image_get_friendly_filename:
217 * @image: the image.
219 * Returns the "friendly filename" for the @image, to be displayed or used as
220 * a default name when saving a file to the disk.
221 * See #purple_image_set_friendly_filename.
223 * If the friendly filename was not set, it will be generated with
224 * #purple_image_generate_filename.
226 * Returns: (transfer none): the friendly filename.
228 const gchar *purple_image_get_friendly_filename(PurpleImage *image);
230 G_END_DECLS
232 #endif /* PURPLE_IMAGE_H */