support 1/2/4 bit palette tiff images with alpha

This commit is contained in:
John Cupitt 2014-04-30 14:39:50 +01:00
parent 5ec80bf163
commit b1b3c6e9de
2 changed files with 22 additions and 20 deletions

View File

@ -25,6 +25,7 @@
- added vips_tiffload_buffer()
- added vips_foreign_load_buffer(), vips_foreign_save_buffer()
- added vips_object_set_from_string()
- support 1/2/4 bit palette tiff images with alpha
6/3/14 started 7.38.6
- grey ramp minimum was wrong

View File

@ -146,6 +146,8 @@
* - palette images can have an alpha
* 22/4/14
* - add read from buffer
* 30/4/14
* - 1/2/4 bit palette images can have alpha
*/
/*
@ -707,12 +709,13 @@ typedef struct {
gboolean mono;
} PaletteRead;
/* Per-scanline process function for palette images.
/* 1/2/4 bit samples with an 8-bit palette.
*/
static void
palette_line_bit( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n, void *client )
{
PaletteRead *read = (PaletteRead *) client;
int samples = rtiff->samples_per_pixel;
int bit;
VipsPel data;
@ -720,7 +723,7 @@ palette_line_bit( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n, void *client )
bit = 0;
data = 0;
for( x = 0; x < n; x++ ) {
for( x = 0; x < n * samples; x++ ) {
int i;
if( bit <= 0 ) {
@ -732,20 +735,25 @@ palette_line_bit( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n, void *client )
data <<= rtiff->bits_per_sample;
bit -= rtiff->bits_per_sample;
if( read->mono ) {
q[0] = read->red8[i];
q += 1;
}
else {
q[0] = read->red8[i];
q[1] = read->green8[i];
q[2] = read->blue8[i];
q += 3;
/* The first band goes through the LUT, subsequent bands are
* left-justified and copied.
*/
if( x % samples == 0 ) {
if( read->mono )
*q++ = read->red8[i];
else {
q[0] = read->red8[i];
q[1] = read->green8[i];
q[2] = read->blue8[i];
q += 3;
}
}
else
*q++ = i << (8 - rtiff->bits_per_sample);
}
}
/* The tiff is 8-bit and can have an alpha.
/* 8-bit samples with an 8-bit palette.
*/
static void
palette_line8( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n,
@ -777,7 +785,7 @@ palette_line8( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n,
}
}
/* 16-bit tiff and can have an alpha.
/* 16-bit samples with 16-bit data in the palette.
*/
static void
palette_line16( ReadTiff *rtiff, VipsPel *q, VipsPel *p, int n,
@ -827,13 +835,6 @@ parse_palette( ReadTiff *rtiff, VipsImage *out )
return( -1 );
len = 1 << rtiff->bits_per_sample;
if( rtiff->bits_per_sample < 8 &&
rtiff->samples_per_pixel > 1 ) {
vips_error( "tiff2vips", "%s", _( "can't have an alpha for "
"palette images less than 8 bits per sample" ) );
return( -1 );
}
if( !(read = VIPS_NEW( out, PaletteRead )) ||
!(read->red8 = VIPS_ARRAY( out, len, VipsPel )) ||
!(read->green8 = VIPS_ARRAY( out, len, VipsPel )) ||