static GdkPixbuf * impl_load_pixbuf_file (const char *uri, int available_width, int available_height, GError **error) { GdkPixbuf *pixbuf = NULL; GFile *file; char *contents = NULL; gsize size; if (g_str_has_prefix (uri, "data:")) return decode_image (uri); file = g_file_new_for_uri (uri); if (g_file_load_contents (file, NULL, &contents, &size, NULL, error)) { pixbuf = impl_load_pixbuf_data ((const guchar *) contents, size, available_width, available_height, error); } g_object_unref (file); g_free (contents); return pixbuf; }
/** * st_texture_cache_load_from_data: * @cache: The texture cache instance * @data: Image data in PNG, GIF, etc format * @len: length of @data * @size: Size in pixels to use for the resulting texture * @error: Return location for error * * Synchronously creates an image from @data. The image is scaled down * to fit the available width and height dimensions, but the image is * never scaled up beyond its actual size. The pixbuf is rotated * according to the associated orientation setting. * * Return value: (transfer none): A new #ClutterActor with the image data loaded if it was * generated succesfully, %NULL otherwise */ ClutterActor * st_texture_cache_load_from_data (StTextureCache *cache, const guchar *data, gsize len, int size, GError **error) { ClutterTexture *texture; CoglHandle texdata; GdkPixbuf *pixbuf; char *key; char *checksum; texture = create_default_texture (cache); clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size); checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len); key = g_strdup_printf (CACHE_PREFIX_COMPRESSED_CHECKSUM "checksum=%s,size=%d", checksum, size); g_free (checksum); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { pixbuf = impl_load_pixbuf_data (data, len, size, size, error); if (!pixbuf) { g_object_unref (texture); g_free (key); return NULL; } texdata = pixbuf_to_cogl_handle (pixbuf); g_object_unref (pixbuf); set_texture_cogl_texture (texture, texdata); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } g_free (key); set_texture_cogl_texture (texture, texdata); return CLUTTER_ACTOR (texture); }
static GdkPixbuf * impl_load_pixbuf_file (GFile *file, int available_width, int available_height, int scale, GError **error) { GdkPixbuf *pixbuf = NULL; char *contents = NULL; gsize size; if (g_file_load_contents (file, NULL, &contents, &size, NULL, error)) { pixbuf = impl_load_pixbuf_data ((const guchar *) contents, size, available_width, available_height, scale, error); } g_free (contents); return pixbuf; }