1999-10-20 21:20:49 +00:00
|
|
|
|
/* GdkPixbuf library - Basic memory management
|
1999-01-04 23:53:12 +00:00
|
|
|
|
*
|
1999-10-18 19:29:45 +00:00
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Authors: Mark Crichton <crichton@gimp.org>
|
|
|
|
|
* Miguel de Icaza <miguel@gnu.org>
|
|
|
|
|
* Federico Mena-Quintero <federico@gimp.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
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-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-10-18 19:29:45 +00:00
|
|
|
|
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/* Reference counting */
|
1999-09-22 22:30:51 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_ref:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Adds a reference to a pixbuf. It must be released afterwards using
|
|
|
|
|
* gdk_pixbuf_unref().
|
|
|
|
|
**/
|
1999-01-04 23:53:12 +00:00
|
|
|
|
void
|
1999-10-18 19:29:45 +00:00
|
|
|
|
gdk_pixbuf_ref (GdkPixbuf *pixbuf)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
1999-10-18 19:29:45 +00:00
|
|
|
|
g_return_if_fail (pixbuf != NULL);
|
|
|
|
|
g_return_if_fail (pixbuf->ref_count > 0);
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
pixbuf->ref_count++;
|
1999-01-04 23:53:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_unref:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Removes a reference from a pixbuf. It will be destroyed when the reference
|
|
|
|
|
* count drops to zero.
|
|
|
|
|
**/
|
1999-01-04 23:53:12 +00:00
|
|
|
|
void
|
1999-10-18 19:29:45 +00:00
|
|
|
|
gdk_pixbuf_unref (GdkPixbuf *pixbuf)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
1999-10-18 19:29:45 +00:00
|
|
|
|
g_return_if_fail (pixbuf != NULL);
|
|
|
|
|
g_return_if_fail (pixbuf->ref_count > 0);
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
pixbuf->ref_count--;
|
1999-09-17 05:59:53 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
if (pixbuf->ref_count == 0) {
|
|
|
|
|
art_pixbuf_free (pixbuf->art_pixbuf);
|
|
|
|
|
pixbuf->art_pixbuf = NULL;
|
|
|
|
|
g_free (pixbuf);
|
|
|
|
|
}
|
1999-07-16 20:35:21 +00:00
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
1999-07-17 20:03:34 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/* Wrap a libart pixbuf */
|
1999-07-17 20:03:34 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new_from_art_pixbuf:
|
|
|
|
|
* @art_pixbuf: A libart pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Creates a &GdkPixbuf by wrapping a libart pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Return value: A newly-created &GdkPixbuf structure with a reference count of
|
|
|
|
|
* 1.
|
|
|
|
|
**/
|
1999-10-18 19:29:45 +00:00
|
|
|
|
GdkPixbuf *
|
1999-10-20 21:20:49 +00:00
|
|
|
|
gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf)
|
1999-07-19 02:13:34 +00:00
|
|
|
|
{
|
1999-10-20 21:20:49 +00:00
|
|
|
|
GdkPixbuf *pixbuf;
|
1999-10-18 19:29:45 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
g_return_val_if_fail (art_pixbuf != NULL, NULL);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
pixbuf = g_new (GdkPixbuf, 1);
|
|
|
|
|
pixbuf->ref_count = 1;
|
1999-10-18 19:29:45 +00:00
|
|
|
|
pixbuf->art_pixbuf = art_pixbuf;
|
|
|
|
|
|
|
|
|
|
return pixbuf;
|
1999-07-19 02:13:34 +00:00
|
|
|
|
}
|
1999-10-27 17:28:44 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new:
|
|
|
|
|
* @art_pixbuf: A libart pixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Creates a &GdkPixbuf; magically sets the ArtPixFormat, rowstride, and creates
|
|
|
|
|
* the buffer. Use gdk_pixbuf_new_from_data() to do things manually.
|
|
|
|
|
*
|
|
|
|
|
* Return value: A newly-created &GdkPixbuf structure with a reference count of
|
|
|
|
|
* 1. Somewhat oddly, returns NULL if it can't allocate the buffer; this unusual
|
|
|
|
|
* behavior is needed because images can be very large.
|
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
gdk_pixbuf_new (gboolean has_alpha, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (width > 0, NULL);
|
|
|
|
|
g_return_val_if_fail (height > 0, NULL);
|
|
|
|
|
|
|
|
|
|
pixbuf = g_new (GdkPixbuf, 1);
|
|
|
|
|
pixbuf->ref_count = 1;
|
|
|
|
|
|
|
|
|
|
if (has_alpha) {
|
|
|
|
|
art_u8* pixels;
|
|
|
|
|
int rowstride;
|
|
|
|
|
|
|
|
|
|
/* FIXME, pick an optimal stride */
|
|
|
|
|
rowstride = 4*width;
|
|
|
|
|
|
|
|
|
|
pixels = art_alloc(rowstride*height);
|
|
|
|
|
|
|
|
|
|
if (pixels == NULL) {
|
|
|
|
|
g_free(pixbuf);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, width, height, rowstride);
|
|
|
|
|
} else {
|
|
|
|
|
art_u8* pixels;
|
|
|
|
|
int rowstride;
|
|
|
|
|
|
|
|
|
|
/* FIXME, pick an optimal stride */
|
|
|
|
|
rowstride = 3*width;
|
|
|
|
|
|
|
|
|
|
pixels = art_alloc(rowstride*height);
|
|
|
|
|
|
|
|
|
|
if (pixels == NULL) {
|
|
|
|
|
g_free(pixbuf);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, width, height, rowstride);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|