2 * io-tiff.c: GdkPixBuf I/O for TIFF files.
3 * Copyright (C) 1999 Mark Crichton
4 * Author: Mark Crichton <crichton@gimp.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
22 /* Following code (almost) blatantly ripped from Imlib */
30 #include "gdk-pixbuf.h"
31 /*#include "gdk-pixbuf-io.h" */
33 GdkPixBuf *image_load(FILE * f)
37 art_u8 *pixels, *tmppix;
38 gint w, h, x, y, num_pixs, fd;
39 uint32 *rast, *tmp_rast;
41 g_return_val_if_fail(f != NULL, NULL);
44 tiff = TIFFFdOpen(fd, "libpixbuf-tiff", "r");
49 TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w);
50 TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h);
53 /* Yes, it needs to be _TIFFMalloc... */
54 rast = (uint32 *) _TIFFmalloc(num_pixs * sizeof(uint32));
61 if (TIFFReadRGBAImage(tiff, w, h, rast, 0)) {
62 pixels = art_alloc(num_pixs * 4);
70 for (y = 0; y < h; y++) {
71 /* Unexplainable...are tiffs backwards? */
72 /* Also looking at the GIMP plugin, this
73 * whole reading thing can be a bit more
76 tmp_rast = rast + ((h - y - 1) * w);
77 for (x = 0; x < w; x++) {
78 tmppix[0] = TIFFGetR(*tmp_rast);
79 tmppix[1] = TIFFGetG(*tmp_rast);
80 tmppix[2] = TIFFGetB(*tmp_rast);
81 tmppix[3] = TIFFGetA(*tmp_rast);
90 pixbuf = gdk_pixbuf_new (art_pixbuf_new_rgba (pixels, w, h, (w * 4)),