3 * Pidgin 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 #include "pidgin/pidgingdkpixbuf.h"
25 pidgin_gdk_pixbuf_new_from_image(PurpleImage
*image
, GError
**error
) {
26 GdkPixbufLoader
*loader
= NULL
;
27 GdkPixbuf
*pixbuf
= NULL
;
29 gboolean success
= FALSE
;
31 g_return_val_if_fail(PURPLE_IS_IMAGE(image
), NULL
);
33 data
= purple_image_get_contents(image
);
34 success
= gdk_pixbuf_loader_write_bytes(loader
, data
, error
);
38 if(error
!= NULL
&& *error
!= NULL
) {
39 g_object_unref(G_OBJECT(loader
));
44 if(gdk_pixbuf_loader_close(loader
, error
)) {
45 pixbuf
= gdk_pixbuf_loader_get_pixbuf(loader
);
47 pixbuf
= g_object_ref(pixbuf
);
51 g_object_unref(G_OBJECT(loader
));
57 void pidgin_gdk_pixbuf_make_round(GdkPixbuf
*pixbuf
) {
58 gint width
, height
, rowstride
;
61 if (!gdk_pixbuf_get_has_alpha(pixbuf
)) {
65 width
= gdk_pixbuf_get_width(pixbuf
);
66 height
= gdk_pixbuf_get_height(pixbuf
);
67 rowstride
= gdk_pixbuf_get_rowstride(pixbuf
);
68 pixels
= gdk_pixbuf_get_pixels(pixbuf
);
70 if (width
< 6 || height
< 6) {
74 /* The following code will conver the alpha of the pixel data in all
75 * corners to look something like the following diagram.
77 * 00 80 c0 FF FF c0 80 00
78 * 80 FF FF FF FF FF FF 80
79 * c0 FF FF FF FF FF FF c0
80 * FF FF FF FF FF FF FF FF
81 * FF FF FF FF FF FF FF FF
82 * c0 FF FF FF FF FF FF c0
83 * 80 FF FF FF FF FF FF 80
84 * 00 80 c0 FF FF c0 80 00
91 pixels
[rowstride
+ 3] = 0x80;
92 pixels
[rowstride
* 2 + 3] = 0xC0;
95 pixels
[width
* 4 - 1] = 0;
96 pixels
[width
* 4 - 5] = 0x80;
97 pixels
[width
* 4 - 9] = 0xC0;
98 pixels
[rowstride
+ (width
* 4) - 1] = 0x80;
99 pixels
[(2 * rowstride
) + (width
* 4) - 1] = 0xC0;
102 pixels
[(height
- 1) * rowstride
+ 3] = 0;
103 pixels
[(height
- 1) * rowstride
+ 7] = 0x80;
104 pixels
[(height
- 1) * rowstride
+ 11] = 0xC0;
105 pixels
[(height
- 2) * rowstride
+ 3] = 0x80;
106 pixels
[(height
- 3) * rowstride
+ 3] = 0xC0;
109 pixels
[height
* rowstride
- 1] = 0;
110 pixels
[(height
- 1) * rowstride
- 1] = 0x80;
111 pixels
[(height
- 2) * rowstride
- 1] = 0xC0;
112 pixels
[height
* rowstride
- 5] = 0x80;
113 pixels
[height
* rowstride
- 9] = 0xC0;
117 pidgin_gdk_pixbuf_is_opaque(GdkPixbuf
*pixbuf
) {
118 gint height
, rowstride
, i
;
122 if (!gdk_pixbuf_get_has_alpha(pixbuf
)) {
126 height
= gdk_pixbuf_get_height (pixbuf
);
127 rowstride
= gdk_pixbuf_get_rowstride (pixbuf
);
128 pixels
= gdk_pixbuf_get_pixels (pixbuf
);
130 /* check the top row */
132 for (i
= 3; i
< rowstride
; i
+=4) {
138 /* check the left and right sides */
139 for (i
= 1; i
< height
- 1; i
++) {
140 row
= pixels
+ (i
* rowstride
);
141 if (row
[3] < 0xfe || row
[rowstride
- 1] < 0xfe) {
146 /* check the bottom */
147 row
= pixels
+ ((height
- 1) * rowstride
);
148 for (i
= 3; i
< rowstride
; i
+= 4) {