mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Merge "cwebp: add basic TIFF support"
This commit is contained in:
commit
27caa5aa34
@ -27,6 +27,10 @@
|
|||||||
#include <jpeglib.h>
|
#include <jpeglib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WEBP_HAVE_TIFF
|
||||||
|
#include <tiffio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_WINCODEC_H
|
#ifdef HAVE_WINCODEC_H
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#define INITGUID // Without this GUIDs are declared extern and fail to link
|
#define INITGUID // Without this GUIDs are declared extern and fail to link
|
||||||
@ -449,9 +453,73 @@ static int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WEBP_HAVE_TIFF
|
||||||
|
static 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;
|
||||||
|
int dircount = 1;
|
||||||
|
|
||||||
|
if (tif == NULL) {
|
||||||
|
fprintf(stderr, "Error! Cannot open TIFF file '%s'\n", filename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (TIFFReadDirectory(tif)) ++dircount;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
|
||||||
|
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
|
||||||
|
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
|
||||||
|
static int ReadTIFF(const char* const filename,
|
||||||
|
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
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PNG = 0,
|
PNG = 0,
|
||||||
JPEG,
|
JPEG,
|
||||||
|
TIFF_, // 'TIFF' clashes with libtiff
|
||||||
UNSUPPORTED
|
UNSUPPORTED
|
||||||
} InputFileFormat;
|
} InputFileFormat;
|
||||||
|
|
||||||
@ -470,6 +538,8 @@ static InputFileFormat GetImageType(FILE* in_file) {
|
|||||||
format = PNG;
|
format = PNG;
|
||||||
} else if (magic >= 0xFFD8FF00U && magic <= 0xFFD8FFFFU) {
|
} else if (magic >= 0xFFD8FF00U && magic <= 0xFFD8FFFFU) {
|
||||||
format = JPEG;
|
format = JPEG;
|
||||||
|
} else if (magic == 0x49492A00 || magic == 0x4D4D002A) {
|
||||||
|
format = TIFF_;
|
||||||
}
|
}
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
@ -490,6 +560,8 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
|||||||
ok = ReadPNG(in_file, pic, keep_alpha);
|
ok = ReadPNG(in_file, pic, keep_alpha);
|
||||||
} else if (format == JPEG) {
|
} else if (format == JPEG) {
|
||||||
ok = ReadJPEG(in_file, pic);
|
ok = ReadJPEG(in_file, pic);
|
||||||
|
} else if (format == TIFF_) {
|
||||||
|
ok = ReadTIFF(filename, pic, keep_alpha);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If image size is specified, infer it as YUV format.
|
// If image size is specified, infer it as YUV format.
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
# These flag assume you have libpng and libjpeg installed. If not, either
|
# These flag assume you have libpng and libjpeg installed. If not, either
|
||||||
# follow below install instructions or just comment out the next lines.
|
# follow below install instructions or just comment out the next lines.
|
||||||
EXTRA_FLAGS= -DWEBP_HAVE_PNG -DWEBP_HAVE_JPEG
|
EXTRA_FLAGS= -DWEBP_HAVE_PNG -DWEBP_HAVE_JPEG -DWEBP_HAVE_TIFF
|
||||||
EXTRA_LIBS= -lpng -ljpeg -lz
|
EXTRA_LIBS= -lpng -ltiff -ljpeg -lz
|
||||||
ifeq ($(strip $(shell uname)), Darwin)
|
ifeq ($(strip $(shell uname)), Darwin)
|
||||||
# Work around a problem linking tables marked as common symbols,
|
# Work around a problem linking tables marked as common symbols,
|
||||||
# cf., src/enc/yuv.[hc]
|
# cf., src/enc/yuv.[hc]
|
||||||
@ -30,10 +30,12 @@ endif
|
|||||||
# 1. Install MacPorts (http://www.macports.org/install.php)
|
# 1. Install MacPorts (http://www.macports.org/install.php)
|
||||||
# 2. Run "sudo port install jpeg"
|
# 2. Run "sudo port install jpeg"
|
||||||
# 3. Run "sudo port install libpng"
|
# 3. Run "sudo port install libpng"
|
||||||
|
# 4. Run "sudo port install tiff"
|
||||||
|
|
||||||
# To install libraries on Linux:
|
# To install libraries on Linux:
|
||||||
# 1. Run "sudo apt-get install libjpeg62-dev"
|
# 1. Run "sudo apt-get install libjpeg62-dev"
|
||||||
# 2. Run "sudo apt-get install libpng12-dev"
|
# 2. Run "sudo apt-get install libpng12-dev"
|
||||||
|
# 3. Run "sudo apt-get install libtiff4-dev"
|
||||||
|
|
||||||
# Uncomment for build for 32bit platform
|
# Uncomment for build for 32bit platform
|
||||||
# Alternatively, you can just use the command
|
# Alternatively, you can just use the command
|
||||||
|
Loading…
Reference in New Issue
Block a user