+1999-09-22 Michael Meeks <michael@nuclecu.unam.mx>
+
+ * src/gdk-pixbuf.c (gdk_pixbuf_new): created.
+ (gdk_pixbuf_scale): use gdk_pixbuf_new + return a new scaled image.
+
+ * src/gdk-pixbuf.h (struct _GdkPixBuf): Re-organise struct, + add
+ GdkPixBufUnrefFunc + gdk_pixbuf_new.
+
+ * src/io-jpeg.c (image_load): clean to use gdk_pixbuf_new.
+
+ * src/io-xpm.c (_pixbuf_create_from_xpm): ditto.
+
+ * src/io-tiff.c (image_load): ditto + fix leak
+
+ * src/io-png.c (image_load): ditto + add more exit points; monitor.png
+ crashes this module ( add warning :-)
+
+ * src/io-bmp.c (image_load): ditto.
+
+ * src/io-gif.c (image_load): ditto.
+
+1999-09-18 Michael Meeks <michael@nuclecu.unam.mx>
+
+ * src/gdk-pixbuf.c (gdk_pixbuf_scale): Hack rgba support in so
+ it doesn't crash scaling with alpha.
+
1999-09-17 Federico Mena Quintero <federico@redhat.com>
* src/io-bmp.c (image_load): Set the initial ref_count to 1.
gdk_pixbuf_destroy (GdkPixBuf *pixbuf)
{
art_pixbuf_free (pixbuf->art_pixbuf);
+ pixbuf->art_pixbuf = NULL;
g_free (pixbuf);
}
+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;
+}
+
void
gdk_pixbuf_ref (GdkPixBuf *pixbuf)
{
}
GdkPixBuf *
-gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
+gdk_pixbuf_scale (const GdkPixBuf *pixbuf, gint w, gint h)
{
art_u8 *pixels;
gint rowstride;
double affine[6];
ArtAlphaGamma *alphagamma;
ArtPixBuf *art_pixbuf = NULL;
+ GdkPixBuf *copy = NULL;
alphagamma = NULL;
affine[1] = affine[2] = affine[4] = affine[5] = 0;
-
affine[0] = w / (double)(pixbuf->art_pixbuf->width);
affine[3] = h / (double)(pixbuf->art_pixbuf->height);
affine, ART_FILTER_NEAREST, alphagamma);
if (pixbuf->art_pixbuf->has_alpha)
- /* should be rgba */
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ /* should be rgba */
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
else
- art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
+ 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);
- art_pixbuf_free (pixbuf->art_pixbuf);
- pixbuf->art_pixbuf = art_pixbuf;
+ copy->ref_count = 1;
+ copy->unref_fn = pixbuf->unref_fn;
+ copy->art_pixbuf = art_pixbuf_duplicate (pixbuf->art_pixbuf);
- return pixbuf;
+ return copy;
}
GdkPixBuf *
#include <libart_lgpl/art_pixbuf.h>
#include <glib.h>
-typedef struct {
- int ref_count;
- ArtPixBuf *art_pixbuf;
- void (*unref_func)(void *gdkpixbuf);
-} GdkPixBuf;
+typedef struct _GdkPixBuf GdkPixBuf;
+typedef void (*GdkPixBufUnrefFunc) (GdkPixBuf *pixbuf);
+
+struct _GdkPixBuf
+{
+ int ref_count;
+ ArtPixBuf *art_pixbuf;
+ GdkPixBufUnrefFunc *unref_fn;
+};
GdkPixBuf *gdk_pixbuf_load_image (const char *file);
void gdk_pixbuf_save_image (const char *format_id, const char *file, ...);
+GdkPixBuf *gdk_pixbuf_new (ArtPixBuf *art_pixbuf,
+ GdkPixBufUnrefFunc *unref_fn);
void gdk_pixbuf_ref (GdkPixBuf *pixbuf);
void gdk_pixbuf_unref (GdkPixBuf *pixbuf);
-GdkPixBuf *gdk_pixbuf_duplicate (GdkPixBuf *pixbuf);
-GdkPixBuf *gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h);
+GdkPixBuf *gdk_pixbuf_duplicate (const GdkPixBuf *pixbuf);
+GdkPixBuf *gdk_pixbuf_scale (const GdkPixBuf *pixbuf, gint w, gint h);
GdkPixBuf *gdk_pixbuf_rotate (GdkPixBuf *pixbuf, gdouble angle);
void gdk_pixbuf_destroy (GdkPixBuf *pixbuf);
/* Shared library entry point */
GdkPixBuf *image_load(FILE * f)
{
- GdkPixBuf *pixbuf;
art_u8 *pixels;
+ ArtPixBuf *art_pixbuf;
/* Ok, now stuff the GdkPixBuf with goodies */
- pixbuf = g_new(GdkPixBuf, 1);
-
if (is_trans)
- pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+ art_pixbuf = art_pixbuf_new_rgba (pixels, w, h, (w * 4));
else
- pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
+ art_pixbuf = art_pixbuf_new_rgb (pixels, w, h, (w * 3));
/* Ok, I'm anal...shoot me */
- if (!(pixbuf->art_pixbuf))
- return NULL;
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
-
- return pixbuf;
+ return gdk_pixbuf_new (art_pixbuf, NULL);
}
{8, 8, 4, 2};
GdkPixBuf *pixbuf;
+ ArtPixBuf *art_pixbuf;
g_return_val_if_fail(f != NULL, NULL);
}
g_free(rows);
- /* Ok, now stuff the GdkPixBuf with goodies */
-
- pixbuf = g_new(GdkPixBuf, 1);
-
if (is_trans)
- pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+ art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
else
- pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
+
+ pixbuf = gdk_pixbuf_new (art_pixbuf, NULL);
/* Ok, I'm anal...shoot me */
- if (!(pixbuf->art_pixbuf)) {
+ if (!pixbuf)
art_free(pixels);
- g_free(pixbuf);
- return NULL;
- }
-
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
return pixbuf;
}
jpeg_destroy_decompress(&cinfo);
/* finish off, create the pixbuf */
- pixbuf = g_new(GdkPixBuf, 1);
- pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
- if (!(pixbuf->art_pixbuf)) {
- art_free(pixels);
- g_free(pixbuf);
- return NULL;
- }
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
-
+ pixbuf = gdk_pixbuf_new (art_pixbuf_new_rgb (pixels, w, h, (w * 3)),
+ NULL);
+ if (!pixbuf)
+ art_free (pixels);
+
return pixbuf;
}
png_bytepp rows;
art_u8 *pixels, *temp, *rowdata;
GdkPixBuf *pixbuf;
+ ArtPixBuf *art_pixbuf;
- g_return_val_if_fail(f != NULL, NULL);
+ g_return_val_if_fail (f != NULL, NULL);
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
- NULL);
+ png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
+ NULL, NULL, NULL);
+ if (!png_ptr)
+ return NULL;
- info_ptr = png_create_info_struct(png_ptr);
+ info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr) {
- png_destroy_read_struct(&png_ptr, NULL, NULL);
- return NULL;
+ png_destroy_read_struct (&png_ptr, NULL, NULL);
+ return NULL;
}
- end_info = png_create_info_struct(png_ptr);
+
+ end_info = png_create_info_struct (png_ptr);
if (!end_info) {
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
- return NULL;
+ png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
+ return NULL;
}
- if (setjmp(png_ptr->jmpbuf)) {
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- return NULL;
+
+ if (setjmp (png_ptr->jmpbuf)) {
+ png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
+ return NULL;
}
- png_init_io(png_ptr, f);
- png_read_info(png_ptr, info_ptr);
- png_get_IHDR(png_ptr, info_ptr, &w, &h, &depth, &ctype, &inttype,
- NULL, NULL);
+ png_init_io (png_ptr, f);
+ png_read_info (png_ptr, info_ptr);
+ png_get_IHDR (png_ptr, info_ptr, &w, &h, &depth, &ctype, &inttype,
+ NULL, NULL);
/* Ok, we want to work with 24 bit images.
* However, PNG can vary depth per channel.
* everything into a format libart expects.
* We also use png_set_strip_16 to reduce down to 8 bit/chan.
*/
-
if (ctype == PNG_COLOR_TYPE_PALETTE && depth <= 8)
- png_set_expand(png_ptr);
+ png_set_expand (png_ptr);
if (ctype == PNG_COLOR_TYPE_GRAY && depth < 8)
- png_set_expand(png_ptr);
+ png_set_expand (png_ptr);
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_expand(png_ptr);
+ if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_set_expand (png_ptr);
+ g_warning ("FIXME: We are going to crash");
+ }
if (depth == 16)
- png_set_strip_16(png_ptr);
+ png_set_strip_16 (png_ptr);
/* We also have png "packing" bits into bytes if < 8 */
if (depth < 8)
- png_set_packing(png_ptr);
+ png_set_packing (png_ptr);
/* Lastly, if the PNG is greyscale, convert to RGB */
if (ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_GRAY_ALPHA)
- png_set_gray_to_rgb(png_ptr);
+ png_set_gray_to_rgb (png_ptr);
/* ...and if we're interlaced... */
- passes = png_set_interlace_handling(png_ptr);
+ passes = png_set_interlace_handling (png_ptr);
/* Update our info structs */
- png_read_update_info(png_ptr, info_ptr);
+ png_read_update_info (png_ptr, info_ptr);
/* Allocate some memory and set up row array */
- /* This "inhales vigirously"... */
+ /* This "inhales vigorously"... */
if (ctype & PNG_COLOR_MASK_ALPHA)
bpp = 4;
else
bpp = 3;
- pixels = art_alloc(w * h * bpp);
- rows = g_malloc(h * sizeof(png_bytep));
+ pixels = art_alloc (w * h * bpp);
+ rows = g_malloc (h * sizeof(png_bytep));
- if ((!pixels) || (!rows)) {
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ if (!pixels || !rows) {
+ png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
return NULL;
}
/* Icky code, but it has to be done... */
for (i = 0; i < h; i++) {
- if ((rows[i] = g_malloc(w * sizeof(art_u8) * bpp)) == NULL) {
+ if ((rows[i] = g_malloc (w * sizeof (art_u8) * bpp)) == NULL) {
int n;
for (n = 0; n < i; n++)
- g_free(rows[i]);
- g_free(rows);
- art_free(pixels);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ g_free (rows[i]);
+ g_free (rows);
+ art_free (pixels);
+ png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
return NULL;
}
}
/* And we FINALLY get here... */
- png_read_image(png_ptr, rows);
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ png_read_image (png_ptr, rows);
+ png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
/* Now stuff the bytes into pixels & free rows[y] */
temp[3] = rowdata[(x * bpp) + 3];
temp += bpp;
}
- g_free(rows[y]);
+ g_free (rows[y]);
}
- g_free(rows);
-
- /* Return the GdkPixBuf */
- pixbuf = g_new(GdkPixBuf, 1);
+ g_free (rows);
if (ctype & PNG_COLOR_MASK_ALPHA)
- pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+ art_pixbuf = art_pixbuf_new_rgba (pixels, w, h, (w * 4));
else
- pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
+ art_pixbuf = art_pixbuf_new_rgb (pixels, w, h, (w * 3));
- /* Ok, I'm anal...shoot me */
- if (!(pixbuf->art_pixbuf)) {
- art_free(pixels);
- g_free(pixbuf);
- return NULL;
- }
+ pixbuf = gdk_pixbuf_new (art_pixbuf, NULL);
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
+ if (!pixbuf)
+ art_free (pixels);
return pixbuf;
}
_TIFFfree(rast);
TIFFClose(tiff);
- /* Return the GdkPixBuf */
- pixbuf = g_new(GdkPixBuf, 1);
- pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+ pixbuf = gdk_pixbuf_new (art_pixbuf_new_rgba (pixels, w, h, (w * 4)),
+ NULL);
- /* Ok, I'm anal...shoot me */
- if (!(pixbuf->art_pixbuf))
- return NULL;
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
+ if (!pixbuf)
+ art_free (pixels);
return pixbuf;
}
_XPMColor *colors, *color, *fallbackcolor;
art_u8 *pixels, *pixtmp;
GdkPixBuf *pixbuf;
+ ArtPixBuf *art_pixbuf;
buffer = (*get_buf) (op_header, handle);
if (!buffer) {
/* Ok, now stuff the GdkPixBuf with goodies */
- pixbuf = g_new(GdkPixBuf, 1);
-
if (is_trans)
- pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+ art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
else
- pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
+ art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
- /* Ok, I'm anal...shoot me */
- if (!(pixbuf->art_pixbuf)) {
- art_free(pixels);
- g_free(pixbuf);
- return NULL;
- }
+ pixbuf = gdk_pixbuf_new (art_pixbuf, NULL);
- pixbuf->ref_count = 1;
- pixbuf->unref_func = NULL;
+ if (!pixbuf)
+ art_free(pixels);
return pixbuf;
}