grim/pidgin

910bdda75c74
Parents 8fa1f37d32f2
Children 92d4104b5d9b
Move the pidgin_pixbuf stuff to pidgingdkpixbuf.[ch]

Testing Done:
Compiled

Reviewed at https://reviews.imfreedom.org/r/1100/
--- a/pidgin/gtkaccount.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/gtkaccount.c Tue Oct 26 04:05:39 2021 -0500
@@ -36,6 +36,7 @@
#include "pidgincore.h"
#include "pidgindialog.h"
#include "minidialog.h"
+#include "pidgingdkpixbuf.h"
#include "pidginprotocolchooser.h"
enum
--- a/pidgin/gtkrequest.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/gtkrequest.c Tue Oct 26 04:05:39 2021 -0500
@@ -33,6 +33,7 @@
#include "pidginaccountstore.h"
#include "pidgincore.h"
#include "pidgindialog.h"
+#include "pidgingdkpixbuf.h"
#include <gdk/gdkkeysyms.h>
--- a/pidgin/gtkutils.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/gtkutils.c Tue Oct 26 04:05:39 2021 -0500
@@ -47,6 +47,7 @@
#include "gtkutils.h"
#include "minidialog.h"
#include "pidgincore.h"
+#include "pidgingdkpixbuf.h"
/******************************************************************************
* Enums
@@ -1941,194 +1942,6 @@
#endif
}
-static GObject *pidgin_pixbuf_from_data_helper(const guchar *buf, gsize count, gboolean animated)
-{
- GObject *pixbuf;
- GdkPixbufLoader *loader;
- GError *error = NULL;
-
- loader = gdk_pixbuf_loader_new();
-
- if (!gdk_pixbuf_loader_write(loader, buf, count, &error) || error) {
- purple_debug_warning("gtkutils", "gdk_pixbuf_loader_write() "
- "failed with size=%" G_GSIZE_FORMAT ": %s\n", count,
- error ? error->message : "(no error message)");
- if (error)
- g_error_free(error);
- g_object_unref(G_OBJECT(loader));
- return NULL;
- }
-
- if (!gdk_pixbuf_loader_close(loader, &error) || error) {
- purple_debug_warning("gtkutils", "gdk_pixbuf_loader_close() "
- "failed for image of size %" G_GSIZE_FORMAT ": %s\n", count,
- error ? error->message : "(no error message)");
- if (error)
- g_error_free(error);
- g_object_unref(G_OBJECT(loader));
- return NULL;
- }
-
- if (animated)
- pixbuf = G_OBJECT(gdk_pixbuf_loader_get_animation(loader));
- else
- pixbuf = G_OBJECT(gdk_pixbuf_loader_get_pixbuf(loader));
- if (!pixbuf) {
- purple_debug_warning("gtkutils", "%s() returned NULL for image "
- "of size %" G_GSIZE_FORMAT "\n",
- animated ? "gdk_pixbuf_loader_get_animation"
- : "gdk_pixbuf_loader_get_pixbuf", count);
- g_object_unref(G_OBJECT(loader));
- return NULL;
- }
-
- g_object_ref(pixbuf);
- g_object_unref(G_OBJECT(loader));
-
- return pixbuf;
-}
-
-GdkPixbuf *pidgin_pixbuf_from_data(const guchar *buf, gsize count)
-{
- return GDK_PIXBUF(pidgin_pixbuf_from_data_helper(buf, count, FALSE));
-}
-
-GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count)
-{
- return GDK_PIXBUF_ANIMATION(pidgin_pixbuf_from_data_helper(buf, count, TRUE));
-}
-
-GdkPixbuf *
-pidgin_pixbuf_from_image(PurpleImage *image)
-{
- return pidgin_pixbuf_from_data(purple_image_get_data(image),
- purple_image_get_data_size(image));
-}
-
-GdkPixbuf *pidgin_pixbuf_new_from_file(const gchar *filename)
-{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
-
- g_return_val_if_fail(filename != NULL, NULL);
- g_return_val_if_fail(filename[0] != '\0', NULL);
-
- pixbuf = gdk_pixbuf_new_from_file(filename, &error);
- if (!pixbuf || error) {
- purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file() "
- "returned %s for file %s: %s\n",
- pixbuf ? "something" : "nothing",
- filename,
- error ? error->message : "(no error message)");
- if (error)
- g_error_free(error);
- if (pixbuf)
- g_object_unref(G_OBJECT(pixbuf));
- return NULL;
- }
-
- return pixbuf;
-}
-
-GdkPixbuf *pidgin_pixbuf_new_from_file_at_size(const char *filename, int width, int height)
-{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
-
- g_return_val_if_fail(filename != NULL, NULL);
- g_return_val_if_fail(filename[0] != '\0', NULL);
-
- pixbuf = gdk_pixbuf_new_from_file_at_size(filename,
- width, height, &error);
- if (!pixbuf || error) {
- purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_size() "
- "returned %s for file %s: %s\n",
- pixbuf ? "something" : "nothing",
- filename,
- error ? error->message : "(no error message)");
- if (error)
- g_error_free(error);
- if (pixbuf)
- g_object_unref(G_OBJECT(pixbuf));
- return NULL;
- }
-
- return pixbuf;
-}
-
-GdkPixbuf *pidgin_pixbuf_new_from_file_at_scale(const char *filename, int width, int height, gboolean preserve_aspect_ratio)
-{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
-
- g_return_val_if_fail(filename != NULL, NULL);
- g_return_val_if_fail(filename[0] != '\0', NULL);
-
- pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
- width, height, preserve_aspect_ratio, &error);
- if (!pixbuf || error) {
- purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_scale() "
- "returned %s for file %s: %s\n",
- pixbuf ? "something" : "nothing",
- filename,
- error ? error->message : "(no error message)");
- if (error)
- g_error_free(error);
- if (pixbuf)
- g_object_unref(G_OBJECT(pixbuf));
- return NULL;
- }
-
- return pixbuf;
-}
-
-GdkPixbuf *
-pidgin_pixbuf_scale_down(GdkPixbuf *src, guint max_width, guint max_height,
- GdkInterpType interp_type, gboolean preserve_ratio)
-{
- guint cur_w, cur_h;
- GdkPixbuf *dst;
-
- g_return_val_if_fail(src != NULL, NULL);
-
- if (max_width == 0 || max_height == 0) {
- g_object_unref(src);
- g_return_val_if_reached(NULL);
- }
-
- cur_w = gdk_pixbuf_get_width(src);
- cur_h = gdk_pixbuf_get_height(src);
-
- if (cur_w <= max_width && cur_h <= max_height)
- return src;
-
- /* cur_ratio = cur_w / cur_h
- * max_ratio = max_w / max_h
- */
-
- if (!preserve_ratio) {
- cur_w = MIN(cur_w, max_width);
- cur_h = MIN(cur_h, max_height);
- } else if ((guint64)cur_w * max_height > (guint64)max_width * cur_h) {
- /* cur_w / cur_h > max_width / max_height */
- cur_h = (guint64)max_width * cur_h / cur_w;
- cur_w = max_width;
- } else {
- cur_w = (guint64)max_height * cur_w / cur_h;
- cur_h = max_height;
- }
-
- if (cur_w <= 0)
- cur_w = 1;
- if (cur_h <= 0)
- cur_h = 1;
-
- dst = gdk_pixbuf_scale_simple(src, cur_w, cur_h, interp_type);
- g_object_unref(src);
-
- return dst;
-}
-
GtkWidget *
pidgin_make_scrollable(GtkWidget *child, GtkPolicyType hscrollbar_policy, GtkPolicyType vscrollbar_policy, GtkShadowType shadow_type, int width, int height)
{
--- a/pidgin/gtkutils.h Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/gtkutils.h Tue Oct 26 04:05:39 2021 -0500
@@ -422,138 +422,6 @@
GtkWidget *pidgin_add_widget_to_vbox(GtkBox *vbox, const char *widget_label, GtkSizeGroup *sg, GtkWidget *widget, gboolean expand, GtkWidget **p_label);
/**
- * pidgin_pixbuf_from_data:
- * @buf: The raw binary image data.
- * @count: The length of buf in bytes.
- *
- * Create a GdkPixbuf from a chunk of image data.
- *
- * Returns: (transfer full): A GdkPixbuf created from the image data, or NULL if
- * there was an error parsing the data.
- */
-GdkPixbuf *pidgin_pixbuf_from_data(const guchar *buf, gsize count);
-
-/**
- * pidgin_pixbuf_anim_from_data:
- * @buf: The raw binary image data.
- * @count: The length of buf in bytes.
- *
- * Create a GdkPixbufAnimation from a chunk of image data.
- *
- * Returns: (transfer full): A GdkPixbufAnimation created from the image data, or NULL if
- * there was an error parsing the data.
- */
-GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count);
-
-/**
- * pidgin_pixbuf_from_image:
- * @image: a PurpleImage.
- *
- * Create a GdkPixbuf from a PurpleImage.
- *
- * Returns: (transfer full): a GdkPixbuf created from the @image.
- */
-GdkPixbuf *
-pidgin_pixbuf_from_image(PurpleImage *image);
-
-/**
- * pidgin_pixbuf_new_from_file:
- * @filename: Name of file to load, in the GLib file name encoding
- *
- * Helper function that calls gdk_pixbuf_new_from_file() and checks both
- * the return code and the GError and returns NULL if either one failed.
- *
- * The gdk-pixbuf documentation implies that it is sufficient to check
- * the return value of gdk_pixbuf_new_from_file() to determine
- * whether the image was able to be loaded. However, this is not the case
- * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
- * cases a GdkPixbuf object is returned that will cause some operations
- * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
- * infinite loop.
- *
- * This function shouldn't be necessary once Pidgin requires a version of
- * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
- * nice to keep this function around for the debug message that it logs.
- *
- * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
- * a warning is logged.
- */
-GdkPixbuf *pidgin_pixbuf_new_from_file(const char *filename);
-
-/**
- * pidgin_pixbuf_new_from_file_at_size:
- * @filename: Name of file to load, in the GLib file name encoding
- * @width: The width the image should have or -1 to not constrain the width
- * @height: The height the image should have or -1 to not constrain the height
- *
- * Helper function that calls gdk_pixbuf_new_from_file_at_size() and checks
- * both the return code and the GError and returns NULL if either one failed.
- *
- * The gdk-pixbuf documentation implies that it is sufficient to check
- * the return value of gdk_pixbuf_new_from_file_at_size() to determine
- * whether the image was able to be loaded. However, this is not the case
- * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
- * cases a GdkPixbuf object is returned that will cause some operations
- * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
- * infinite loop.
- *
- * This function shouldn't be necessary once Pidgin requires a version of
- * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
- * nice to keep this function around for the debug message that it logs.
- *
- * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
- * a warning is logged.
- */
-GdkPixbuf *pidgin_pixbuf_new_from_file_at_size(const char *filename, int width, int height);
-
-/**
- * pidgin_pixbuf_new_from_file_at_scale:
- * @filename: Name of file to load, in the GLib file name encoding
- * @width: The width the image should have or -1 to not constrain the width
- * @height: The height the image should have or -1 to not constrain the height
- * @preserve_aspect_ratio: TRUE to preserve the image's aspect ratio
- *
- * Helper function that calls gdk_pixbuf_new_from_file_at_scale() and checks
- * both the return code and the GError and returns NULL if either one failed.
- *
- * The gdk-pixbuf documentation implies that it is sufficient to check
- * the return value of gdk_pixbuf_new_from_file_at_scale() to determine
- * whether the image was able to be loaded. However, this is not the case
- * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
- * cases a GdkPixbuf object is returned that will cause some operations
- * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
- * infinite loop.
- *
- * This function shouldn't be necessary once Pidgin requires a version of
- * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
- * nice to keep this function around for the debug message that it logs.
- *
- * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
- * a warning is logged.
- */
-GdkPixbuf *pidgin_pixbuf_new_from_file_at_scale(const char *filename, int width, int height, gboolean preserve_aspect_ratio);
-
-/**
- * pidgin_pixbuf_scale_down:
- * @src: The source image.
- * @max_width: Maximum width in px.
- * @max_height: Maximum height in px.
- * @interp_type: Interpolation method.
- * @preserve_ratio: %TRUE to preserve image's aspect ratio.
- *
- * Scales the image to the desired dimensions. If image is smaller, it will be
- * returned without modifications.
- *
- * If new image is created, @src reference count will be decreased and new image
- * with a ref count of 1 will be returned.
- *
- * Returns: (transfer full): The image with proper sizing. %NULL in case of error.
- */
-GdkPixbuf *
-pidgin_pixbuf_scale_down(GdkPixbuf *src, guint max_width, guint max_height,
- GdkInterpType interp_type, gboolean preserve_ratio);
-
-/**
* pidgin_make_scrollable:
* @child: The child widget
* @hscrollbar_policy: Horizontal scrolling policy
--- a/pidgin/gtkxfer.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/gtkxfer.c Tue Oct 26 04:05:39 2021 -0500
@@ -28,6 +28,7 @@
#include "gtkxfer.h"
#include "gtkutils.h"
#include "pidgincore.h"
+#include "pidgingdkpixbuf.h"
#ifdef _WIN32
# include <shellapi.h>
--- a/pidgin/pidgingdkpixbuf.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/pidgingdkpixbuf.c Tue Oct 26 04:05:39 2021 -0500
@@ -154,3 +154,190 @@
return TRUE;
}
+static GObject *pidgin_pixbuf_from_data_helper(const guchar *buf, gsize count, gboolean animated)
+{
+ GObject *pixbuf;
+ GdkPixbufLoader *loader;
+ GError *error = NULL;
+
+ loader = gdk_pixbuf_loader_new();
+
+ if (!gdk_pixbuf_loader_write(loader, buf, count, &error) || error) {
+ purple_debug_warning("gtkutils", "gdk_pixbuf_loader_write() "
+ "failed with size=%" G_GSIZE_FORMAT ": %s\n", count,
+ error ? error->message : "(no error message)");
+ if (error)
+ g_error_free(error);
+ g_object_unref(G_OBJECT(loader));
+ return NULL;
+ }
+
+ if (!gdk_pixbuf_loader_close(loader, &error) || error) {
+ purple_debug_warning("gtkutils", "gdk_pixbuf_loader_close() "
+ "failed for image of size %" G_GSIZE_FORMAT ": %s\n", count,
+ error ? error->message : "(no error message)");
+ if (error)
+ g_error_free(error);
+ g_object_unref(G_OBJECT(loader));
+ return NULL;
+ }
+
+ if (animated)
+ pixbuf = G_OBJECT(gdk_pixbuf_loader_get_animation(loader));
+ else
+ pixbuf = G_OBJECT(gdk_pixbuf_loader_get_pixbuf(loader));
+ if (!pixbuf) {
+ purple_debug_warning("gtkutils", "%s() returned NULL for image "
+ "of size %" G_GSIZE_FORMAT "\n",
+ animated ? "gdk_pixbuf_loader_get_animation"
+ : "gdk_pixbuf_loader_get_pixbuf", count);
+ g_object_unref(G_OBJECT(loader));
+ return NULL;
+ }
+
+ g_object_ref(pixbuf);
+ g_object_unref(G_OBJECT(loader));
+
+ return pixbuf;
+}
+
+GdkPixbuf *pidgin_pixbuf_from_data(const guchar *buf, gsize count)
+{
+ return GDK_PIXBUF(pidgin_pixbuf_from_data_helper(buf, count, FALSE));
+}
+
+GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count)
+{
+ return GDK_PIXBUF_ANIMATION(pidgin_pixbuf_from_data_helper(buf, count, TRUE));
+}
+
+GdkPixbuf *
+pidgin_pixbuf_from_image(PurpleImage *image)
+{
+ return pidgin_pixbuf_from_data(purple_image_get_data(image),
+ purple_image_get_data_size(image));
+}
+
+GdkPixbuf *pidgin_pixbuf_new_from_file(const gchar *filename)
+{
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ g_return_val_if_fail(filename != NULL, NULL);
+ g_return_val_if_fail(filename[0] != '\0', NULL);
+
+ pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+ if (!pixbuf || error) {
+ purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file() "
+ "returned %s for file %s: %s\n",
+ pixbuf ? "something" : "nothing",
+ filename,
+ error ? error->message : "(no error message)");
+ if (error)
+ g_error_free(error);
+ if (pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+ return NULL;
+ }
+
+ return pixbuf;
+}
+
+GdkPixbuf *pidgin_pixbuf_new_from_file_at_size(const char *filename, int width, int height)
+{
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ g_return_val_if_fail(filename != NULL, NULL);
+ g_return_val_if_fail(filename[0] != '\0', NULL);
+
+ pixbuf = gdk_pixbuf_new_from_file_at_size(filename,
+ width, height, &error);
+ if (!pixbuf || error) {
+ purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_size() "
+ "returned %s for file %s: %s\n",
+ pixbuf ? "something" : "nothing",
+ filename,
+ error ? error->message : "(no error message)");
+ if (error)
+ g_error_free(error);
+ if (pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+ return NULL;
+ }
+
+ return pixbuf;
+}
+
+GdkPixbuf *pidgin_pixbuf_new_from_file_at_scale(const char *filename, int width, int height, gboolean preserve_aspect_ratio)
+{
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ g_return_val_if_fail(filename != NULL, NULL);
+ g_return_val_if_fail(filename[0] != '\0', NULL);
+
+ pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
+ width, height, preserve_aspect_ratio, &error);
+ if (!pixbuf || error) {
+ purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_scale() "
+ "returned %s for file %s: %s\n",
+ pixbuf ? "something" : "nothing",
+ filename,
+ error ? error->message : "(no error message)");
+ if (error)
+ g_error_free(error);
+ if (pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+ return NULL;
+ }
+
+ return pixbuf;
+}
+
+GdkPixbuf *
+pidgin_pixbuf_scale_down(GdkPixbuf *src, guint max_width, guint max_height,
+ GdkInterpType interp_type, gboolean preserve_ratio)
+{
+ guint cur_w, cur_h;
+ GdkPixbuf *dst;
+
+ g_return_val_if_fail(src != NULL, NULL);
+
+ if (max_width == 0 || max_height == 0) {
+ g_object_unref(src);
+ g_return_val_if_reached(NULL);
+ }
+
+ cur_w = gdk_pixbuf_get_width(src);
+ cur_h = gdk_pixbuf_get_height(src);
+
+ if (cur_w <= max_width && cur_h <= max_height)
+ return src;
+
+ /* cur_ratio = cur_w / cur_h
+ * max_ratio = max_w / max_h
+ */
+
+ if (!preserve_ratio) {
+ cur_w = MIN(cur_w, max_width);
+ cur_h = MIN(cur_h, max_height);
+ } else if ((guint64)cur_w * max_height > (guint64)max_width * cur_h) {
+ /* cur_w / cur_h > max_width / max_height */
+ cur_h = (guint64)max_width * cur_h / cur_w;
+ cur_w = max_width;
+ } else {
+ cur_w = (guint64)max_height * cur_w / cur_h;
+ cur_h = max_height;
+ }
+
+ if (cur_w <= 0)
+ cur_w = 1;
+ if (cur_h <= 0)
+ cur_h = 1;
+
+ dst = gdk_pixbuf_scale_simple(src, cur_w, cur_h, interp_type);
+ g_object_unref(src);
+
+ return dst;
+}
--- a/pidgin/pidgingdkpixbuf.h Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/pidgingdkpixbuf.h Tue Oct 26 04:05:39 2021 -0500
@@ -64,6 +64,140 @@
*/
gboolean pidgin_gdk_pixbuf_is_opaque(GdkPixbuf *pixbuf);
+/**
+ * pidgin_pixbuf_from_data:
+ * @buf: The raw binary image data.
+ * @count: The length of buf in bytes.
+ *
+ * Create a GdkPixbuf from a chunk of image data.
+ *
+ * Returns: (transfer full): A GdkPixbuf created from the image data, or NULL if
+ * there was an error parsing the data.
+ */
+GdkPixbuf *pidgin_pixbuf_from_data(const guchar *buf, gsize count);
+
+/**
+ * pidgin_pixbuf_anim_from_data:
+ * @buf: The raw binary image data.
+ * @count: The length of buf in bytes.
+ *
+ * Create a GdkPixbufAnimation from a chunk of image data.
+ *
+ * Returns: (transfer full): A GdkPixbufAnimation created from the image data, or NULL if
+ * there was an error parsing the data.
+ */
+GdkPixbufAnimation *pidgin_pixbuf_anim_from_data(const guchar *buf, gsize count);
+
+/**
+ * pidgin_pixbuf_from_image:
+ * @image: a PurpleImage.
+ *
+ * Create a GdkPixbuf from a PurpleImage.
+ *
+ * Returns: (transfer full): a GdkPixbuf created from the @image.
+ */
+GdkPixbuf *
+pidgin_pixbuf_from_image(PurpleImage *image);
+
+/**
+ * pidgin_pixbuf_new_from_file:
+ * @filename: Name of file to load, in the GLib file name encoding
+ *
+ * Helper function that calls gdk_pixbuf_new_from_file() and checks both
+ * the return code and the GError and returns NULL if either one failed.
+ *
+ * The gdk-pixbuf documentation implies that it is sufficient to check
+ * the return value of gdk_pixbuf_new_from_file() to determine
+ * whether the image was able to be loaded. However, this is not the case
+ * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
+ * cases a GdkPixbuf object is returned that will cause some operations
+ * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
+ * infinite loop.
+ *
+ * This function shouldn't be necessary once Pidgin requires a version of
+ * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
+ * nice to keep this function around for the debug message that it logs.
+ *
+ * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
+ * a warning is logged.
+ */
+GdkPixbuf *pidgin_pixbuf_new_from_file(const char *filename);
+
+/**
+ * pidgin_pixbuf_new_from_file_at_size:
+ * @filename: Name of file to load, in the GLib file name encoding
+ * @width: The width the image should have or -1 to not constrain the width
+ * @height: The height the image should have or -1 to not constrain the height
+ *
+ * Helper function that calls gdk_pixbuf_new_from_file_at_size() and checks
+ * both the return code and the GError and returns NULL if either one failed.
+ *
+ * The gdk-pixbuf documentation implies that it is sufficient to check
+ * the return value of gdk_pixbuf_new_from_file_at_size() to determine
+ * whether the image was able to be loaded. However, this is not the case
+ * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
+ * cases a GdkPixbuf object is returned that will cause some operations
+ * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
+ * infinite loop.
+ *
+ * This function shouldn't be necessary once Pidgin requires a version of
+ * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
+ * nice to keep this function around for the debug message that it logs.
+ *
+ * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
+ * a warning is logged.
+ */
+GdkPixbuf *pidgin_pixbuf_new_from_file_at_size(const char *filename, int width, int height);
+
+/**
+ * pidgin_pixbuf_new_from_file_at_scale:
+ * @filename: Name of file to load, in the GLib file name encoding
+ * @width: The width the image should have or -1 to not constrain the width
+ * @height: The height the image should have or -1 to not constrain the height
+ * @preserve_aspect_ratio: TRUE to preserve the image's aspect ratio
+ *
+ * Helper function that calls gdk_pixbuf_new_from_file_at_scale() and checks
+ * both the return code and the GError and returns NULL if either one failed.
+ *
+ * The gdk-pixbuf documentation implies that it is sufficient to check
+ * the return value of gdk_pixbuf_new_from_file_at_scale() to determine
+ * whether the image was able to be loaded. However, this is not the case
+ * with gdk-pixbuf 2.23.3 and probably many earlier versions. In some
+ * cases a GdkPixbuf object is returned that will cause some operations
+ * (like gdk_pixbuf_scale_simple()) to rapidly consume memory in an
+ * infinite loop.
+ *
+ * This function shouldn't be necessary once Pidgin requires a version of
+ * gdk-pixbuf where the aforementioned bug is fixed. However, it might be
+ * nice to keep this function around for the debug message that it logs.
+ *
+ * Returns: (transfer full): The GdkPixbuf if successful. Otherwise NULL is returned and
+ * a warning is logged.
+ */
+GdkPixbuf *pidgin_pixbuf_new_from_file_at_scale(const char *filename, int width, int height, gboolean preserve_aspect_ratio);
+
+/**
+ * pidgin_pixbuf_scale_down:
+ * @src: The source image.
+ * @max_width: Maximum width in px.
+ * @max_height: Maximum height in px.
+ * @interp_type: Interpolation method.
+ * @preserve_ratio: %TRUE to preserve image's aspect ratio.
+ *
+ * Scales the image to the desired dimensions. If image is smaller, it will be
+ * returned without modifications.
+ *
+ * If new image is created, @src reference count will be decreased and new image
+ * with a ref count of 1 will be returned.
+ *
+ * Returns: (transfer full): The image with proper sizing. %NULL in case of error.
+ */
+GdkPixbuf *
+pidgin_pixbuf_scale_down(GdkPixbuf *src, guint max_width, guint max_height,
+ GdkInterpType interp_type, gboolean preserve_ratio);
+
+
+
G_END_DECLS
#endif /* PIDGIN_GDK_PIXBUF_H */
--- a/pidgin/prefs/pidginprefs.c Tue Oct 26 04:04:58 2021 -0500
+++ b/pidgin/prefs/pidginprefs.c Tue Oct 26 04:05:39 2021 -0500
@@ -42,6 +42,7 @@
#include "gtkutils.h"
#include "pidgincore.h"
#include "pidgindebug.h"
+#include "pidgingdkpixbuf.h"
#include "pidginprefs.h"
#include "pidginstock.h"
#ifdef USE_VV