gd_tiff.c (libgd-2.2.4) | : | gd_tiff.c (libgd-2.2.5) | ||
---|---|---|---|---|
skipping to change at line 535 | skipping to change at line 535 | |||
int extra, | int extra, | |||
int align) | int align) | |||
{ | { | |||
int x = startx, y = starty; | int x = startx, y = starty; | |||
(void)has_alpha; | (void)has_alpha; | |||
(void)extra; | (void)extra; | |||
(void)align; | (void)align; | |||
for (y = starty; y < starty + height; y++) { | for (y = starty; y < starty + height; y++) { | |||
for (x = startx; x < startx + width; x++) { | for (x = startx; x < startx + width;) { | |||
register unsigned char curr = *src++; | register unsigned char curr = *src++; | |||
register unsigned char mask; | register unsigned char mask; | |||
if (photometric == PHOTOMETRIC_MINISWHITE) { | if (photometric == PHOTOMETRIC_MINISWHITE) { | |||
curr = ~curr; | curr = ~curr; | |||
} | } | |||
for (mask = 0x80; mask != 0 && x < startx + width; mask > >= 1) { | for (mask = 0x80; mask != 0 && x < startx + width; x++, m ask >>= 1) { | |||
gdImageSetPixel(im, x, y, ((curr & mask) != 0)?0: 1); | gdImageSetPixel(im, x, y, ((curr & mask) != 0)?0: 1); | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
static void readTiff8bit (const unsigned char *src, | static void readTiff8bit (const unsigned char *src, | |||
gdImagePtr im, | gdImagePtr im, | |||
uint16 photometric, | uint16 photometric, | |||
int startx, | int startx, | |||
skipping to change at line 646 | skipping to change at line 646 | |||
} | } | |||
static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | |||
char has_alpha, char is_bw, int extra) | char has_alpha, char is_bw, int extra) | |||
{ | { | |||
uint16 planar; | uint16 planar; | |||
int im_width, im_height; | int im_width, im_height; | |||
int tile_width, tile_height; | int tile_width, tile_height; | |||
int x, y, height, width; | int x, y, height, width; | |||
unsigned char *buffer; | unsigned char *buffer; | |||
int success = GD_SUCCESS; | ||||
if (!TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar)) { | if (!TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar)) { | |||
planar = PLANARCONFIG_CONTIG; | planar = PLANARCONFIG_CONTIG; | |||
} | } | |||
if (TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &im_width) == 0 || | if (TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &im_width) == 0 || | |||
TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &im_height) == 0 || | TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &im_height) == 0 || | |||
TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width) == 0 || | TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width) == 0 || | |||
TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height) == 0) { | TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height) == 0) { | |||
return FALSE; | return FALSE; | |||
} | } | |||
buffer = (unsigned char *) gdMalloc (TIFFTileSize (tif)); | buffer = (unsigned char *) gdMalloc (TIFFTileSize (tif)); | |||
if (!buffer) { | if (!buffer) { | |||
return FALSE; | return FALSE; | |||
} | } | |||
for (y = 0; y < im_height; y += tile_height) { | for (y = 0; y < im_height; y += tile_height) { | |||
for (x = 0; x < im_width; x += tile_width) { | for (x = 0; x < im_width; x += tile_width) { | |||
TIFFReadTile(tif, buffer, x, y, 0, 0); | if (TIFFReadTile(tif, buffer, x, y, 0, 0) < 0) { | |||
success = GD_FAILURE; | ||||
goto end; | ||||
} | ||||
width = MIN(im_width - x, tile_width); | width = MIN(im_width - x, tile_width); | |||
height = MIN(im_height - y, tile_height); | height = MIN(im_height - y, tile_height); | |||
if (bps == 16) { | if (bps == 16) { | |||
} else if (bps == 8) { | } else if (bps == 8) { | |||
readTiff8bit(buffer, im, photometric, x, y, width , height, has_alpha, extra, 0); | readTiff8bit(buffer, im, photometric, x, y, width , height, has_alpha, extra, 0); | |||
} else if (is_bw) { | } else if (is_bw) { | |||
readTiffBw(buffer, im, photometric, x, y, width, height, has_alpha, extra, 0); | readTiffBw(buffer, im, photometric, x, y, width, height, has_alpha, extra, 0); | |||
} else { | } else { | |||
/* TODO: implement some default reader or detect this case earlier use force_rgb */ | /* TODO: implement some default reader or detect this case earlier use force_rgb */ | |||
} | } | |||
} | } | |||
} | } | |||
end: | ||||
gdFree(buffer); | gdFree(buffer); | |||
return TRUE; | return success; | |||
} | } | |||
static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | |||
char has_alpha, char is_bw, int extra) | char has_alpha, char is_bw, int extra) | |||
{ | { | |||
uint16 planar; | uint16 planar; | |||
uint32 im_height, im_width, y; | uint32 im_height, im_width, y; | |||
unsigned char *buffer; | unsigned char *buffer; | |||
int success = GD_SUCCESS; | ||||
if (!TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar)) { | if (!TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar)) { | |||
planar = PLANARCONFIG_CONTIG; | planar = PLANARCONFIG_CONTIG; | |||
} | } | |||
if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &im_height)) { | if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &im_height)) { | |||
gd_error("Can't fetch TIFF height\n"); | gd_error("Can't fetch TIFF height\n"); | |||
return FALSE; | return FALSE; | |||
} | } | |||
skipping to change at line 717 | skipping to change at line 723 | |||
if (planar == PLANARCONFIG_CONTIG) { | if (planar == PLANARCONFIG_CONTIG) { | |||
switch (bps) { | switch (bps) { | |||
case 16: | case 16: | |||
/* TODO | /* TODO | |||
* or simply use force_rgba | * or simply use force_rgba | |||
*/ | */ | |||
break; | break; | |||
case 8: | case 8: | |||
for (y = 0; y < im_height; y++ ) { | for (y = 0; y < im_height; y++ ) { | |||
if (!TIFFReadScanline (tif, buffer, y, 0)) { | if (TIFFReadScanline (tif, buffer, y, 0) < 0) { | |||
gd_error("Error while reading scanline %i ", y); | gd_error("Error while reading scanline %i ", y); | |||
success = GD_FAILURE; | ||||
break; | break; | |||
} | } | |||
/* reading one line at a time */ | /* reading one line at a time */ | |||
readTiff8bit(buffer, im, photometric, 0, y, im_wi dth, 1, has_alpha, extra, 0); | readTiff8bit(buffer, im, photometric, 0, y, im_wi dth, 1, has_alpha, extra, 0); | |||
} | } | |||
break; | break; | |||
default: | default: | |||
if (is_bw) { | if (is_bw) { | |||
for (y = 0; y < im_height; y++ ) { | for (y = 0; y < im_height; y++ ) { | |||
if (!TIFFReadScanline (tif, buffer, y, 0) ) { | if (TIFFReadScanline (tif, buffer, y, 0) < 0) { | |||
gd_error("Error while reading sca nline %i", y); | gd_error("Error while reading sca nline %i", y); | |||
success = GD_FAILURE; | ||||
break; | break; | |||
} | } | |||
/* reading one line at a time */ | /* reading one line at a time */ | |||
readTiffBw(buffer, im, photometric, 0, y, im_width, 1, has_alpha, extra, 0); | readTiffBw(buffer, im, photometric, 0, y, im_width, 1, has_alpha, extra, 0); | |||
} | } | |||
} else { | } else { | |||
/* TODO: implement some default reader or detect this case earlier > force_rgb */ | /* TODO: implement some default reader or detect this case earlier > force_rgb */ | |||
} | } | |||
break; | break; | |||
} | } | |||
} else { | } else { | |||
/* TODO: implement a reader for separate panes. We detect this ca se earlier for now and use force_rgb */ | /* TODO: implement a reader for separate panes. We detect this ca se earlier for now and use force_rgb */ | |||
} | } | |||
gdFree(buffer); | gdFree(buffer); | |||
return GD_SUCCESS; | return success; | |||
} | } | |||
static int createFromTiffRgba(TIFF * tif, gdImagePtr im) | static int createFromTiffRgba(TIFF * tif, gdImagePtr im) | |||
{ | { | |||
int a; | int a; | |||
int x, y; | int x, y; | |||
int alphaBlendingFlag = 0; | int alphaBlendingFlag = 0; | |||
int color; | int color; | |||
int width = im->sx; | int width = im->sx; | |||
int height = im->sy; | int height = im->sy; | |||
uint32 *buffer; | uint32 *buffer; | |||
uint32 rgba; | uint32 rgba; | |||
int success; | int success; | |||
buffer = (uint32 *) gdCalloc(sizeof(uint32), width * height); | ||||
if (!buffer) { | ||||
return GD_FAILURE; | ||||
} | ||||
/* switch off colour merging on target gd image just while we write out | /* switch off colour merging on target gd image just while we write out | |||
* content - we want to preserve the alpha data until the user chooses | * content - we want to preserve the alpha data until the user chooses | |||
* what to do with the image */ | * what to do with the image */ | |||
alphaBlendingFlag = im->alphaBlendingFlag; | alphaBlendingFlag = im->alphaBlendingFlag; | |||
gdImageAlphaBlending(im, 0); | gdImageAlphaBlending(im, 0); | |||
buffer = (uint32 *) gdCalloc(sizeof(uint32), width * height); | ||||
if (!buffer) { | ||||
return GD_FAILURE; | ||||
} | ||||
success = TIFFReadRGBAImage(tif, width, height, buffer, 1); | success = TIFFReadRGBAImage(tif, width, height, buffer, 1); | |||
if (success) { | if (success) { | |||
for(y = 0; y < height; y++) { | for(y = 0; y < height; y++) { | |||
for(x = 0; x < width; x++) { | for(x = 0; x < width; x++) { | |||
/* if it doesn't already exist, allocate a new co lour, | /* if it doesn't already exist, allocate a new co lour, | |||
* else use existing one */ | * else use existing one */ | |||
rgba = buffer[(y * width + x)]; | rgba = buffer[(y * width + x)]; | |||
a = (0xff - TIFFGetA(rgba)) / 2; | a = (0xff - TIFFGetA(rgba)) / 2; | |||
color = gdTrueColorAlpha(TIFFGetR(rgba), TIFFGetG (rgba), TIFFGetB(rgba), a); | color = gdTrueColorAlpha(TIFFGetR(rgba), TIFFGetG (rgba), TIFFGetB(rgba), a); | |||
skipping to change at line 852 | skipping to change at line 860 | |||
} | } | |||
if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height)) { | if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height)) { | |||
gd_error("TIFF error, Cannot read image width"); | gd_error("TIFF error, Cannot read image width"); | |||
goto error; | goto error; | |||
} | } | |||
TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, &bps); | TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, &bps); | |||
/* Unsupported bps, force to RGBA */ | /* Unsupported bps, force to RGBA */ | |||
if (1/*bps > 8 && bps != 16*/) { | if (bps != 1 /*bps > 8 && bps != 16*/) { | |||
force_rgba = TRUE; | force_rgba = TRUE; | |||
} | } | |||
TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, &spp); | TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, &spp); | |||
if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &extra, &extra_types)) { | if (!TIFFGetField (tif, TIFFTAG_EXTRASAMPLES, &extra, &extra_types)) { | |||
extra = 0; | extra = 0; | |||
} | } | |||
if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photometric)) { | if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photometric)) { | |||
skipping to change at line 935 | skipping to change at line 943 | |||
case PHOTOMETRIC_PALETTE: | case PHOTOMETRIC_PALETTE: | |||
image_type = GD_INDEXED; | image_type = GD_INDEXED; | |||
break; | break; | |||
default: | default: | |||
force_rgba = TRUE; | force_rgba = TRUE; | |||
break; | break; | |||
} | } | |||
/* Force rgba if image has 1bps, but is not bw */ | ||||
if (bps == 1 && !is_bw) { | ||||
force_rgba = TRUE; | ||||
} | ||||
if (!TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar)) { | if (!TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar)) { | |||
planar = PLANARCONFIG_CONTIG; | planar = PLANARCONFIG_CONTIG; | |||
} | } | |||
/* Force rgba if image plans are not contiguous */ | /* Force rgba if image plans are not contiguous */ | |||
if (force_rgba || planar != PLANARCONFIG_CONTIG) { | if (force_rgba || planar != PLANARCONFIG_CONTIG) { | |||
image_type = GD_RGB; | image_type = GD_RGB; | |||
} | } | |||
if (!force_rgba && | if (!force_rgba && | |||
End of changes. 16 change blocks. | ||||
13 lines changed or deleted | 26 lines changed or added |