b50f277bc7
the expression using dircount will be promoted to int when tdir_t is an unsigned short. quiets: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] Change-Id: If2e8c27454826556178b0a972aaed272d5fbfa07
88 lines
2.5 KiB
C
88 lines
2.5 KiB
C
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
//
|
|
// This code is licensed under the same terms as WebM:
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// TIFF decode.
|
|
|
|
#include "./tiffdec.h"
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef WEBP_HAVE_TIFF
|
|
#include <tiffio.h>
|
|
|
|
#include "webp/encode.h"
|
|
|
|
int ReadTIFF(const char* const filename,
|
|
WebPPicture* const pic, int keep_alpha) {
|
|
TIFF* const tif = TIFFOpen(filename, "r");
|
|
uint32 width, height;
|
|
uint32* raster;
|
|
int ok = 0;
|
|
tdir_t dircount;
|
|
|
|
if (tif == NULL) {
|
|
fprintf(stderr, "Error! Cannot open TIFF file '%s'\n", filename);
|
|
return 0;
|
|
}
|
|
|
|
dircount = TIFFNumberOfDirectories(tif);
|
|
if (dircount > 1) {
|
|
fprintf(stderr, "Warning: multi-directory TIFF files are not supported.\n"
|
|
"Only the first will be used, %d will be ignored.\n",
|
|
dircount - 1);
|
|
}
|
|
|
|
if (!(TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) &&
|
|
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height))) {
|
|
fprintf(stderr, "Error! Cannot retrieve TIFF image dimensions.\n");
|
|
return 0;
|
|
}
|
|
raster = (uint32*)_TIFFmalloc(width * height * sizeof(*raster));
|
|
if (raster != NULL) {
|
|
if (TIFFReadRGBAImageOriented(tif, width, height, raster,
|
|
ORIENTATION_TOPLEFT, 1)) {
|
|
const int stride = width * sizeof(*raster);
|
|
pic->width = width;
|
|
pic->height = height;
|
|
// TIFF data is ABGR
|
|
#ifdef __BIG_ENDIAN__
|
|
TIFFSwabArrayOfLong(raster, width * height);
|
|
#endif
|
|
ok = keep_alpha
|
|
? WebPPictureImportRGBA(pic, (const uint8_t*)raster, stride)
|
|
: WebPPictureImportRGBX(pic, (const uint8_t*)raster, stride);
|
|
}
|
|
_TIFFfree(raster);
|
|
} else {
|
|
fprintf(stderr, "Error allocating TIFF RGBA memory!\n");
|
|
}
|
|
|
|
if (ok && keep_alpha == 2) {
|
|
WebPCleanupTransparentArea(pic);
|
|
}
|
|
|
|
TIFFClose(tif);
|
|
return ok;
|
|
}
|
|
#else // !WEBP_HAVE_TIFF
|
|
int ReadTIFF(const char* const filename,
|
|
struct WebPPicture* const pic, int keep_alpha) {
|
|
(void)filename;
|
|
(void)pic;
|
|
(void)keep_alpha;
|
|
fprintf(stderr, "TIFF support not compiled. Please install the libtiff "
|
|
"development package before building.\n");
|
|
return 0;
|
|
}
|
|
#endif // WEBP_HAVE_TIFF
|
|
|
|
// -----------------------------------------------------------------------------
|