summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-tiff.c
diff options
context:
space:
mode:
authorMark Crichton <crichton@src.gnome.org>1999-07-01 06:59:07 +0000
committerMark Crichton <crichton@src.gnome.org>1999-07-01 06:59:07 +0000
commit8d072a4f58c8a065cb0c7b3f9f7e190df79fecfb (patch)
treef04628114405c926eb073763780994e583848876 /gdk-pixbuf/io-tiff.c
parent6cf7477093d66d9ad922c2a80e5ec2e34ad9395b (diff)
downloadgdk-pixbuf-8d072a4f58c8a065cb0c7b3f9f7e190df79fecfb.tar.gz
Now we have very rudimentary tiff support.
Now we have very rudimentary tiff support. I should use the loading logic in the GIMP plugin...
Diffstat (limited to 'gdk-pixbuf/io-tiff.c')
-rw-r--r--gdk-pixbuf/io-tiff.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c
new file mode 100644
index 000000000..771a05267
--- /dev/null
+++ b/gdk-pixbuf/io-tiff.c
@@ -0,0 +1,101 @@
+/*
+ * io-tiff.c: GdkPixBuf I/O for TIFF files.
+ * Copyright (C) 1999 Mark Crichton
+ * Author: Mark Crichton <crichton@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, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* Following code (almost) blatantly ripped from Imlib */
+
+#include <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <tiffio.h>
+
+#include "gdk-pixbuf.h"
+/*#include "gdk-pixbuf-io.h" */
+
+GdkPixBuf *image_load(FILE * f)
+{
+ GdkPixBuf *pixbuf;
+ TIFF *tiff;
+ art_u8 *pixels, *tmppix;
+ gint w, h, x, y, num_pixs, fd;
+ uint32 *rast, *tmp_rast;
+
+ g_return_val_if_fail(f != NULL, NULL);
+
+ fd = fileno(f);
+ tiff = TIFFFdOpen(fd, "libpixbuf-tiff", "r");
+
+ if (!tiff)
+ return NULL;
+
+ TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
+ num_pixs = w * h;
+
+ /* Yes, it needs to be _TIFFMalloc... */
+ rast = (uint32 *) _TIFFmalloc(num_pixs * sizeof(uint32));
+
+ if (!rast) {
+ TIFFClose(tiff);
+ return NULL;
+ }
+
+ if (TIFFReadRGBAImage(tiff, w, h, rast, 0)) {
+ pixels = art_alloc(num_pixs * 4);
+ if (!pixels) {
+ _TIFFfree(rast);
+ TIFFClose(tiff);
+ return NULL;
+ }
+ tmppix = pixels;
+
+ for (y = 0; y < h; y++) {
+ /* Unexplainable...are tiffs backwards? */
+ /* Also looking at the GIMP plugin, this
+ * whole reading thing can be a bit more
+ * robust.
+ */
+ tmp_rast = rast + ((h - y - 1) * w);
+ for (x = 0; x < w; x++) {
+ tmppix[0] = TIFFGetR(*tmp_rast);
+ tmppix[1] = TIFFGetG(*tmp_rast);
+ tmppix[2] = TIFFGetB(*tmp_rast);
+ tmppix[3] = TIFFGetA(*tmp_rast);
+ tmp_rast++;
+ tmppix += 4;
+ }
+ }
+ }
+ _TIFFfree(rast);
+ TIFFClose(tiff);
+
+ /* Return the GdkPixBuf */
+ pixbuf = g_new(GdkPixBuf, 1);
+ pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
+
+ /* Ok, I'm anal...shoot me */
+ if (!(pixbuf->art_pixbuf))
+ return NULL;
+ pixbuf->ref_count = 0;
+ pixbuf->unref_func = NULL;
+
+ return pixbuf;
+}