1999-01-04 23:53:12 +00:00
|
|
|
/*
|
|
|
|
* gdk-pixbuf.c: Resource management.
|
|
|
|
*
|
1999-07-20 18:59:39 +00:00
|
|
|
* Authors:
|
1999-01-04 23:53:12 +00:00
|
|
|
* Miguel de Icaza (miguel@gnu.org)
|
1999-07-20 18:59:39 +00:00
|
|
|
* Mark Crichton (crichton@gimp.org)
|
1999-01-04 23:53:12 +00:00
|
|
|
*/
|
1999-08-09 06:09:24 +00:00
|
|
|
|
1999-01-04 23:53:12 +00:00
|
|
|
#include <config.h>
|
1999-07-08 16:04:16 +00:00
|
|
|
#include <glib.h>
|
1999-07-19 02:13:34 +00:00
|
|
|
#include <math.h>
|
1999-07-16 20:35:21 +00:00
|
|
|
#include <libart_lgpl/art_misc.h>
|
1999-08-09 06:09:24 +00:00
|
|
|
#include <libart_lgpl/art_affine.h>
|
|
|
|
#include <libart_lgpl/art_pixbuf.h>
|
|
|
|
#include <libart_lgpl/art_rgb_pixbuf_affine.h>
|
1999-07-16 20:35:21 +00:00
|
|
|
#include <libart_lgpl/art_alphagamma.h>
|
1999-01-04 23:53:12 +00:00
|
|
|
#include "gdk-pixbuf.h"
|
|
|
|
|
|
|
|
|
1999-07-19 02:13:34 +00:00
|
|
|
void
|
1999-01-04 23:53:12 +00:00
|
|
|
gdk_pixbuf_destroy (GdkPixBuf *pixbuf)
|
|
|
|
{
|
1999-07-19 02:13:34 +00:00
|
|
|
art_pixbuf_free (pixbuf->art_pixbuf);
|
1999-09-22 22:30:51 +00:00
|
|
|
pixbuf->art_pixbuf = NULL;
|
1999-07-19 02:13:34 +00:00
|
|
|
g_free (pixbuf);
|
1999-01-04 23:53:12 +00:00
|
|
|
}
|
|
|
|
|
1999-09-22 22:30:51 +00:00
|
|
|
GdkPixBuf *
|
|
|
|
gdk_pixbuf_new (ArtPixBuf *art_pixbuf,
|
|
|
|
GdkPixBufUnrefFunc *unref_fn)
|
|
|
|
{
|
|
|
|
GdkPixBuf *pixbuf;
|
|
|
|
|
|
|
|
if (!art_pixbuf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pixbuf = g_new (GdkPixBuf, 1);
|
|
|
|
pixbuf->ref_count = 1;
|
|
|
|
pixbuf->unref_fn = unref_fn;
|
|
|
|
pixbuf->art_pixbuf = art_pixbuf;
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
1999-01-04 23:53:12 +00:00
|
|
|
void
|
|
|
|
gdk_pixbuf_ref (GdkPixBuf *pixbuf)
|
|
|
|
{
|
1999-07-19 02:13:34 +00:00
|
|
|
g_return_if_fail (pixbuf != NULL);
|
1999-09-17 05:59:53 +00:00
|
|
|
g_return_if_fail (pixbuf->ref_count > 0);
|
1999-08-09 06:09:24 +00:00
|
|
|
|
1999-07-19 02:13:34 +00:00
|
|
|
pixbuf->ref_count++;
|
1999-01-04 23:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_pixbuf_unref (GdkPixBuf *pixbuf)
|
|
|
|
{
|
1999-07-16 20:35:21 +00:00
|
|
|
g_return_if_fail (pixbuf != NULL);
|
1999-09-17 05:59:53 +00:00
|
|
|
g_return_if_fail (pixbuf->ref_count > 0);
|
1999-08-09 06:09:24 +00:00
|
|
|
|
1999-07-16 20:35:21 +00:00
|
|
|
pixbuf->ref_count--;
|
1999-09-17 05:59:53 +00:00
|
|
|
|
|
|
|
if (pixbuf->ref_count == 0)
|
1999-07-16 20:35:21 +00:00
|
|
|
gdk_pixbuf_destroy (pixbuf);
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
1999-07-13 06:21:40 +00:00
|
|
|
GdkPixBuf *
|
1999-09-22 22:30:51 +00:00
|
|
|
gdk_pixbuf_scale (const GdkPixBuf *pixbuf, gint w, gint h)
|
1999-07-13 06:21:40 +00:00
|
|
|
{
|
1999-07-16 20:35:21 +00:00
|
|
|
art_u8 *pixels;
|
1999-07-17 20:03:34 +00:00
|
|
|
gint rowstride;
|
1999-07-13 07:01:08 +00:00
|
|
|
double affine[6];
|
1999-07-16 20:35:21 +00:00
|
|
|
ArtAlphaGamma *alphagamma;
|
1999-07-17 20:03:34 +00:00
|
|
|
ArtPixBuf *art_pixbuf = NULL;
|
1999-09-22 22:30:51 +00:00
|
|
|
GdkPixBuf *copy = NULL;
|
1999-07-13 07:01:08 +00:00
|
|
|
|
1999-07-16 20:35:21 +00:00
|
|
|
alphagamma = NULL;
|
1999-07-13 07:01:08 +00:00
|
|
|
|
1999-07-17 03:00:10 +00:00
|
|
|
affine[1] = affine[2] = affine[4] = affine[5] = 0;
|
1999-08-09 06:09:24 +00:00
|
|
|
|
1999-07-17 20:03:34 +00:00
|
|
|
affine[0] = w / (double)(pixbuf->art_pixbuf->width);
|
|
|
|
affine[3] = h / (double)(pixbuf->art_pixbuf->height);
|
|
|
|
|
1999-07-19 02:13:34 +00:00
|
|
|
/* rowstride = w * pixbuf->art_pixbuf->n_channels; */
|
1999-07-17 20:03:34 +00:00
|
|
|
rowstride = w * 3;
|
|
|
|
|
|
|
|
pixels = art_alloc (h * rowstride);
|
1999-08-09 06:09:24 +00:00
|
|
|
art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
|
1999-07-17 20:03:34 +00:00
|
|
|
pixbuf->art_pixbuf,
|
|
|
|
affine, ART_FILTER_NEAREST, alphagamma);
|
|
|
|
|
|
|
|
if (pixbuf->art_pixbuf->has_alpha)
|
1999-09-22 22:30:51 +00:00
|
|
|
/* should be rgba */
|
|
|
|
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
|
1999-08-09 06:09:24 +00:00
|
|
|
else
|
1999-09-22 22:30:51 +00:00
|
|
|
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
|
|
|
|
|
|
|
|
copy = gdk_pixbuf_new (art_pixbuf, NULL);
|
|
|
|
|
|
|
|
if (!copy)
|
|
|
|
art_free (pixels);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixBuf *
|
|
|
|
gdk_pixbuf_duplicate (const GdkPixBuf *pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixBuf *copy = g_new (GdkPixBuf, 1);
|
1999-07-17 20:03:34 +00:00
|
|
|
|
1999-09-22 22:30:51 +00:00
|
|
|
copy->ref_count = 1;
|
|
|
|
copy->unref_fn = pixbuf->unref_fn;
|
|
|
|
copy->art_pixbuf = art_pixbuf_duplicate (pixbuf->art_pixbuf);
|
1999-07-17 20:03:34 +00:00
|
|
|
|
1999-09-22 22:30:51 +00:00
|
|
|
return copy;
|
1999-07-16 20:35:21 +00:00
|
|
|
}
|
1999-07-17 20:03:34 +00:00
|
|
|
|
1999-07-19 02:13:34 +00:00
|
|
|
GdkPixBuf *
|
|
|
|
gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle)
|
|
|
|
{
|
|
|
|
art_u8 *pixels;
|
|
|
|
gint rowstride, w, h;
|
|
|
|
gdouble rad;
|
1999-07-20 18:59:39 +00:00
|
|
|
double rot[6], trans[6], affine[6];
|
1999-07-19 02:13:34 +00:00
|
|
|
ArtAlphaGamma *alphagamma = NULL;
|
|
|
|
ArtPixBuf *art_pixbuf = NULL;
|
|
|
|
|
|
|
|
w = pixbuf->art_pixbuf->width;
|
|
|
|
h = pixbuf->art_pixbuf->height;
|
|
|
|
|
1999-07-20 18:59:39 +00:00
|
|
|
rad = (M_PI * angle / 180.0);
|
1999-07-19 02:13:34 +00:00
|
|
|
|
1999-07-20 18:59:39 +00:00
|
|
|
rot[0] = cos(rad);
|
|
|
|
rot[1] = sin(rad);
|
|
|
|
rot[2] = -sin(rad);
|
|
|
|
rot[3] = cos(rad);
|
|
|
|
rot[4] = rot[5] = 0;
|
|
|
|
|
1999-07-20 19:30:08 +00:00
|
|
|
trans[0] = trans[3] = 1;
|
|
|
|
trans[1] = trans[2] = 0;
|
|
|
|
trans[4] = -(double)w / 2.0;
|
|
|
|
trans[5] = -(double)h / 2.0;
|
|
|
|
|
|
|
|
art_affine_multiply(rot, trans, rot);
|
|
|
|
|
1999-07-20 18:59:39 +00:00
|
|
|
trans[0] = trans[3] = 1;
|
|
|
|
trans[1] = trans[2] = 0;
|
|
|
|
trans[4] = (double)w / 2.0;
|
1999-07-20 19:30:08 +00:00
|
|
|
trans[5] = (double)h / 2.0;
|
1999-07-20 18:59:39 +00:00
|
|
|
|
|
|
|
art_affine_multiply(affine, rot, trans);
|
|
|
|
|
|
|
|
g_print("Affine: %e %e %e %e %e %e\n", affine[0], affine[1], affine[2],
|
|
|
|
affine[3], affine[4], affine[5]);
|
1999-07-19 02:13:34 +00:00
|
|
|
|
|
|
|
/* rowstride = w * pixbuf->art_pixbuf->n_channels; */
|
|
|
|
rowstride = w * 3;
|
|
|
|
|
|
|
|
pixels = art_alloc (h * rowstride);
|
|
|
|
art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
|
|
|
|
pixbuf->art_pixbuf,
|
|
|
|
affine, ART_FILTER_NEAREST, alphagamma);
|
1999-07-20 18:59:39 +00:00
|
|
|
if (pixbuf->art_pixbuf->has_alpha)
|
|
|
|
/* should be rgba */
|
1999-08-09 06:09:24 +00:00
|
|
|
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
|
|
|
|
else
|
|
|
|
art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
|
1999-07-17 20:03:34 +00:00
|
|
|
|
1999-07-20 18:59:39 +00:00
|
|
|
art_pixbuf_free (pixbuf->art_pixbuf);
|
|
|
|
pixbuf->art_pixbuf = art_pixbuf;
|
1999-07-17 20:03:34 +00:00
|
|
|
|
1999-07-20 18:59:39 +00:00
|
|
|
return pixbuf;
|
1999-07-19 02:13:34 +00:00
|
|
|
}
|