gd_tiff.c (libgd-2.3.2) | : | gd_tiff.c (libgd-2.3.3) | ||
---|---|---|---|---|
skipping to change at line 239 | skipping to change at line 239 | |||
int r, g, b, a; | int r, g, b, a; | |||
TIFF *tiff; | TIFF *tiff; | |||
int width, height; | int width, height; | |||
int color; | int color; | |||
char *scan; | char *scan; | |||
int samplesPerPixel = 3; | int samplesPerPixel = 3; | |||
int bitsPerSample; | int bitsPerSample; | |||
int transparentColorR = -1; | int transparentColorR = -1; | |||
int transparentColorG = -1; | int transparentColorG = -1; | |||
int transparentColorB = -1; | int transparentColorB = -1; | |||
uint16 extraSamples[1]; | uint16_t extraSamples[1]; | |||
uint16 *colorMapRed = NULL; | uint16_t *colorMapRed = NULL; | |||
uint16 *colorMapGreen = NULL; | uint16_t *colorMapGreen = NULL; | |||
uint16 *colorMapBlue = NULL; | uint16_t *colorMapBlue = NULL; | |||
tiff_handle *th; | tiff_handle *th; | |||
th = new_tiff_handle(out); | th = new_tiff_handle(out); | |||
if (!th) { | if (!th) { | |||
return; | return; | |||
} | } | |||
extraSamples[0] = EXTRASAMPLE_ASSOCALPHA; | extraSamples[0] = EXTRASAMPLE_ASSOCALPHA; | |||
/* read in the width/height of gd image */ | /* read in the width/height of gd image */ | |||
skipping to change at line 294 | skipping to change at line 294 | |||
(bitDepth == 24) ? PHOTOMETRIC_RGB : PHOTOMETRIC_PALETTE); | (bitDepth == 24) ? PHOTOMETRIC_RGB : PHOTOMETRIC_PALETTE); | |||
bitsPerSample = (bitDepth == 24 || bitDepth == 8) ? 8 : 1; | bitsPerSample = (bitDepth == 24 || bitDepth == 8) ? 8 : 1; | |||
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitsPerSample); | TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitsPerSample); | |||
TIFFSetField(tiff, TIFFTAG_XRESOLUTION, (float)image->res_x); | TIFFSetField(tiff, TIFFTAG_XRESOLUTION, (float)image->res_x); | |||
TIFFSetField(tiff, TIFFTAG_YRESOLUTION, (float)image->res_y); | TIFFSetField(tiff, TIFFTAG_YRESOLUTION, (float)image->res_y); | |||
/* build the color map for 8 bit images */ | /* build the color map for 8 bit images */ | |||
if(bitDepth != 24) { | if(bitDepth != 24) { | |||
colorMapRed = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); | colorMapRed = (uint16_t *) gdMalloc(3 * (1 << bitsPerSample)); | |||
if (!colorMapRed) { | if (!colorMapRed) { | |||
gdFree(th); | gdFree(th); | |||
return; | return; | |||
} | } | |||
colorMapGreen = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); | colorMapGreen = (uint16_t *) gdMalloc(3 * (1 << bitsPerSample)); | |||
if (!colorMapGreen) { | if (!colorMapGreen) { | |||
gdFree(colorMapRed); | gdFree(colorMapRed); | |||
gdFree(th); | gdFree(th); | |||
return; | return; | |||
} | } | |||
colorMapBlue = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); | colorMapBlue = (uint16_t *) gdMalloc(3 * (1 << bitsPerSample)); | |||
if (!colorMapBlue) { | if (!colorMapBlue) { | |||
gdFree(colorMapRed); | gdFree(colorMapRed); | |||
gdFree(colorMapGreen); | gdFree(colorMapGreen); | |||
gdFree(th); | gdFree(th); | |||
return; | return; | |||
} | } | |||
for(i = 0; i < image->colorsTotal; i++) { | for(i = 0; i < image->colorsTotal; i++) { | |||
colorMapRed[i] = gdImageRed(image,i) + (gdImageRed(imag e,i) * 256); | colorMapRed[i] = gdImageRed(image,i) + (gdImageRed(imag e,i) * 256); | |||
colorMapGreen[i] = gdImageGreen(image,i)+(gdImageGreen(im age,i)*256); | colorMapGreen[i] = gdImageGreen(image,i)+(gdImageGreen(im age,i)*256); | |||
skipping to change at line 450 | skipping to change at line 450 | |||
tiffWriter(image, out, bitDepth); | tiffWriter(image, out, bitDepth); | |||
/* reset clipping area to the gd image's original values */ | /* reset clipping area to the gd image's original values */ | |||
gdImageSetClip(image, clipx1P, clipy1P, clipx2P, clipy2P); | gdImageSetClip(image, clipx1P, clipy1P, clipx2P, clipy2P); | |||
} | } | |||
/* Check if we are really in 8bit mode */ | /* Check if we are really in 8bit mode */ | |||
static int checkColorMap(n, r, g, b) | static int checkColorMap(n, r, g, b) | |||
int n; | int n; | |||
uint16 *r, *g, *b; | uint16_t *r, *g, *b; | |||
{ | { | |||
while (n-- > 0) | while (n-- > 0) | |||
if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) | if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256) | |||
return (16); | return (16); | |||
return (8); | return (8); | |||
} | } | |||
/* Read and convert a TIFF colormap */ | /* Read and convert a TIFF colormap */ | |||
static int readTiffColorMap(gdImagePtr im, TIFF *tif, char is_bw, int photometri c) | static int readTiffColorMap(gdImagePtr im, TIFF *tif, char is_bw, int photometri c) | |||
{ | { | |||
uint16 *redcmap, *greencmap, *bluecmap; | uint16_t *redcmap, *greencmap, *bluecmap; | |||
uint16 bps; | uint16_t bps; | |||
int i; | int i; | |||
if (is_bw) { | if (is_bw) { | |||
if (photometric == PHOTOMETRIC_MINISWHITE) { | if (photometric == PHOTOMETRIC_MINISWHITE) { | |||
gdImageColorAllocate(im, 255,255,255); | gdImageColorAllocate(im, 255,255,255); | |||
gdImageColorAllocate(im, 0, 0, 0); | gdImageColorAllocate(im, 0, 0, 0); | |||
} else { | } else { | |||
gdImageColorAllocate(im, 0, 0, 0); | gdImageColorAllocate(im, 0, 0, 0); | |||
gdImageColorAllocate(im, 255,255,255); | gdImageColorAllocate(im, 255,255,255); | |||
} | } | |||
} else { | } else { | |||
uint16 min_sample_val, max_sample_val; | uint16_t min_sample_val, max_sample_val; | |||
if (!TIFFGetField(tif, TIFFTAG_MINSAMPLEVALUE, &min_sample_val)) { | if (!TIFFGetField(tif, TIFFTAG_MINSAMPLEVALUE, &min_sample_val)) { | |||
min_sample_val = 0; | min_sample_val = 0; | |||
} | } | |||
if (!TIFFGetField(tif, TIFFTAG_MAXSAMPLEVALUE, &max_sample_val)) { | if (!TIFFGetField(tif, TIFFTAG_MAXSAMPLEVALUE, &max_sample_val)) { | |||
max_sample_val = 255; | max_sample_val = 255; | |||
} | } | |||
if (photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTO METRIC_MINISWHITE) { | if (photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTO METRIC_MINISWHITE) { | |||
/* TODO: use TIFFTAG_MINSAMPLEVALUE and TIFFTAG_MAXSAMPLE VALUE */ | /* TODO: use TIFFTAG_MINSAMPLEVALUE and TIFFTAG_MAXSAMPLE VALUE */ | |||
skipping to change at line 516 | skipping to change at line 516 | |||
for (i = 0; i < 256; i++) { | for (i = 0; i < 256; i++) { | |||
gdImageColorAllocate(im, redcmap[i], greencmap[i], bluecm ap[i]); | gdImageColorAllocate(im, redcmap[i], greencmap[i], bluecm ap[i]); | |||
} | } | |||
#undef CVT | #undef CVT | |||
} | } | |||
return GD_SUCCESS; | return GD_SUCCESS; | |||
} | } | |||
static void readTiffBw (const unsigned char *src, | static void readTiffBw (const unsigned char *src, | |||
gdImagePtr im, | gdImagePtr im, | |||
uint16 photometric, | uint16_t photometric, | |||
int startx, | int startx, | |||
int starty, | int starty, | |||
int width, | int width, | |||
int height, | int height, | |||
char has_alpha, | char has_alpha, | |||
int extra, | int extra, | |||
int align) | int align) | |||
{ | { | |||
int x = startx, y = starty; | int x = startx, y = starty; | |||
skipping to change at line 548 | skipping to change at line 548 | |||
} | } | |||
for (mask = 0x80; mask != 0 && x < startx + width; x++, m ask >>= 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_t photometric, | |||
int startx, | int startx, | |||
int starty, | int starty, | |||
int width, | int width, | |||
int height, | int height, | |||
char has_alpha, | char has_alpha, | |||
int extra, | int extra, | |||
int align) | int align) | |||
{ | { | |||
int red, green, blue, alpha; | int red, green, blue, alpha; | |||
int x, y; | int x, y; | |||
skipping to change at line 635 | skipping to change at line 635 | |||
for (y = starty; y < height; y++) { | for (y = starty; y < height; y++) { | |||
for (x = 0; x < width; x++) { | for (x = 0; x < width; x++) { | |||
gdImageSetPixel(im, x, y, *src++); | gdImageSetPixel(im, x, y, *src++); | |||
} | } | |||
} | } | |||
} | } | |||
break; | break; | |||
} | } | |||
} | } | |||
static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16_t bps, uint16_t photometric, | |||
char has_alpha, char is_bw, int extra) | char has_alpha, char is_bw, int extra) | |||
{ | { | |||
uint16 planar; | uint16_t 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; | 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 || | |||
skipping to change at line 683 | skipping to change at line 683 | |||
} 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: | end: | |||
gdFree(buffer); | gdFree(buffer); | |||
return success; | return success; | |||
} | } | |||
static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot ometric, | static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16_t bps, uint16_t photometric, | |||
char has_alpha, char is_bw, int extra) | char has_alpha, char is_bw, int extra) | |||
{ | { | |||
uint16 planar; | uint16_t planar; | |||
uint32 im_height, im_width, y; | uint32_t im_height, im_width, y; | |||
unsigned char *buffer; | unsigned char *buffer; | |||
int success = GD_SUCCESS; | 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"); | |||
skipping to change at line 762 | skipping to change at line 762 | |||
} | } | |||
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_t *buffer; | |||
uint32 rgba; | uint32_t rgba; | |||
int success; | int success; | |||
buffer = (uint32 *) gdCalloc(sizeof(uint32), width * height); | buffer = (uint32_t *) gdCalloc(sizeof(uint32_t), width * height); | |||
if (!buffer) { | if (!buffer) { | |||
return GD_FAILURE; | 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); | |||
skipping to change at line 811 | skipping to change at line 811 | |||
/* | /* | |||
Function: gdImageCreateFromTiffCtx | Function: gdImageCreateFromTiffCtx | |||
Create a gdImage from a TIFF file input from an gdIOCtx. | Create a gdImage from a TIFF file input from an gdIOCtx. | |||
*/ | */ | |||
BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) | BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) | |||
{ | { | |||
TIFF *tif; | TIFF *tif; | |||
tiff_handle *th; | tiff_handle *th; | |||
uint16 bps, spp, photometric; | uint16_t bps, spp, photometric; | |||
uint16 orientation; | uint16_t orientation; | |||
int width, height; | int width, height; | |||
uint16 extra, *extra_types; | uint16_t extra, *extra_types; | |||
uint16 planar; | uint16_t planar; | |||
char has_alpha, is_bw, is_gray; | char has_alpha, is_bw, is_gray; | |||
char force_rgba = FALSE; | char force_rgba = FALSE; | |||
char save_transparent; | char save_transparent; | |||
int image_type; | int image_type; | |||
int ret; | int ret; | |||
float res_float; | float res_float; | |||
gdImagePtr im = NULL; | gdImagePtr im = NULL; | |||
th = new_tiff_handle(infile); | th = new_tiff_handle(infile); | |||
skipping to change at line 868 | skipping to change at line 868 | |||
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)) { | |||
uint16 compression; | uint16_t compression; | |||
if (TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression) && | if (TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression) && | |||
(compression == COMPRESSION_CCITTFAX3 || | (compression == COMPRESSION_CCITTFAX3 || | |||
compression == COMPRESSION_CCITTFAX4 || | compression == COMPRESSION_CCITTFAX4 || | |||
compression == COMPRESSION_CCITTRLE || | compression == COMPRESSION_CCITTRLE || | |||
compression == COMPRESSION_CCITTRLEW)) { | compression == COMPRESSION_CCITTRLEW)) { | |||
gd_error("Could not get photometric. " | gd_error("Could not get photometric. " | |||
"Image is CCITT compressed, assuming min-is-white "); | "Image is CCITT compressed, assuming min-is-white "); | |||
photometric = PHOTOMETRIC_MINISWHITE; | photometric = PHOTOMETRIC_MINISWHITE; | |||
} else { | } else { | |||
gd_error("Could not get photometric. " | gd_error("Could not get photometric. " | |||
skipping to change at line 1076 | skipping to change at line 1076 | |||
#else | #else | |||
static void _noTiffError(void) | static void _noTiffError(void) | |||
{ | { | |||
gd_error("TIFF image support has been disabled\n"); | gd_error("TIFF image support has been disabled\n"); | |||
} | } | |||
BGD_DECLARE(void) gdImageTiffCtx(gdImagePtr image, gdIOCtx *out) | BGD_DECLARE(void) gdImageTiffCtx(gdImagePtr image, gdIOCtx *out) | |||
{ | { | |||
ARG_NOT_USED(image); | ||||
ARG_NOT_USED(out); | ||||
_noTiffError(); | _noTiffError(); | |||
} | } | |||
BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) | BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) | |||
{ | { | |||
ARG_NOT_USED(infile); | ||||
_noTiffError(); | _noTiffError(); | |||
return NULL; | return NULL; | |||
} | } | |||
BGD_DECLARE(gdImagePtr) gdImageCreateFromTiff(FILE *inFile) | BGD_DECLARE(gdImagePtr) gdImageCreateFromTiff(FILE *inFile) | |||
{ | { | |||
ARG_NOT_USED(inFile); | ||||
_noTiffError(); | _noTiffError(); | |||
return NULL; | return NULL; | |||
} | } | |||
BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data) | BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data) | |||
{ | { | |||
ARG_NOT_USED(size); | ||||
ARG_NOT_USED(data); | ||||
_noTiffError(); | _noTiffError(); | |||
return NULL; | return NULL; | |||
} | } | |||
BGD_DECLARE(void) gdImageTiff(gdImagePtr im, FILE *outFile) | BGD_DECLARE(void) gdImageTiff(gdImagePtr im, FILE *outFile) | |||
{ | { | |||
ARG_NOT_USED(im); | ||||
ARG_NOT_USED(outFile); | ||||
_noTiffError(); | _noTiffError(); | |||
} | } | |||
BGD_DECLARE(void *) gdImageTiffPtr(gdImagePtr im, int *size) | BGD_DECLARE(void *) gdImageTiffPtr(gdImagePtr im, int *size) | |||
{ | { | |||
ARG_NOT_USED(im); | ||||
ARG_NOT_USED(size); | ||||
_noTiffError(); | _noTiffError(); | |||
return NULL; | return NULL; | |||
} | } | |||
#endif | #endif | |||
End of changes. 24 change blocks. | ||||
26 lines changed or deleted | 36 lines changed or added |