1999-10-20 21:20:49 +00:00
|
|
|
|
/* GdkPixbuf library - JPEG image loader
|
|
|
|
|
*
|
1999-07-01 06:59:07 +00:00
|
|
|
|
* Copyright (C) 1999 Mark Crichton
|
1999-10-20 21:20:49 +00:00
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Authors: Mark Crichton <crichton@gimp.org>
|
|
|
|
|
* Federico Mena-Quintero <federico@gimp.org>
|
1999-07-01 06:59:07 +00:00
|
|
|
|
*
|
|
|
|
|
* 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
|
1999-10-20 21:20:49 +00:00
|
|
|
|
* 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-07-01 06:59:07 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Following code (almost) blatantly ripped from Imlib */
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <tiffio.h>
|
|
|
|
|
#include "gdk-pixbuf.h"
|
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Destroy notification function for the libart pixbuf */
|
|
|
|
|
static void
|
|
|
|
|
free_buffer (gpointer user_data, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shared library entry point */
|
1999-10-18 19:29:45 +00:00
|
|
|
|
GdkPixbuf *
|
|
|
|
|
image_load (FILE *f)
|
1999-07-01 06:59:07 +00:00
|
|
|
|
{
|
1999-10-18 19:29:45 +00:00
|
|
|
|
TIFF *tiff;
|
1999-10-20 21:20:49 +00:00
|
|
|
|
guchar *pixels, *tmppix;
|
1999-10-18 19:29:45 +00:00
|
|
|
|
gint w, h, x, y, num_pixs, fd;
|
|
|
|
|
uint32 *rast, *tmp_rast;
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
fd = fileno (f);
|
|
|
|
|
tiff = TIFFFdOpen (fd, "libpixbuf-tiff", "r");
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
if (!tiff)
|
|
|
|
|
return NULL;
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &w);
|
|
|
|
|
TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &h);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
num_pixs = w * h;
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
/* Yes, it needs to be _TIFFMalloc... */
|
1999-10-20 21:20:49 +00:00
|
|
|
|
rast = (uint32 *) _TIFFmalloc (num_pixs * sizeof (uint32));
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-18 19:29:45 +00:00
|
|
|
|
if (!rast) {
|
1999-10-20 21:20:49 +00:00
|
|
|
|
TIFFClose (tiff);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
return NULL;
|
1999-07-01 06:59:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
if (TIFFReadRGBAImage (tiff, w, h, rast, 0)) {
|
|
|
|
|
pixels = malloc (num_pixs * 4);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
if (!pixels) {
|
1999-10-20 21:20:49 +00:00
|
|
|
|
_TIFFfree (rast);
|
|
|
|
|
TIFFClose (tiff);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
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++) {
|
1999-10-20 21:20:49 +00:00
|
|
|
|
tmppix[0] = TIFFGetR (*tmp_rast);
|
|
|
|
|
tmppix[1] = TIFFGetG (*tmp_rast);
|
|
|
|
|
tmppix[2] = TIFFGetB (*tmp_rast);
|
|
|
|
|
tmppix[3] = TIFFGetA (*tmp_rast);
|
1999-10-18 19:29:45 +00:00
|
|
|
|
tmp_rast++;
|
|
|
|
|
tmppix += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-01 06:59:07 +00:00
|
|
|
|
}
|
1999-10-20 21:20:49 +00:00
|
|
|
|
_TIFFfree (rast);
|
|
|
|
|
TIFFClose (tiff);
|
1999-07-01 06:59:07 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
return gdk_pixbuf_new_from_data (pixels, ART_PIX_RGB, TRUE,
|
|
|
|
|
w, h, w * 4,
|
|
|
|
|
free_buffer, NULL);
|
1999-07-01 06:59:07 +00:00
|
|
|
|
}
|