-/*! Create a new RrImage, which is linked to an image cache */
-RrImage* RrImageNew(RrImageCache *cache)
-{
- RrImage *self;
-
- g_assert(cache != NULL);
-
- self = g_new0(RrImage, 1);
- self->ref = 1;
- self->cache = cache;
- return self;
-}
-
-/*! Set function that will be called just before RrImage is destroyed. */
-void RrImageSetDestroyFunc(RrImage *image, RrImageDestroyFunc func,
- gpointer data)
-{
- image->destroy_func = func;
- image->destroy_data = data;
-}
-
-void RrImageRef(RrImage *self)
-{
- ++self->ref;
-}
-
-void RrImageUnref(RrImage *self)
-{
- if (self && --self->ref == 0) {
-/*
-#ifdef DEBUG
- g_debug("Refcount to 0, removing ALL pictures from the cache:\n "
- "Image 0x%lx", (gulong)self);
-#endif
-*/
- if (self->destroy_func)
- self->destroy_func(self, self->destroy_data);
- while (self->n_original > 0)
- RemovePicture(self, &self->original, 0, &self->n_original);
- while (self->n_resized > 0)
- RemovePicture(self, &self->resized, 0, &self->n_resized);
- g_free(self);
- }
-}
-
-static void AddPictureFromData(RrImage *self, const char *name,
- const RrPixel32 *data, gint w, gint h)
-{
- gint i;
- RrImagePic *pic;
-
- /* make sure we don't already have this size.. */
- for (i = 0; i < self->n_original; ++i)
- if (self->original[i]->width == w && self->original[i]->height == h) {
-/*
-#ifdef DEBUG
- g_debug("Found duplicate ORIGINAL image:\n "
- "Image 0x%lx, w %d h %d", (gulong)self, w, h);
-#endif
-*/
- return;
- }
-
- /* remove any resized pictures of this same size */
- for (i = 0; i < self->n_resized; ++i)
- if (self->resized[i]->width == w || self->resized[i]->height == h) {
- RemovePicture(self, &self->resized, i, &self->n_resized);
- break;
- }
-
- /* add the new picture */
- pic = g_new(RrImagePic, 1);
- RrImagePicInit(pic, name, w, h, g_memdup(data, w*h*sizeof(RrPixel32)));
- AddPicture(self, &self->original, &self->n_original, pic);
-}
-
-gboolean RrImageAddPictureName(RrImage *self, const gchar *name)
-{
-#ifdef USE_IMLIB2
- Imlib_Image img;
- gint w, h;
- RrPixel32 *data;
- gchar *path;
-
- /* XXX find the path via freedesktop icon spec (use obt) ! */
- path = g_strdup(name);
-
- if (!(img = imlib_load_image(path)))
- g_message("Cannot load image \"%s\" from file \"%s\"", name, path);
- g_free(path);
-
- if (!img)
- return FALSE; /* failed to load it */
-
- /* Get data and dimensions of the image.
-
- WARNING: This stuff is NOT threadsafe !!
- */
- imlib_context_set_image(img);
- data = imlib_image_get_data_for_reading_only();
- w = imlib_image_get_width();
- h = imlib_image_get_height();
-
- /* add it to the RrImage, and set its name */
- AddPictureFromData(self, name, data, w, h);
-
- imlib_free_image();
- return TRUE;
-#else
- return FALSE;
-#endif
-}
-
-/*! Add a new picture with the given RGBA pixel data and dimensions into the
- RrImage. This adds an "original" picture to the image.
-*/
-void RrImageAddPicture(RrImage *self, const RrPixel32 *data, gint w, gint h)
-{
- AddPictureFromData(self, NULL, data, w, h);
-}
-
-/*! Remove the picture from the RrImage which has the given dimensions. This
- removes an "original" picture from the image.
-*/
-void RrImageRemovePicture(RrImage *self, gint w, gint h)
-{
- gint i;
-
- /* remove any resized pictures of this same size */
- for (i = 0; i < self->n_original; ++i)
- if (self->original[i]->width == w && self->original[i]->height == h) {
- RemovePicture(self, &self->original, i, &self->n_original);
- break;
- }
-}
-