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
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
28 * @section_id: libpurple-image
29 * @short_description: implementation-independent image data container
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 GObjectClass parent_class
;
48 void (*purple_reserved1
)(void);
49 void (*purple_reserved2
)(void);
50 void (*purple_reserved3
)(void);
51 void (*purple_reserved4
)(void);
57 * purple_image_get_type:
59 * Returns: the #GType for an image.
61 G_DECLARE_DERIVABLE_TYPE(PurpleImage
, purple_image
, PURPLE
, IMAGE
, GObject
)
64 * purple_image_new_from_bytes:
65 * @bytes: (transfer none): A #GBytes containing the raw image data.
67 * Loads a raw image data as a new #PurpleImage object.
69 * Returns: the new #PurpleImage.
71 PurpleImage
*purple_image_new_from_bytes(GBytes
*bytes
);
74 * purple_image_new_from_file:
75 * @path: the path to the image file.
76 * @error: (optional) (out): An optional return address for a #GError
78 * Loads an image file as a new #PurpleImage object. The @path must exists, be
79 * readable and should point to a valid image file. If you don't set @be_eager
80 * parameter, there will be a risk that file will be removed from disk before
81 * you access its data.
83 * Returns: the new #PurpleImage.
85 PurpleImage
*purple_image_new_from_file(const gchar
*path
, GError
**error
);
88 * purple_image_new_from_data:
89 * @data: the pointer to the image data buffer.
90 * @length: the length of @data.
92 * Creates a new #PurpleImage object with contents of @data buffer.
94 * The @data buffer is owned by #PurpleImage object, so you might want
95 * to #g_memdup it first.
97 * Returns: the new #PurpleImage.
99 PurpleImage
*purple_image_new_from_data(const guint8
*data
, gsize length
);
102 * purple_image_new_take_data:
103 * @data: (transfer full): the pointer to the image data buffer.
104 * @length: the length of @data.
106 * Creates a new #PurpleImage object with contents of @data buffer.
108 * The @data buffer is owned by #PurpleImage object, so you might want
109 * to #g_memdup it first.
111 * Returns: the new #PurpleImage.
113 PurpleImage
*purple_image_new_take_data(guint8
*data
, gsize length
);
118 * @path: destination of a saved image file.
120 * Saves an @image to the disk.
122 * Returns: %TRUE if succeeded, %FALSE otherwise.
124 gboolean
purple_image_save(PurpleImage
*image
, const gchar
*path
);
127 * purple_image_get_contents:
128 * @image: The #PurpleImage.
130 * Returns a new reference to the #GBytes that contains the image data.
132 * Returns: (transfer full): A #GBytes containing the image data.
134 GBytes
*purple_image_get_contents(PurpleImage
*image
);
138 * purple_image_get_path:
141 * Returns the physical path of the @image file. It is set only, if the @image is
142 * really backed by an existing file. In the other case it returns %NULL.
144 * Returns: the physical path of the @image, or %NULL.
146 const gchar
*purple_image_get_path(PurpleImage
*image
);
149 * purple_image_get_data_size:
152 * Returns the size of @image's data.
154 * Returns: the size of data, or 0 in case of failure.
156 gsize
purple_image_get_data_size(PurpleImage
*image
);
159 * purple_image_get_data:
162 * Returns the pointer to the buffer containing image data.
164 * Returns: (transfer none): the @image data.
166 gconstpointer
purple_image_get_data(PurpleImage
*image
);
169 * purple_image_get_extension:
172 * Guesses the @image format based on its contents.
174 * Returns: (transfer none): the file extension suitable for @image format.
176 const gchar
*purple_image_get_extension(PurpleImage
*image
);
179 * purple_image_get_mimetype:
182 * Guesses the @image mime-type based on its contents.
184 * Returns: (transfer none): the mime-type suitable for @image format.
186 const gchar
*purple_image_get_mimetype(PurpleImage
*image
);
189 * purple_image_generate_filename:
192 * Calculates almost-unique filename by computing checksum from file contents
193 * and appending a suitable extension. You should not assume the checksum
194 * is SHA-1, because it may change in the future.
196 * Returns: (transfer none): the generated file name.
198 const gchar
*purple_image_generate_filename(PurpleImage
*image
);
201 * purple_image_set_friendly_filename:
203 * @filename: the friendly filename.
205 * Sets the "friendly filename" for the @image. This don't have to be a real
206 * name, because it's used for displaying or as a default file name when the
207 * user wants to save the @image to the disk.
209 * The provided @filename may either be a full path, or contain
210 * filesystem-unfriendly characters, because it will be reformatted.
212 void purple_image_set_friendly_filename(PurpleImage
*image
, const gchar
*filename
);
215 * purple_image_get_friendly_filename:
218 * Returns the "friendly filename" for the @image, to be displayed or used as
219 * a default name when saving a file to the disk.
220 * See #purple_image_set_friendly_filename.
222 * If the friendly filename was not set, it will be generated with
223 * #purple_image_generate_filename.
225 * Returns: (transfer none): the friendly filename.
227 const gchar
*purple_image_get_friendly_filename(PurpleImage
*image
);
231 #endif /* PURPLE_IMAGE_H */