libpurple/purplegdkpixbuf.c

Tue, 20 Feb 2024 00:55:28 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 20 Feb 2024 00:55:28 -0600
changeset 42592
6b65c0e4ba15
parent 42182
3fc2d2b7b7a8
child 42594
eddde70cedd8
permissions
-rw-r--r--

Remove unnecessary casts for GObject methods

Testing Done:
Compiled with the turtles and verified no new warnings appeared.

Reviewed at https://reviews.imfreedom.org/r/2956/

41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
1 /*
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
2 * Purple - Internet Messaging Library
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
23 #include "libpurple/purplegdkpixbuf.h"
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
25 #include "debug.h"
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
27 void purple_gdk_pixbuf_make_round(GdkPixbuf *pixbuf) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 gint width, height, rowstride;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 guchar *pixels;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 return;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 width = gdk_pixbuf_get_width(pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 height = gdk_pixbuf_get_height(pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 rowstride = gdk_pixbuf_get_rowstride(pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 pixels = gdk_pixbuf_get_pixels(pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
40 if (width < 6 || height < 6) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 return;
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
42 }
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43
41086
631e6cba8635 Fix typos in Pidgin
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39571
diff changeset
44 /* The following code will convert the alpha of the pixel data in all
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 * corners to look something like the following diagram.
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 *
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 * 00 80 c0 FF FF c0 80 00
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 * 80 FF FF FF FF FF FF 80
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 * c0 FF FF FF FF FF FF c0
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 * FF FF FF FF FF FF FF FF
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 * FF FF FF FF FF FF FF FF
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 * c0 FF FF FF FF FF FF c0
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 * 80 FF FF FF FF FF FF 80
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 * 00 80 c0 FF FF c0 80 00
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 /* Top left */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 pixels[3] = 0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 pixels[7] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 pixels[11] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 pixels[rowstride + 3] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 pixels[rowstride * 2 + 3] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 /* Top right */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 pixels[width * 4 - 1] = 0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 pixels[width * 4 - 5] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 pixels[width * 4 - 9] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 pixels[rowstride + (width * 4) - 1] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 pixels[(2 * rowstride) + (width * 4) - 1] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 /* Bottom left */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 pixels[(height - 1) * rowstride + 3] = 0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 pixels[(height - 1) * rowstride + 7] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 pixels[(height - 1) * rowstride + 11] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 pixels[(height - 2) * rowstride + 3] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 pixels[(height - 3) * rowstride + 3] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 /* Bottom right */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 pixels[height * rowstride - 1] = 0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 pixels[(height - 1) * rowstride - 1] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 pixels[(height - 2) * rowstride - 1] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 pixels[height * rowstride - 5] = 0x80;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 pixels[height * rowstride - 9] = 0xC0;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 gboolean
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
87 purple_gdk_pixbuf_is_opaque(GdkPixbuf *pixbuf) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 gint height, rowstride, i;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 guchar *pixels;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 guchar *row;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
92 if (!gdk_pixbuf_get_has_alpha(pixbuf)) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 return TRUE;
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
94 }
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 height = gdk_pixbuf_get_height (pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 pixels = gdk_pixbuf_get_pixels (pixbuf);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 /* check the top row */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 row = pixels;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 for (i = 3; i < rowstride; i+=4) {
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
103 if (row[i] < 0xfe) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 return FALSE;
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
105 }
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 /* check the left and right sides */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 for (i = 1; i < height - 1; i++) {
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 row = pixels + (i * rowstride);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 if (row[3] < 0xfe || row[rowstride - 1] < 0xfe) {
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 return FALSE;
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
113 }
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 /* check the bottom */
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 row = pixels + ((height - 1) * rowstride);
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 for (i = 3; i < rowstride; i += 4) {
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
119 if (row[i] < 0xfe) {
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 return FALSE;
39571
b88f466a4a4d Add some missing braces and fix some errant spaces
Gary Kramlich <grim@reaperworld.com>
parents: 39568
diff changeset
121 }
39568
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 return TRUE;
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 }
f4714f1de6d0 Start cleaning up gtkutils by moving functions to individual files
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
127 static GObject *purple_gdk_pixbuf_from_data_helper(const guchar *buf, gsize count, gboolean animated)
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
128 {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
129 GObject *pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
130 GdkPixbufLoader *loader;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
131 GError *error = NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
132
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
133 loader = gdk_pixbuf_loader_new();
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
134
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
135 if (!gdk_pixbuf_loader_write(loader, buf, count, &error) || error) {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
136 purple_debug_warning("gtkutils", "gdk_pixbuf_loader_write() "
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
137 "failed with size=%" G_GSIZE_FORMAT ": %s\n", count,
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
138 error ? error->message : "(no error message)");
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
139 g_clear_error(&error);
42592
6b65c0e4ba15 Remove unnecessary casts for GObject methods
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
140 g_object_unref(loader);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
141 return NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
142 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
143
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
144 if (!gdk_pixbuf_loader_close(loader, &error) || error) {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
145 purple_debug_warning("gtkutils", "gdk_pixbuf_loader_close() "
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
146 "failed for image of size %" G_GSIZE_FORMAT ": %s\n", count,
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
147 error ? error->message : "(no error message)");
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
148 g_clear_error(&error);
42592
6b65c0e4ba15 Remove unnecessary casts for GObject methods
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
149 g_object_unref(loader);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
150 return NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
151 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
152
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
153 if (animated)
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
154 pixbuf = G_OBJECT(gdk_pixbuf_loader_get_animation(loader));
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
155 else
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
156 pixbuf = G_OBJECT(gdk_pixbuf_loader_get_pixbuf(loader));
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
157 if (!pixbuf) {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
158 purple_debug_warning("gtkutils", "%s() returned NULL for image "
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
159 "of size %" G_GSIZE_FORMAT "\n",
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
160 animated ? "gdk_pixbuf_loader_get_animation"
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
161 : "gdk_pixbuf_loader_get_pixbuf", count);
42592
6b65c0e4ba15 Remove unnecessary casts for GObject methods
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
162 g_object_unref(loader);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
163 return NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
164 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
165
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
166 g_object_ref(pixbuf);
42592
6b65c0e4ba15 Remove unnecessary casts for GObject methods
Gary Kramlich <grim@reaperworld.com>
parents: 42182
diff changeset
167 g_object_unref(loader);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
168
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
169 return pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
170 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
171
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
172 GdkPixbuf *purple_gdk_pixbuf_from_data(const guchar *buf, gsize count)
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
173 {
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
174 return GDK_PIXBUF(purple_gdk_pixbuf_from_data_helper(buf, count, FALSE));
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
175 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
176
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
177 GdkPixbuf *
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
178 purple_gdk_pixbuf_from_image(PurpleImage *image)
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
179 {
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
180 return purple_gdk_pixbuf_from_data(purple_image_get_data(image),
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
181 purple_image_get_data_size(image));
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
182 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
183
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
184 GdkPixbuf *purple_gdk_pixbuf_new_from_file(const gchar *filename)
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
185 {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
186 GdkPixbuf *pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
187 GError *error = NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
188
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
189 g_return_val_if_fail(filename != NULL, NULL);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
190 g_return_val_if_fail(filename[0] != '\0', NULL);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
191
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
192 pixbuf = gdk_pixbuf_new_from_file(filename, &error);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
193 if (!pixbuf || error) {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
194 purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file() "
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
195 "returned %s for file %s: %s\n",
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
196 pixbuf ? "something" : "nothing",
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
197 filename,
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
198 error ? error->message : "(no error message)");
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
199 g_clear_error(&error);
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
200 g_clear_object(&pixbuf);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
201 return NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
202 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
203
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
204 return pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
205 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
206
41319
04d027ed3d63 Add gdk-pixbuf as a libpurple dependency and move helpers from pidgin to purple
Gary Kramlich <grim@reaperworld.com>
parents: 41144
diff changeset
207 GdkPixbuf *purple_gdk_pixbuf_new_from_file_at_size(const char *filename, int width, int height)
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
208 {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
209 GdkPixbuf *pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
210 GError *error = NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
211
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
212 g_return_val_if_fail(filename != NULL, NULL);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
213 g_return_val_if_fail(filename[0] != '\0', NULL);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
214
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
215 pixbuf = gdk_pixbuf_new_from_file_at_size(filename,
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
216 width, height, &error);
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
217 if (!pixbuf || error) {
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
218 purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_size() "
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
219 "returned %s for file %s: %s\n",
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
220 pixbuf ? "something" : "nothing",
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
221 filename,
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
222 error ? error->message : "(no error message)");
42182
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
223 g_clear_error(&error);
3fc2d2b7b7a8 Fix leaked errors
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41319
diff changeset
224 g_clear_object(&pixbuf);
41144
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
225 return NULL;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
226 }
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
227
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
228 return pixbuf;
910bdda75c74 Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41086
diff changeset
229 }

mercurial