static GdkPixbuf * _eventd_nd_pixbuf_from_file(const gchar *path, gint width, gint height) { GError *error = NULL; GdkPixbufFormat *format; GdkPixbuf *pixbuf; if ( *path == 0 ) return NULL; if ( ( ( width > 0 ) || ( height > 0 ) ) && ( ( format = gdk_pixbuf_get_file_info(path, NULL, NULL) ) != NULL ) && gdk_pixbuf_format_is_scalable(format) ) pixbuf = gdk_pixbuf_new_from_file_at_size(path, width, height, &error); else pixbuf = gdk_pixbuf_new_from_file(path, &error); if ( pixbuf == NULL ) g_warning("Couldn't load file '%s': %s", path, error->message); g_clear_error(&error); return pixbuf; }
GdkPixbuf * eventd_nd_pixbuf_from_data(GVariant *var, gint width, gint height) { GdkPixbuf *pixbuf = NULL; GError *error = NULL; const gchar *mime_type; GVariant *invar; g_variant_get(var, "(m&sm&sv)", &mime_type, NULL, &invar); if ( g_strcmp0(mime_type, "image/x.eventd.pixbuf") == 0 ) { gboolean a; gint b, w, h, s, n; GVariant *data; g_variant_get(invar, "(iiibii@ay)", &w, &h, &s, &a, &b, &n, &data); /* This is the only format gdk-pixbuf can read */ if ( ( b == 8 ) && ( n == ( a ? 4 : 3 ) ) && ( h * s == (gint) g_variant_get_size(data) ) ) return gdk_pixbuf_new_from_data(g_variant_get_data(data), GDK_COLORSPACE_RGB, a, b, w, h, s, _eventd_nd_pixbuf_free_data, data); g_variant_unref(data); goto end; } if ( ! g_variant_is_of_type(invar, G_VARIANT_TYPE_BYTESTRING) ) goto end; GdkPixbufLoader *loader; const guchar *data; gsize length; data = g_variant_get_data(invar); length = g_variant_get_size(invar); if ( mime_type != NULL ) { loader = gdk_pixbuf_loader_new_with_mime_type(mime_type, &error); if ( loader == NULL ) { g_warning("Couldn't create loader for MIME type '%s': %s", mime_type, error->message); goto end; } GdkPixbufFormat *format; if ( ( ( width > 0 ) || ( height > 0 ) ) && ( ( format = gdk_pixbuf_loader_get_format(loader) ) != NULL ) && gdk_pixbuf_format_is_scalable(format) ) gdk_pixbuf_loader_set_size(loader, width, height); } else loader = gdk_pixbuf_loader_new(); if ( ! gdk_pixbuf_loader_write(loader, data, length, &error) ) { g_warning("Couldn't write image data: %s", error->message); goto error; } if ( ! gdk_pixbuf_loader_close(loader, &error) ) { g_warning("Couldn't load image data: %s", error->message); goto error; } pixbuf = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader)); error: g_object_unref(loader); end: g_variant_unref(invar); g_variant_unref(var); g_clear_error(&error); return pixbuf; }
static VALUE rg_scalable_p(VALUE self) { return CBOOL2RVAL(gdk_pixbuf_format_is_scalable(_SELF(self))); }