Updated tiff plug-in.

From Nicolas Lamb:
 This is a total replacement for the TIFF loading code, probably 50% new code
 and the rest rewritten. It is faster (for boring images, such as RGB and
 8-bit Grayscale) and more stable.


--Sven
This commit is contained in:
Sven Neumann 1998-05-18 00:54:11 +00:00
parent a7b206b5c3
commit 11832a6f1d
3 changed files with 516 additions and 726 deletions

View File

@ -1,3 +1,7 @@
Mon May 18 02:50:03 MEST 1998 Sven Neumann <sven@gimp.org>
* plug-ins/tiff/tiff.c: updated tiff plug-in
Sun May 17 17:31:05 PDT 1998 Manish Singh <yosh@gimp.org> Sun May 17 17:31:05 PDT 1998 Manish Singh <yosh@gimp.org>
* plug-ins/maze: updated maze plugin * plug-ins/maze: updated maze plugin

View File

@ -1,7 +1,7 @@
/* tiff loading and saving for the GIMP /* tiff loading and saving for the GIMP
* -Peter Mattis * -Peter Mattis
* various fixes along the route to GIMP 1.0 * The TIFF loading code has been completely revamped by Nick Lamb
* -Nick Lamb and others (list yourselves here people) * njl195@zepler.org.uk -- 18 May 1998
* *
* The code for this filter is based on "tifftopnm" and "pnmtotiff", * The code for this filter is based on "tifftopnm" and "pnmtotiff",
* 2 programs that are a part of the netpbm package. * 2 programs that are a part of the netpbm package.
@ -57,8 +57,8 @@ static void run (char *name,
GParam **return_vals); GParam **return_vals);
static gint32 load_image (char *filename); static gint32 load_image (char *filename);
static gint save_image (char *filename, static gint save_image (char *filename,
gint32 image_ID, gint32 image,
gint32 drawable_ID); gint32 drawable);
static gint save_dialog (); static gint save_dialog ();
@ -123,9 +123,9 @@ query ()
gimp_install_procedure ("file_tiff_load", gimp_install_procedure ("file_tiff_load",
"loads files of the tiff file format", "loads files of the tiff file format",
"FIXME: write help for tiff_load", "FIXME: write help for tiff_load",
"Spencer Kimball & Peter Mattis", "Spencer Kimball, Peter Mattis & Nick Lamb",
"Spencer Kimball & Peter Mattis", "Nick Lamb <njl195@.ecs.soton.ac.uk>",
"1995-1996", "1995-1996,1998",
"<Load>/Tiff", "<Load>/Tiff",
NULL, NULL,
PROC_PLUG_IN, PROC_PLUG_IN,
@ -139,7 +139,7 @@ query ()
"Spencer Kimball & Peter Mattis", "Spencer Kimball & Peter Mattis",
"1995-1996", "1995-1996",
"<Save>/Tiff", "<Save>/Tiff",
"RGB*, GRAY*", "RGB*, GRAY*, INDEXED",
PROC_PLUG_IN, PROC_PLUG_IN,
nsave_args, 0, nsave_args, 0,
save_args, NULL); save_args, NULL);
@ -159,7 +159,7 @@ run (char *name,
static GParam values[2]; static GParam values[2];
GRunModeType run_mode; GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS; GStatusType status = STATUS_SUCCESS;
gint32 image_ID; gint32 image;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
@ -170,14 +170,14 @@ run (char *name,
if (strcmp (name, "file_tiff_load") == 0) if (strcmp (name, "file_tiff_load") == 0)
{ {
image_ID = load_image (param[1].data.d_string); image = load_image (param[1].data.d_string);
if (image_ID != -1) if (image != -1)
{ {
*nreturn_vals = 2; *nreturn_vals = 2;
values[0].data.d_status = STATUS_SUCCESS; values[0].data.d_status = STATUS_SUCCESS;
values[1].type = PARAM_IMAGE; values[1].type = PARAM_IMAGE;
values[1].data.d_image = image_ID; values[1].data.d_image = image;
} }
else else
{ {
@ -240,410 +240,307 @@ run (char *name,
} }
} }
static gint32 static gint32 load_image (char *filename) {
load_image (char *filename)
{
TIFF *tif; TIFF *tif;
int col; unsigned short bps, spp, photomet;
int cols, rows, maxval, alpha;
int image, layer, tile_height;
unsigned short *redmap, *greenmap, *bluemap;
guchar cmap[768];
int image_type= 0, layer_type= 0;
unsigned short *extra_types, extra = 0;
int col, row, start, i, j;
unsigned char sample; unsigned char sample;
int bitsleft; int bitsleft;
int cols, rows, grayscale;
int alpha;
int gray_val, red_val, green_val, blue_val, alpha_val; int gray_val, red_val, green_val, blue_val, alpha_val;
int numcolors;
int row, i; guchar *source, *s, *dest, *d;
guchar *buf, *s;
guchar *dest, *d;
int maxval;
int image_type;
int layer_type;
unsigned short bps, spp, photomet;
unsigned short *redcolormap;
unsigned short *greencolormap;
unsigned short *bluecolormap;
unsigned short k, num_extra = 0;
unsigned short *extra_samples;
int image_ID;
int layer_ID;
GDrawable *drawable; GDrawable *drawable;
GPixelRgn pixel_rgn; GPixelRgn pixel_rgn;
int tile_height;
int y, yend;
char *name; char *name;
typedef struct {
gint32 ID;
GDrawable *drawable;
GPixelRgn pixel_rgn;
guchar *pixels, *pixel;
} channel_data;
channel_data *channel;
guchar colors[3]= {0, 0, 0}; guchar colors[3]= {0, 0, 0};
tif = TIFFOpen (filename, "r"); typedef struct {
if (!tif) gint32 ID;
{ GDrawable *drawable;
g_warning ("can't open \"%s\"\n", filename); GPixelRgn pixel_rgn;
gimp_quit (); guchar *pixels;
} guchar *pixel;
} channel_data;
name = malloc (strlen (filename) + 12); channel_data *channel= NULL;
tif = TIFFOpen (filename, "r");
if (!tif) {
g_error ("TIFF Can't open \"%s\"\n", filename);
gimp_quit ();
}
name = g_malloc (strlen (filename) + 12);
sprintf (name, "Loading %s:", filename); sprintf (name, "Loading %s:", filename);
gimp_progress_init (name); gimp_progress_init (name);
free (name); g_free (name);
if (!TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bps)) if (!TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bps))
bps = 1; bps = 1;
if (bps > 8) {
g_error("TIFF Can't handle samples wider than 8-bit\n");
gimp_quit();
}
if (!TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &spp)) if (!TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &spp))
spp = 1; spp = 1;
if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &num_extra, &extra_samples)) if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &extra, &extra_types))
alpha = 0; extra = 0;
if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet))
{ if (!TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &cols)) {
g_warning ("error getting photometric\n"); g_error ("TIFF Can't get image width\n");
gimp_quit (); gimp_quit ();
} }
if (!TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &rows)) {
g_error ("TIFF Can't get image length\n");
gimp_quit ();
}
if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet)) {
g_error ("TIFF Can't get photometric\n");
gimp_quit ();
}
/* test if the extrasample represents an associated alpha channel... */ /* test if the extrasample represents an associated alpha channel... */
if (num_extra > 0 && (extra_samples [0] == EXTRASAMPLE_ASSOCALPHA)) if (extra > 0 && (extra_types[0] == EXTRASAMPLE_ASSOCALPHA)) {
alpha = 1; alpha = 1;
else } else {
alpha = 0; alpha = 0;
}
if (spp > 3) alpha = 1; /* Kludge - like all the rest of this -- njl195 */ /* some programs seem to think alpha etc. aren't "extra" samples (?) */
if (spp > 3) {
TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &cols); extra= spp - 3;
TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &rows); }
maxval = (1 << bps) - 1; maxval = (1 << bps) - 1;
if (maxval == 1 && spp == 1)
{ switch (photomet) {
grayscale = 1; case PHOTOMETRIC_MINISBLACK:
case PHOTOMETRIC_MINISWHITE:
image_type = GRAY; image_type = GRAY;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE; layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE;
} break;
else
{
switch (photomet)
{
case PHOTOMETRIC_MINISBLACK:
grayscale = 1;
image_type = GRAY;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE;
break;
case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_RGB:
grayscale = 1; image_type = RGB;
image_type = GRAY; layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE; break;
break;
case PHOTOMETRIC_PALETTE: case PHOTOMETRIC_PALETTE:
if (alpha) image_type = INDEXED;
g_print ("ignoring alpha channel on indexed color image\n"); layer_type = (alpha) ? INDEXEDA_IMAGE : INDEXED_IMAGE;
break;
if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redcolormap, case PHOTOMETRIC_MASK:
&greencolormap, &bluecolormap)) g_error ("TIFF Can't handle PHOTOMETRIC_MASK\n");
{ gimp_quit ();
g_print ("error getting colormaps\n"); break;
gimp_quit (); default:
} g_error ("TIFF Unknown photometric: %d\n", photomet);
numcolors = maxval + 1; gimp_quit ();
maxval = 255; }
grayscale = 0;
for (i = 0; i < numcolors; i++) if ((image = gimp_image_new (cols, rows, image_type)) == -1) {
{ g_error ("TIFF Can't allocate new image\n");
redcolormap[i] >>= 8; gimp_quit ();
greencolormap[i] >>= 8; }
bluecolormap[i] >>= 8; gimp_image_set_filename (image, filename);
}
if (numcolors > 256) /* Install colormap for INDEXED images only */
{ if (image_type == INDEXED) {
image_type = RGB; if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) {
layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE; g_error ("TIFF Can't get colormaps\n");
}
else
{
image_type = INDEXED;
layer_type = (alpha) ? INDEXEDA_IMAGE : INDEXED_IMAGE;
}
break;
case PHOTOMETRIC_RGB:
grayscale = 0;
image_type = RGB;
layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE;
break;
case PHOTOMETRIC_MASK:
g_print ("don't know how to handle PHOTOMETRIC_MASK\n");
gimp_quit ();
default:
g_print ("unknown photometric: %d\n", photomet);
gimp_quit ();
}
}
image_ID = gimp_image_new (cols, rows, image_type);
if (image_ID == -1)
{
g_print ("can't allocate new image\n");
gimp_quit (); gimp_quit ();
} }
gimp_image_set_filename (image_ID, filename);
if ((image_type == INDEXED) && (numcolors <= 256)) for (i = 0, j = 0; i <= maxval; i++) {
{ cmap[j++] = redmap[i] >> 8;
guchar *cmap; cmap[j++] = greenmap[i] >> 8;
gint i, j; cmap[j++] = bluemap[i] >> 8;
cmap = g_new (guchar, numcolors * 3);
for (i = 0, j = 0; i < numcolors; i++)
{
cmap[j++] = redcolormap[i];
cmap[j++] = greencolormap[i];
cmap[j++] = bluecolormap[i];
}
gimp_image_set_cmap (image_ID, cmap, numcolors);
g_free (cmap);
} }
gimp_image_set_cmap (image, cmap, maxval + 1);
}
layer_ID = gimp_layer_new (image_ID, "Background", layer = gimp_layer_new (image, "Background", cols, rows, layer_type,
cols, rows, layer_type,
100, NORMAL_MODE); 100, NORMAL_MODE);
gimp_image_add_layer (image_ID, layer_ID, 0); gimp_image_add_layer (image, layer, 0);
drawable = gimp_drawable_get (layer);
buf = g_new (guchar, TIFFScanlineSize (tif));
drawable = gimp_drawable_get (layer_ID);
source= g_new (guchar, TIFFScanlineSize (tif));
tile_height = gimp_tile_height (); tile_height = gimp_tile_height ();
dest = g_new (guchar, tile_height * cols * drawable->bpp); dest = g_new (guchar, tile_height * cols * drawable->bpp);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, cols, rows, TRUE, FALSE); gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, cols, rows, TRUE, FALSE);
if (num_extra - alpha > 0) if (extra - alpha > 0)
channel = g_new (channel_data, num_extra - alpha); channel = g_new (channel_data, extra - alpha);
for (k= 0; alpha + k < num_extra; ++k) /* Add alpha channels as appropriate */
{ for (i= 0; alpha + i < extra; ++i) {
channel[k].ID= gimp_channel_new(image_ID, "TIFF Channel", cols, rows, channel[i].ID= gimp_channel_new(image, "TIFF Channel", cols, rows,
100.0, colors); 100.0, colors);
gimp_image_add_channel(image_ID, channel[k].ID, 0); gimp_image_add_channel(image, channel[i].ID, 0);
channel[k].drawable= gimp_drawable_get (channel[k].ID); channel[i].drawable= gimp_drawable_get (channel[i].ID);
channel[k].pixels= g_new(guchar, tile_height * cols); channel[i].pixels= g_new(guchar, tile_height * cols);
gimp_pixel_rgn_init (&(channel[k].pixel_rgn), channel[k].drawable, 0, 0, gimp_pixel_rgn_init (&(channel[i].pixel_rgn), channel[i].drawable, 0, 0,
cols, rows, TRUE, FALSE); cols, rows, TRUE, FALSE);
} }
#define NEXTSAMPLE \ /* Step through all <= 8-bit samples in an image */
#define NEXTSAMPLE(var) \
{ \ { \
if ( bitsleft == 0 ) \ if (bitsleft == 0) \
{ \ { \
s++; \ s++; \
bitsleft = 8; \ bitsleft = 8; \
} \ } \
bitsleft -= bps; \ bitsleft -= bps; \
sample = ( *s >> bitsleft ) & maxval; \ var = ( *s >> bitsleft ) & maxval; \
} }
for (y = 0; y < rows; y = yend) for (start= 0, row = 0; row < rows; ++row) {
{ d= dest + cols * (row % tile_height) * drawable->bpp;
yend = y + tile_height;
yend = MIN (yend, rows);
for (row = y; row < yend; row++) /* Special cases: Scanline is compatible with GIMP storage */
{ if (extra == 0 && bps == 8) {
if (TIFFReadScanline (tif, buf, row, 0) < 0) if (TIFFReadScanline (tif, d, row, 0) < 0) {
{ g_error ("TIFF Bad data read on line %d\n", row);
g_print ("bad data read on line %d\n", row); gimp_quit ();
gimp_quit (); }
/* Or read in and process each sample -- slower */
} else {
if (TIFFReadScanline (tif, source, row, 0) < 0) {
g_error ("TIFF Bad data read on line %d\n", row);
gimp_quit ();
}
for (i= 0; alpha + i < extra; ++i) {
channel[i].pixel= channel[i].pixels + cols * (row % tile_height);
}
/* Set s/bitleft ready to use NEXTSAMPLE macro */
s= source;
bitsleft= 8;
switch (photomet) {
case PHOTOMETRIC_MINISBLACK:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(gray_val);
if (alpha) {
NEXTSAMPLE(alpha_val);
if (alpha_val)
*d++ = (gray_val * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
} else {
*d++ = (gray_val * 255) / maxval;
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_MINISWHITE:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(gray_val);
if (alpha) {
NEXTSAMPLE(alpha_val);
if (alpha_val)
*d++ = ((maxval - gray_val) * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
} else {
*d++ = ((maxval - gray_val) * 255) / maxval;
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_PALETTE:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(*d++);
if (alpha) {
NEXTSAMPLE(*d++);
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_RGB:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(red_val)
NEXTSAMPLE(green_val)
NEXTSAMPLE(blue_val)
if (alpha) {
NEXTSAMPLE(alpha_val)
if (alpha_val) {
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
} else {
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
} else {
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
} }
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
bitsleft = 8; default:
s = buf; /* This case was handled earlier */
d = dest + cols * (row - y) * drawable->bpp; g_assert_not_reached();
for (k= 0; alpha + k < num_extra; ++k) }
channel[k].pixel= channel[k].pixels + cols * (row - y);
switch (photomet)
{
case PHOTOMETRIC_MINISBLACK:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
gray_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
*d++ = (gray_val * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
}
else
*d++ = (gray_val * 255) / maxval;
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_MINISWHITE:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
gray_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
*d++ = ((maxval - gray_val) * 65025)
/ (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
}
else
*d++ = ((maxval - gray_val) * 255) / maxval ;
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_PALETTE:
if (numcolors > 256)
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
red_val = redcolormap[sample];
green_val = greencolormap[sample];
blue_val = bluecolormap[sample];
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
{
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
}
else
{
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
}
else
{
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
else
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
if (alpha)
{
*d++ = sample;
NEXTSAMPLE;
*d++ = sample;
}
else
{
*d++ = sample;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_RGB:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
red_val = sample;
NEXTSAMPLE;
green_val = sample;
NEXTSAMPLE;
blue_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
{
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
}
else
{
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
}
else
{
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
default:
g_print ("unknown photometric: %d\n", photomet);
gimp_quit ();
}
}
gimp_pixel_rgn_set_rect (&pixel_rgn, dest, 0, y, cols, yend - y);
for (k= 0; alpha + k < num_extra; ++k)
gimp_pixel_rgn_set_rect(&(channel[k].pixel_rgn),
channel[k].pixels, 0, y, cols, yend -y);
gimp_progress_update ((double) row / (double) rows);
} }
if (((row + 1) % tile_height) == 0 || row + 1 == rows) {
gimp_pixel_rgn_set_rect (&pixel_rgn, dest, 0, start, cols, 1+row-start);
for (i= 0; alpha + i < extra; ++i) {
gimp_pixel_rgn_set_rect(&(channel[i].pixel_rgn), channel[i].pixels,
0, start, cols, 1+row-start);
}
gimp_progress_update ((double) row / (double) rows);
start= row + 1;
}
}
gimp_drawable_flush (drawable); gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable); gimp_drawable_detach (drawable);
return image_ID; return image;
} }
/* /*
@ -669,11 +566,7 @@ load_image (char *filename)
** other special, indirect and consequential damages. ** other special, indirect and consequential damages.
*/ */
static gint static gint save_image (char *filename, gint32 image, gint32 layer) {
save_image (char *filename,
gint32 image_ID,
gint32 drawable_ID)
{
TIFF *tif; TIFF *tif;
unsigned short red[256]; unsigned short red[256];
unsigned short grn[256]; unsigned short grn[256];
@ -720,8 +613,8 @@ save_image (char *filename,
gimp_progress_init (name); gimp_progress_init (name);
free (name); free (name);
drawable = gimp_drawable_get (drawable_ID); drawable = gimp_drawable_get (layer);
drawable_type = gimp_drawable_type (drawable_ID); drawable_type = gimp_drawable_type (layer);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE); gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE);
cols = drawable->width; cols = drawable->width;
@ -764,7 +657,7 @@ save_image (char *filename,
bytesperrow = cols; bytesperrow = cols;
alpha = 0; alpha = 0;
cmap = gimp_image_get_cmap (image_ID, &colors); cmap = gimp_image_get_cmap (image, &colors);
for (i = 0; i < colors; i++) for (i = 0; i < colors; i++)
{ {
@ -798,13 +691,13 @@ save_image (char *filename,
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric); TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField (tif, TIFFTAG_FILLORDER, fillorder); TIFFSetField (tif, TIFFTAG_FILLORDER, fillorder);
TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, filename); TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, filename);
TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "created with The GIMP"); TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "Created with The GIMP");
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
/* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */ /* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
if (gimp_drawable_type (drawable_ID) == INDEXED_IMAGE) if (drawable_type == INDEXED_IMAGE)
TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu); TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu);
/* array to rearrange data */ /* array to rearrange data */

View File

@ -1,7 +1,7 @@
/* tiff loading and saving for the GIMP /* tiff loading and saving for the GIMP
* -Peter Mattis * -Peter Mattis
* various fixes along the route to GIMP 1.0 * The TIFF loading code has been completely revamped by Nick Lamb
* -Nick Lamb and others (list yourselves here people) * njl195@zepler.org.uk -- 18 May 1998
* *
* The code for this filter is based on "tifftopnm" and "pnmtotiff", * The code for this filter is based on "tifftopnm" and "pnmtotiff",
* 2 programs that are a part of the netpbm package. * 2 programs that are a part of the netpbm package.
@ -57,8 +57,8 @@ static void run (char *name,
GParam **return_vals); GParam **return_vals);
static gint32 load_image (char *filename); static gint32 load_image (char *filename);
static gint save_image (char *filename, static gint save_image (char *filename,
gint32 image_ID, gint32 image,
gint32 drawable_ID); gint32 drawable);
static gint save_dialog (); static gint save_dialog ();
@ -123,9 +123,9 @@ query ()
gimp_install_procedure ("file_tiff_load", gimp_install_procedure ("file_tiff_load",
"loads files of the tiff file format", "loads files of the tiff file format",
"FIXME: write help for tiff_load", "FIXME: write help for tiff_load",
"Spencer Kimball & Peter Mattis", "Spencer Kimball, Peter Mattis & Nick Lamb",
"Spencer Kimball & Peter Mattis", "Nick Lamb <njl195@.ecs.soton.ac.uk>",
"1995-1996", "1995-1996,1998",
"<Load>/Tiff", "<Load>/Tiff",
NULL, NULL,
PROC_PLUG_IN, PROC_PLUG_IN,
@ -139,7 +139,7 @@ query ()
"Spencer Kimball & Peter Mattis", "Spencer Kimball & Peter Mattis",
"1995-1996", "1995-1996",
"<Save>/Tiff", "<Save>/Tiff",
"RGB*, GRAY*", "RGB*, GRAY*, INDEXED",
PROC_PLUG_IN, PROC_PLUG_IN,
nsave_args, 0, nsave_args, 0,
save_args, NULL); save_args, NULL);
@ -159,7 +159,7 @@ run (char *name,
static GParam values[2]; static GParam values[2];
GRunModeType run_mode; GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS; GStatusType status = STATUS_SUCCESS;
gint32 image_ID; gint32 image;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
@ -170,14 +170,14 @@ run (char *name,
if (strcmp (name, "file_tiff_load") == 0) if (strcmp (name, "file_tiff_load") == 0)
{ {
image_ID = load_image (param[1].data.d_string); image = load_image (param[1].data.d_string);
if (image_ID != -1) if (image != -1)
{ {
*nreturn_vals = 2; *nreturn_vals = 2;
values[0].data.d_status = STATUS_SUCCESS; values[0].data.d_status = STATUS_SUCCESS;
values[1].type = PARAM_IMAGE; values[1].type = PARAM_IMAGE;
values[1].data.d_image = image_ID; values[1].data.d_image = image;
} }
else else
{ {
@ -240,410 +240,307 @@ run (char *name,
} }
} }
static gint32 static gint32 load_image (char *filename) {
load_image (char *filename)
{
TIFF *tif; TIFF *tif;
int col; unsigned short bps, spp, photomet;
int cols, rows, maxval, alpha;
int image, layer, tile_height;
unsigned short *redmap, *greenmap, *bluemap;
guchar cmap[768];
int image_type= 0, layer_type= 0;
unsigned short *extra_types, extra = 0;
int col, row, start, i, j;
unsigned char sample; unsigned char sample;
int bitsleft; int bitsleft;
int cols, rows, grayscale;
int alpha;
int gray_val, red_val, green_val, blue_val, alpha_val; int gray_val, red_val, green_val, blue_val, alpha_val;
int numcolors;
int row, i; guchar *source, *s, *dest, *d;
guchar *buf, *s;
guchar *dest, *d;
int maxval;
int image_type;
int layer_type;
unsigned short bps, spp, photomet;
unsigned short *redcolormap;
unsigned short *greencolormap;
unsigned short *bluecolormap;
unsigned short k, num_extra = 0;
unsigned short *extra_samples;
int image_ID;
int layer_ID;
GDrawable *drawable; GDrawable *drawable;
GPixelRgn pixel_rgn; GPixelRgn pixel_rgn;
int tile_height;
int y, yend;
char *name; char *name;
typedef struct {
gint32 ID;
GDrawable *drawable;
GPixelRgn pixel_rgn;
guchar *pixels, *pixel;
} channel_data;
channel_data *channel;
guchar colors[3]= {0, 0, 0}; guchar colors[3]= {0, 0, 0};
tif = TIFFOpen (filename, "r"); typedef struct {
if (!tif) gint32 ID;
{ GDrawable *drawable;
g_warning ("can't open \"%s\"\n", filename); GPixelRgn pixel_rgn;
gimp_quit (); guchar *pixels;
} guchar *pixel;
} channel_data;
name = malloc (strlen (filename) + 12); channel_data *channel= NULL;
tif = TIFFOpen (filename, "r");
if (!tif) {
g_error ("TIFF Can't open \"%s\"\n", filename);
gimp_quit ();
}
name = g_malloc (strlen (filename) + 12);
sprintf (name, "Loading %s:", filename); sprintf (name, "Loading %s:", filename);
gimp_progress_init (name); gimp_progress_init (name);
free (name); g_free (name);
if (!TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bps)) if (!TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bps))
bps = 1; bps = 1;
if (bps > 8) {
g_error("TIFF Can't handle samples wider than 8-bit\n");
gimp_quit();
}
if (!TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &spp)) if (!TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &spp))
spp = 1; spp = 1;
if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &num_extra, &extra_samples)) if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &extra, &extra_types))
alpha = 0; extra = 0;
if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet))
{ if (!TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &cols)) {
g_warning ("error getting photometric\n"); g_error ("TIFF Can't get image width\n");
gimp_quit (); gimp_quit ();
} }
if (!TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &rows)) {
g_error ("TIFF Can't get image length\n");
gimp_quit ();
}
if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet)) {
g_error ("TIFF Can't get photometric\n");
gimp_quit ();
}
/* test if the extrasample represents an associated alpha channel... */ /* test if the extrasample represents an associated alpha channel... */
if (num_extra > 0 && (extra_samples [0] == EXTRASAMPLE_ASSOCALPHA)) if (extra > 0 && (extra_types[0] == EXTRASAMPLE_ASSOCALPHA)) {
alpha = 1; alpha = 1;
else } else {
alpha = 0; alpha = 0;
}
if (spp > 3) alpha = 1; /* Kludge - like all the rest of this -- njl195 */ /* some programs seem to think alpha etc. aren't "extra" samples (?) */
if (spp > 3) {
TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &cols); extra= spp - 3;
TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &rows); }
maxval = (1 << bps) - 1; maxval = (1 << bps) - 1;
if (maxval == 1 && spp == 1)
{ switch (photomet) {
grayscale = 1; case PHOTOMETRIC_MINISBLACK:
case PHOTOMETRIC_MINISWHITE:
image_type = GRAY; image_type = GRAY;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE; layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE;
} break;
else
{
switch (photomet)
{
case PHOTOMETRIC_MINISBLACK:
grayscale = 1;
image_type = GRAY;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE;
break;
case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_RGB:
grayscale = 1; image_type = RGB;
image_type = GRAY; layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE;
layer_type = (alpha) ? GRAYA_IMAGE : GRAY_IMAGE; break;
break;
case PHOTOMETRIC_PALETTE: case PHOTOMETRIC_PALETTE:
if (alpha) image_type = INDEXED;
g_print ("ignoring alpha channel on indexed color image\n"); layer_type = (alpha) ? INDEXEDA_IMAGE : INDEXED_IMAGE;
break;
if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redcolormap, case PHOTOMETRIC_MASK:
&greencolormap, &bluecolormap)) g_error ("TIFF Can't handle PHOTOMETRIC_MASK\n");
{ gimp_quit ();
g_print ("error getting colormaps\n"); break;
gimp_quit (); default:
} g_error ("TIFF Unknown photometric: %d\n", photomet);
numcolors = maxval + 1; gimp_quit ();
maxval = 255; }
grayscale = 0;
for (i = 0; i < numcolors; i++) if ((image = gimp_image_new (cols, rows, image_type)) == -1) {
{ g_error ("TIFF Can't allocate new image\n");
redcolormap[i] >>= 8; gimp_quit ();
greencolormap[i] >>= 8; }
bluecolormap[i] >>= 8; gimp_image_set_filename (image, filename);
}
if (numcolors > 256) /* Install colormap for INDEXED images only */
{ if (image_type == INDEXED) {
image_type = RGB; if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) {
layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE; g_error ("TIFF Can't get colormaps\n");
}
else
{
image_type = INDEXED;
layer_type = (alpha) ? INDEXEDA_IMAGE : INDEXED_IMAGE;
}
break;
case PHOTOMETRIC_RGB:
grayscale = 0;
image_type = RGB;
layer_type = (alpha) ? RGBA_IMAGE : RGB_IMAGE;
break;
case PHOTOMETRIC_MASK:
g_print ("don't know how to handle PHOTOMETRIC_MASK\n");
gimp_quit ();
default:
g_print ("unknown photometric: %d\n", photomet);
gimp_quit ();
}
}
image_ID = gimp_image_new (cols, rows, image_type);
if (image_ID == -1)
{
g_print ("can't allocate new image\n");
gimp_quit (); gimp_quit ();
} }
gimp_image_set_filename (image_ID, filename);
if ((image_type == INDEXED) && (numcolors <= 256)) for (i = 0, j = 0; i <= maxval; i++) {
{ cmap[j++] = redmap[i] >> 8;
guchar *cmap; cmap[j++] = greenmap[i] >> 8;
gint i, j; cmap[j++] = bluemap[i] >> 8;
cmap = g_new (guchar, numcolors * 3);
for (i = 0, j = 0; i < numcolors; i++)
{
cmap[j++] = redcolormap[i];
cmap[j++] = greencolormap[i];
cmap[j++] = bluecolormap[i];
}
gimp_image_set_cmap (image_ID, cmap, numcolors);
g_free (cmap);
} }
gimp_image_set_cmap (image, cmap, maxval + 1);
}
layer_ID = gimp_layer_new (image_ID, "Background", layer = gimp_layer_new (image, "Background", cols, rows, layer_type,
cols, rows, layer_type,
100, NORMAL_MODE); 100, NORMAL_MODE);
gimp_image_add_layer (image_ID, layer_ID, 0); gimp_image_add_layer (image, layer, 0);
drawable = gimp_drawable_get (layer);
buf = g_new (guchar, TIFFScanlineSize (tif));
drawable = gimp_drawable_get (layer_ID);
source= g_new (guchar, TIFFScanlineSize (tif));
tile_height = gimp_tile_height (); tile_height = gimp_tile_height ();
dest = g_new (guchar, tile_height * cols * drawable->bpp); dest = g_new (guchar, tile_height * cols * drawable->bpp);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, cols, rows, TRUE, FALSE); gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, cols, rows, TRUE, FALSE);
if (num_extra - alpha > 0) if (extra - alpha > 0)
channel = g_new (channel_data, num_extra - alpha); channel = g_new (channel_data, extra - alpha);
for (k= 0; alpha + k < num_extra; ++k) /* Add alpha channels as appropriate */
{ for (i= 0; alpha + i < extra; ++i) {
channel[k].ID= gimp_channel_new(image_ID, "TIFF Channel", cols, rows, channel[i].ID= gimp_channel_new(image, "TIFF Channel", cols, rows,
100.0, colors); 100.0, colors);
gimp_image_add_channel(image_ID, channel[k].ID, 0); gimp_image_add_channel(image, channel[i].ID, 0);
channel[k].drawable= gimp_drawable_get (channel[k].ID); channel[i].drawable= gimp_drawable_get (channel[i].ID);
channel[k].pixels= g_new(guchar, tile_height * cols); channel[i].pixels= g_new(guchar, tile_height * cols);
gimp_pixel_rgn_init (&(channel[k].pixel_rgn), channel[k].drawable, 0, 0, gimp_pixel_rgn_init (&(channel[i].pixel_rgn), channel[i].drawable, 0, 0,
cols, rows, TRUE, FALSE); cols, rows, TRUE, FALSE);
} }
#define NEXTSAMPLE \ /* Step through all <= 8-bit samples in an image */
#define NEXTSAMPLE(var) \
{ \ { \
if ( bitsleft == 0 ) \ if (bitsleft == 0) \
{ \ { \
s++; \ s++; \
bitsleft = 8; \ bitsleft = 8; \
} \ } \
bitsleft -= bps; \ bitsleft -= bps; \
sample = ( *s >> bitsleft ) & maxval; \ var = ( *s >> bitsleft ) & maxval; \
} }
for (y = 0; y < rows; y = yend) for (start= 0, row = 0; row < rows; ++row) {
{ d= dest + cols * (row % tile_height) * drawable->bpp;
yend = y + tile_height;
yend = MIN (yend, rows);
for (row = y; row < yend; row++) /* Special cases: Scanline is compatible with GIMP storage */
{ if (extra == 0 && bps == 8) {
if (TIFFReadScanline (tif, buf, row, 0) < 0) if (TIFFReadScanline (tif, d, row, 0) < 0) {
{ g_error ("TIFF Bad data read on line %d\n", row);
g_print ("bad data read on line %d\n", row); gimp_quit ();
gimp_quit (); }
/* Or read in and process each sample -- slower */
} else {
if (TIFFReadScanline (tif, source, row, 0) < 0) {
g_error ("TIFF Bad data read on line %d\n", row);
gimp_quit ();
}
for (i= 0; alpha + i < extra; ++i) {
channel[i].pixel= channel[i].pixels + cols * (row % tile_height);
}
/* Set s/bitleft ready to use NEXTSAMPLE macro */
s= source;
bitsleft= 8;
switch (photomet) {
case PHOTOMETRIC_MINISBLACK:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(gray_val);
if (alpha) {
NEXTSAMPLE(alpha_val);
if (alpha_val)
*d++ = (gray_val * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
} else {
*d++ = (gray_val * 255) / maxval;
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_MINISWHITE:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(gray_val);
if (alpha) {
NEXTSAMPLE(alpha_val);
if (alpha_val)
*d++ = ((maxval - gray_val) * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
} else {
*d++ = ((maxval - gray_val) * 255) / maxval;
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_PALETTE:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(*d++);
if (alpha) {
NEXTSAMPLE(*d++);
}
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_RGB:
for (col = 0; col < cols; col++) {
NEXTSAMPLE(red_val)
NEXTSAMPLE(green_val)
NEXTSAMPLE(blue_val)
if (alpha) {
NEXTSAMPLE(alpha_val)
if (alpha_val) {
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
} else {
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
} else {
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
} }
for (i= 0; alpha + i < extra; ++i) {
NEXTSAMPLE(sample);
*channel[i].pixel++ = sample;
}
}
break;
bitsleft = 8; default:
s = buf; /* This case was handled earlier */
d = dest + cols * (row - y) * drawable->bpp; g_assert_not_reached();
for (k= 0; alpha + k < num_extra; ++k) }
channel[k].pixel= channel[k].pixels + cols * (row - y);
switch (photomet)
{
case PHOTOMETRIC_MINISBLACK:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
gray_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
*d++ = (gray_val * 65025) / (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
}
else
*d++ = (gray_val * 255) / maxval;
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_MINISWHITE:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
gray_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
*d++ = ((maxval - gray_val) * 65025)
/ (alpha_val * maxval);
else
*d++ = 0;
*d++ = alpha_val;
}
else
*d++ = ((maxval - gray_val) * 255) / maxval ;
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_PALETTE:
if (numcolors > 256)
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
red_val = redcolormap[sample];
green_val = greencolormap[sample];
blue_val = bluecolormap[sample];
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
{
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
}
else
{
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
}
else
{
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
else
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
if (alpha)
{
*d++ = sample;
NEXTSAMPLE;
*d++ = sample;
}
else
{
*d++ = sample;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
case PHOTOMETRIC_RGB:
for (col = 0; col < cols; col++)
{
NEXTSAMPLE;
red_val = sample;
NEXTSAMPLE;
green_val = sample;
NEXTSAMPLE;
blue_val = sample;
if (alpha)
{
NEXTSAMPLE;
alpha_val = sample;
if (alpha_val)
{
*d++ = (red_val * 255) / alpha_val;
*d++ = (green_val * 255) / alpha_val;
*d++ = (blue_val * 255) / alpha_val;
}
else
{
*d++ = 0;
*d++ = 0;
*d++ = 0;
}
*d++ = alpha_val;
}
else
{
*d++ = red_val;
*d++ = green_val;
*d++ = blue_val;
}
for (k= 0; alpha + k < num_extra; ++k)
{
NEXTSAMPLE;
*channel[k].pixel++ = sample;
}
}
break;
default:
g_print ("unknown photometric: %d\n", photomet);
gimp_quit ();
}
}
gimp_pixel_rgn_set_rect (&pixel_rgn, dest, 0, y, cols, yend - y);
for (k= 0; alpha + k < num_extra; ++k)
gimp_pixel_rgn_set_rect(&(channel[k].pixel_rgn),
channel[k].pixels, 0, y, cols, yend -y);
gimp_progress_update ((double) row / (double) rows);
} }
if (((row + 1) % tile_height) == 0 || row + 1 == rows) {
gimp_pixel_rgn_set_rect (&pixel_rgn, dest, 0, start, cols, 1+row-start);
for (i= 0; alpha + i < extra; ++i) {
gimp_pixel_rgn_set_rect(&(channel[i].pixel_rgn), channel[i].pixels,
0, start, cols, 1+row-start);
}
gimp_progress_update ((double) row / (double) rows);
start= row + 1;
}
}
gimp_drawable_flush (drawable); gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable); gimp_drawable_detach (drawable);
return image_ID; return image;
} }
/* /*
@ -669,11 +566,7 @@ load_image (char *filename)
** other special, indirect and consequential damages. ** other special, indirect and consequential damages.
*/ */
static gint static gint save_image (char *filename, gint32 image, gint32 layer) {
save_image (char *filename,
gint32 image_ID,
gint32 drawable_ID)
{
TIFF *tif; TIFF *tif;
unsigned short red[256]; unsigned short red[256];
unsigned short grn[256]; unsigned short grn[256];
@ -720,8 +613,8 @@ save_image (char *filename,
gimp_progress_init (name); gimp_progress_init (name);
free (name); free (name);
drawable = gimp_drawable_get (drawable_ID); drawable = gimp_drawable_get (layer);
drawable_type = gimp_drawable_type (drawable_ID); drawable_type = gimp_drawable_type (layer);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE); gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE);
cols = drawable->width; cols = drawable->width;
@ -764,7 +657,7 @@ save_image (char *filename,
bytesperrow = cols; bytesperrow = cols;
alpha = 0; alpha = 0;
cmap = gimp_image_get_cmap (image_ID, &colors); cmap = gimp_image_get_cmap (image, &colors);
for (i = 0; i < colors; i++) for (i = 0; i < colors; i++)
{ {
@ -798,13 +691,13 @@ save_image (char *filename,
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric); TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField (tif, TIFFTAG_FILLORDER, fillorder); TIFFSetField (tif, TIFFTAG_FILLORDER, fillorder);
TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, filename); TIFFSetField (tif, TIFFTAG_DOCUMENTNAME, filename);
TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "created with The GIMP"); TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "Created with The GIMP");
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
/* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */ /* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
if (gimp_drawable_type (drawable_ID) == INDEXED_IMAGE) if (drawable_type == INDEXED_IMAGE)
TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu); TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu);
/* array to rearrange data */ /* array to rearrange data */