static CoglHandle pixbuf_to_cogl_handle (GdkPixbuf *pixbuf, gboolean add_padding) { return data_to_cogl_handle (gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), add_padding); }
/** * st_texture_cache_load_from_raw: * @cache: a #StTextureCache * @data: (array length=len): raw pixel data * @len: the length of @data * @has_alpha: whether @data includes an alpha channel * @width: width in pixels of @data * @height: width in pixels of @data * @rowstride: rowstride of @data * @size: size of icon to return * * Creates (or retrieves from cache) an icon based on raw pixel data. * * Return value: (transfer none): a new #ClutterActor displaying a * pixbuf created from @data and the other parameters. **/ ClutterActor * st_texture_cache_load_from_raw (StTextureCache *cache, const guchar *data, gsize len, gboolean has_alpha, int width, int height, int rowstride, int size, GError **error) { ClutterTexture *texture; CoglHandle texdata; char *key; char *checksum; texture = create_default_texture (); clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size); /* In theory, two images of with different width and height could have the same * pixel data and thus hash the same. (Say, a 16x16 and a 8x32 blank image.) * We ignore this for now. If anybody hits this problem they should use * GChecksum directly to compute a checksum including the width and height. */ checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len); key = g_strdup_printf (CACHE_PREFIX_RAW_CHECKSUM "checksum=%s", checksum); g_free (checksum); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { texdata = data_to_cogl_handle (data, has_alpha, width, height, rowstride, TRUE); 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); }