Add compression modes for TIFF images
This patch aims at providing multiple compression modes for TIFF output, particularly uncompressed mode. At this moment have None, Deflate, LZW and Pack Bits modes been integrated, mimicking The GIMP export modes (except JPEG mode, which returned encoding errors). More modes could be added if needed. Default remains Deflate. Reviewers: campbellbarton, mont29, sergey Differential Revision: https://developer.blender.org/D1709
This commit is contained in:
parent
1f273cec00
commit
370a8ee741
|
@ -1623,6 +1623,14 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i
|
|||
im_format->imtype = R_IMF_IMTYPE_TIFF;
|
||||
if (custom_flags & TIF_16BIT)
|
||||
im_format->depth = R_IMF_CHAN_DEPTH_16;
|
||||
if (custom_flags & TIF_COMPRESS_NONE)
|
||||
im_format->tiff_codec = R_IMF_TIFF_CODEC_NONE;
|
||||
if (custom_flags & TIF_COMPRESS_DEFLATE)
|
||||
im_format->tiff_codec = R_IMF_TIFF_CODEC_DEFLATE;
|
||||
if (custom_flags & TIF_COMPRESS_LZW)
|
||||
im_format->tiff_codec = R_IMF_TIFF_CODEC_LZW;
|
||||
if (custom_flags & TIF_COMPRESS_PACKBITS)
|
||||
im_format->tiff_codec = R_IMF_TIFF_CODEC_PACKBITS;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2208,8 +2216,21 @@ void BKE_imbuf_write_prepare(ImBuf *ibuf, const ImageFormatData *imf)
|
|||
else if (imtype == R_IMF_IMTYPE_TIFF) {
|
||||
ibuf->ftype = IMB_FTYPE_TIF;
|
||||
|
||||
if (imf->depth == R_IMF_CHAN_DEPTH_16)
|
||||
if (imf->depth == R_IMF_CHAN_DEPTH_16) {
|
||||
ibuf->foptions.flag |= TIF_16BIT;
|
||||
}
|
||||
if (imf->tiff_codec == R_IMF_TIFF_CODEC_NONE) {
|
||||
ibuf->foptions.flag |= TIF_COMPRESS_NONE;
|
||||
}
|
||||
else if (imf->tiff_codec== R_IMF_TIFF_CODEC_DEFLATE) {
|
||||
ibuf->foptions.flag |= TIF_COMPRESS_DEFLATE;
|
||||
}
|
||||
else if (imf->tiff_codec == R_IMF_TIFF_CODEC_LZW) {
|
||||
ibuf->foptions.flag |= TIF_COMPRESS_LZW;
|
||||
}
|
||||
else if (imf->tiff_codec == R_IMF_TIFF_CODEC_PACKBITS) {
|
||||
ibuf->foptions.flag |= TIF_COMPRESS_PACKBITS;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_OPENEXR
|
||||
|
|
|
@ -1126,6 +1126,10 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, int color_man
|
|||
#endif
|
||||
}
|
||||
|
||||
if (imf->imtype == R_IMF_IMTYPE_TIFF) {
|
||||
uiItemR(col, imfptr, "tiff_codec", 0, NULL, ICON_NONE);
|
||||
}
|
||||
|
||||
/* color management */
|
||||
if (color_management &&
|
||||
(!BKE_imtype_requires_linear_float(imf->imtype) ||
|
||||
|
|
|
@ -127,7 +127,11 @@ enum eImbTypes {
|
|||
#define RAWTGA 1
|
||||
|
||||
#ifdef WITH_TIFF
|
||||
#define TIF_16BIT (1 << 8 )
|
||||
#define TIF_16BIT (1 << 8)
|
||||
#define TIF_COMPRESS_NONE (1 << 7)
|
||||
#define TIF_COMPRESS_DEFLATE (1 << 6)
|
||||
#define TIF_COMPRESS_LZW (1 << 5)
|
||||
#define TIF_COMPRESS_PACKBITS (1 << 4)
|
||||
#endif
|
||||
|
||||
typedef struct ImbFormatOptions {
|
||||
|
|
|
@ -708,6 +708,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
|
|||
float *fromf = NULL;
|
||||
float xres, yres;
|
||||
int x, y, from_i, to_i, i;
|
||||
int compress_mode = COMPRESSION_NONE;
|
||||
|
||||
/* check for a valid number of bytes per pixel. Like the PNG writer,
|
||||
* the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding
|
||||
|
@ -725,6 +726,13 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
|
|||
else
|
||||
bitspersample = 8;
|
||||
|
||||
if (ibuf->foptions.flag & TIF_COMPRESS_DEFLATE)
|
||||
compress_mode = COMPRESSION_DEFLATE;
|
||||
else if (ibuf->foptions.flag & TIF_COMPRESS_LZW)
|
||||
compress_mode = COMPRESSION_LZW;
|
||||
else if (ibuf->foptions.flag & TIF_COMPRESS_PACKBITS)
|
||||
compress_mode = COMPRESSION_PACKBITS;
|
||||
|
||||
/* open TIFF file for writing */
|
||||
if (flags & IB_mem) {
|
||||
/* bork at the creation of a TIFF in memory */
|
||||
|
@ -839,7 +847,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
|
|||
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, ibuf->x);
|
||||
TIFFSetField(image, TIFFTAG_IMAGELENGTH, ibuf->y);
|
||||
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, ibuf->y);
|
||||
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
|
||||
TIFFSetField(image, TIFFTAG_COMPRESSION, compress_mode);
|
||||
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
|
||||
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
|
||||
|
|
|
@ -355,7 +355,10 @@ typedef struct ImageFormatData {
|
|||
char jp2_flag;
|
||||
char jp2_codec;
|
||||
|
||||
char pad[5];
|
||||
/* TIFF */
|
||||
char tiff_codec;
|
||||
|
||||
char pad[4];
|
||||
|
||||
/* Multiview */
|
||||
char views_format;
|
||||
|
@ -442,6 +445,14 @@ typedef struct ImageFormatData {
|
|||
/* ImageFormatData.cineon_flag */
|
||||
#define R_IMF_CINEON_FLAG_LOG (1<<0) /* was R_CINEON_LOG */
|
||||
|
||||
/* ImageFormatData.tiff_codec */
|
||||
enum {
|
||||
R_IMF_TIFF_CODEC_DEFLATE = 0,
|
||||
R_IMF_TIFF_CODEC_LZW = 1,
|
||||
R_IMF_TIFF_CODEC_PACKBITS = 2,
|
||||
R_IMF_TIFF_CODEC_NONE = 3,
|
||||
};
|
||||
|
||||
typedef struct BakeData {
|
||||
struct ImageFormatData im_format;
|
||||
|
||||
|
|
|
@ -4580,6 +4580,16 @@ static void rna_def_scene_image_format_data(BlenderRNA *brna)
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef WITH_TIFF
|
||||
static EnumPropertyItem tiff_codec_items[] = {
|
||||
{R_IMF_TIFF_CODEC_NONE, "NONE", 0, "None", ""},
|
||||
{R_IMF_TIFF_CODEC_DEFLATE, "DEFLATE", 0, "Deflate", ""},
|
||||
{R_IMF_TIFF_CODEC_LZW, "LZW", 0, "LZW", ""},
|
||||
{R_IMF_TIFF_CODEC_PACKBITS, "PACKBITS", 0, "Pack Bits", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
|
@ -4679,6 +4689,15 @@ static void rna_def_scene_image_format_data(BlenderRNA *brna)
|
|||
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_TIFF
|
||||
/* TIFF */
|
||||
prop = RNA_def_property(srna, "tiff_codec", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "tiff_codec");
|
||||
RNA_def_property_enum_items(prop, tiff_codec_items);
|
||||
RNA_def_property_ui_text(prop, "Compression", "Compression mode for TIFF");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
|
||||
#endif
|
||||
|
||||
/* Cineon and DPX */
|
||||
|
||||
prop = RNA_def_property(srna, "use_cineon_log", PROP_BOOLEAN, PROP_NONE);
|
||||
|
|
Loading…
Reference in New Issue