+ int spp = image->GetOptionInt(wxIMAGE_OPTION_SAMPLESPERPIXEL);
+ if ( !spp )
+ spp = 3;
+
+ int bpp = image->GetOptionInt(wxIMAGE_OPTION_BITSPERSAMPLE);
+ if ( !bpp )
+ bpp=8;
+
+ int compression = image->GetOptionInt(wxIMAGE_OPTION_COMPRESSION);
+ if ( !compression )
+ {
+ // we can't use COMPRESSION_LZW because current version of libtiff
+ // doesn't implement it ("no longer implemented due to Unisys patent
+ // enforcement") and other compression methods are lossy so we
+ // shouldn't use them by default -- and the only remaining one is none
+ compression = COMPRESSION_NONE;
+ }
+
+ TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, spp);
+ TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bpp);
+ TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, spp*bpp == 1 ? PHOTOMETRIC_MINISBLACK
+ : PHOTOMETRIC_RGB);
+ TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);
+
+ // scanlinesize if determined by spp and bpp
+ tsize_t linebytes = (tsize_t)image->GetWidth() * spp * bpp / 8;
+
+ if ( (image->GetWidth() % 8 > 0) && (spp * bpp < 8) )
+ linebytes+=1;
+
+ unsigned char *buf;