]> Pileus Git - ~andy/gtk/commitdiff
Add pixbuf_duplicate,
authorMichael Meeks <mmeeks@src.gnome.org>
Wed, 22 Sep 1999 22:30:51 +0000 (22:30 +0000)
committerMichael Meeks <mmeeks@src.gnome.org>
Wed, 22 Sep 1999 22:30:51 +0000 (22:30 +0000)
Fix 'scale' API,
Add gdk_pixbuf_new,
clean io modules a tad.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf.c
gdk-pixbuf/gdk-pixbuf.h
gdk-pixbuf/io-bmp.c
gdk-pixbuf/io-gif.c
gdk-pixbuf/io-jpeg.c
gdk-pixbuf/io-png.c
gdk-pixbuf/io-tiff.c
gdk-pixbuf/io-xpm.c

index a7c48604c6ef4b8fb49d26cb3adc363bef29e358..0da60bb997200a08855ff5af9ba909d4ae05084f 100644 (file)
@@ -1,3 +1,29 @@
+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.
index dc23940f2020e263670eab99d49eef03f30d519d..a9f9a50a39a224553a978bfbd73c7587b31dd2f4 100644 (file)
@@ -21,9 +21,27 @@ void
 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)
 {
@@ -46,19 +64,19 @@ gdk_pixbuf_unref (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);
 
@@ -71,15 +89,29 @@ gdk_pixbuf_scale (GdkPixBuf *pixbuf, gint w, gint h)
                           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 *
index 84ff4ca8e767e68a9194da8a3a5be0da068f8747..3ba43ec710353fdd0a78caf8bf8ff76002b1aa99 100644 (file)
@@ -5,18 +5,24 @@
 #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);
index 503747bcb1bb287f7df098d9c6f96091e981786d..13451b4b2652c3cc52036d309612e5212bf42831 100644 (file)
 /* 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);
 }
index 2fb964b66a798577c84c8f3ea7039b5dfe13cfe3..98c9bbcaadcd360c24b584bb2044a47ea0fc77b5 100644 (file)
@@ -46,6 +46,7 @@ GdkPixBuf *image_load(FILE * f)
     {8, 8, 4, 2};
 
     GdkPixBuf *pixbuf;
+    ArtPixBuf *art_pixbuf;
 
     g_return_val_if_fail(f != NULL, NULL);
 
@@ -158,24 +159,16 @@ GdkPixBuf *image_load(FILE * f)
     }
     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;
 }
index afe5baee829506cedb7002d0a1981aa1af8e5cfd..aa9fa775f185ad4157b2ffdf0456a9c5f9a3545b 100644 (file)
@@ -114,16 +114,11 @@ GdkPixBuf *image_load(FILE *f)
        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;
 }
 
index 1f86600f544f457024d082d9c05776efe6cf462b..c574deab123e79dd7098f3ee92bb6ca3923baab8 100644 (file)
@@ -35,31 +35,36 @@ GdkPixBuf *image_load(FILE * f)
     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.
@@ -67,63 +72,64 @@ GdkPixBuf *image_load(FILE * f)
      * 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] */
 
@@ -139,27 +145,19 @@ GdkPixBuf *image_load(FILE * f)
                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;
 }
index dffe9ef2572450bd5205f176f7a1ed64b5860778..1ade9ce296118ab346d4df3d1da594aa1b41f2fc 100644 (file)
@@ -87,15 +87,11 @@ GdkPixBuf *image_load(FILE * f)
     _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;
 }
index db78f1d9310aead5c8fe25414b6c5185146703b1..6cd89fc3c1bb53e8c42c32fee3c196a6e84d1270 100644 (file)
@@ -306,6 +306,7 @@ static GdkPixBuf *
     _XPMColor *colors, *color, *fallbackcolor;
     art_u8 *pixels, *pixtmp;
     GdkPixBuf *pixbuf;
+    ArtPixBuf *art_pixbuf;
 
     buffer = (*get_buf) (op_header, handle);
     if (!buffer) {
@@ -403,22 +404,15 @@ static GdkPixBuf *
 
     /* 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;
 }