Skip to content

Commit e234a28

Browse files
committed
Make all possible compression types supported by libtfiff available, when saving a .tiff file.
1 parent 0626260 commit e234a28

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

CImg.h

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62281,7 +62281,12 @@ namespace cimg_library {
6228162281
//! Save image as a TIFF file.
6228262282
/**
6228362283
\param filename Filename, as a C-string.
62284-
\param compression_type Type of data compression. Can be <tt>{ 0=None | 1=LZW | 2=JPEG }</tt>.
62284+
\param compression_type Type of data compression. Can be
62285+
<tt>{ 0=None | 1=ADOBE_DEFLATE | 2=CCITT_T4 | 3=CCITT_T6 | 4=CCITTFAX3 | 5=CCITTFAX4 | 6=CCITTRLE |
62286+
7=CCITTRLEW | 8=DCS | 9=DEFLATE | 10=IT8BL | 11=IT8CTPAD | 12=IT8LW | 13=IT8MP | 14=JBIG |
62287+
15=JP2000 | 16=JPEG | 17=JXL | 18=LERC | 19=LZMA | 20=LZW | 21=NEXT | 22=OJPEG | 23=PACKBITS |
62288+
24=PIXARFILM | 25=PIXARLOG | 26=SGILOG | 27=SGILOG24 | 28=T43 | 29=T85 | 30=THUNDERSCAN |
62289+
31=WEBP | 32=ZSTD }</tt>
6228562290
\param[out] voxel_size Voxel size, to be stored in the filename.
6228662291
\param[out] description Description, to be stored in the filename.
6228762292
\param use_bigtiff Allow to save big tiff files (>4Gb).
@@ -62295,7 +62300,6 @@ namespace cimg_library {
6229562300
function uses CImg<T>&save_other(const char*).
6229662301
**/
6229762302
const CImg<T>& save_tiff(const char *const filename, const unsigned int compression_type=0,
62298-
6229962303
const float *const voxel_size=0, const char *const description=0,
6230062304
const bool use_bigtiff=true) const {
6230162305
if (!filename)
@@ -62335,6 +62339,22 @@ namespace cimg_library {
6233562339
const unsigned int compression_type, const float *const voxel_size,
6233662340
const char *const description, double val_min, double val_max) const {
6233762341
if (is_empty() || !tif || pixel_t) return *this;
62342+
const unsigned int compression_codes[] = {
62343+
COMPRESSION_NONE, COMPRESSION_ADOBE_DEFLATE, COMPRESSION_CCITT_T4, COMPRESSION_CCITT_T6,
62344+
COMPRESSION_CCITTFAX3, COMPRESSION_CCITTFAX4, COMPRESSION_CCITTRLE, COMPRESSION_CCITTRLEW,
62345+
COMPRESSION_DCS, COMPRESSION_DEFLATE, COMPRESSION_IT8BL, COMPRESSION_IT8CTPAD, COMPRESSION_IT8LW,
62346+
COMPRESSION_IT8MP, COMPRESSION_JBIG, COMPRESSION_JP2000, COMPRESSION_JPEG, COMPRESSION_JXL,
62347+
COMPRESSION_LERC, COMPRESSION_LZMA, COMPRESSION_LZW, COMPRESSION_NEXT, COMPRESSION_OJPEG,
62348+
COMPRESSION_PACKBITS, COMPRESSION_PIXARFILM, COMPRESSION_PIXARLOG, COMPRESSION_SGILOG,
62349+
COMPRESSION_SGILOG24, COMPRESSION_T43, COMPRESSION_T85, COMPRESSION_THUNDERSCAN, COMPRESSION_WEBP,
62350+
COMPRESSION_ZSTD },
62351+
nb_compression_codes = sizeof(compression_codes)/sizeof(unsigned int);
62352+
if (compression_type>=nb_compression_codes)
62353+
throw CImgArgumentException(_cimg_instance
62354+
"save_tiff(): Specified compression type (%u) is invalid "
62355+
"(should be in range [0,%u]).",
62356+
cimg_instance,nb_compression_codes - 1);
62357+
const unsigned int compression_code = compression_codes[compression_type];
6233862358
const char *const filename = TIFFFileName(tif);
6233962359
cimg_uint32 rowsperstrip = (cimg_uint32)-1;
6234062360
cimg_uint16 spp = _spectrum, bpp = sizeof(t)*8, photometric;
@@ -62363,14 +62383,7 @@ namespace cimg_library {
6236362383
TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,bpp);
6236462384
TIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
6236562385
TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,photometric);
62366-
TIFFSetField(tif,TIFFTAG_COMPRESSION,
62367-
compression_type==6?COMPRESSION_ZSTD:
62368-
compression_type==5?COMPRESSION_WEBP:
62369-
compression_type==4?COMPRESSION_LZW:
62370-
compression_type==3?COMPRESSION_LZMA:
62371-
compression_type==2?COMPRESSION_JPEG:
62372-
compression_type==1?COMPRESSION_JBIG:
62373-
COMPRESSION_NONE);
62386+
TIFFSetField(tif,TIFFTAG_COMPRESSION,compression_code);
6237462387
rowsperstrip = TIFFDefaultStripSize(tif,rowsperstrip);
6237562388
TIFFSetField(tif,TIFFTAG_ROWSPERSTRIP,rowsperstrip);
6237662389
TIFFSetField(tif,TIFFTAG_FILLORDER,FILLORDER_MSB2LSB);

0 commit comments

Comments
 (0)