+ if ( image->HasOption(wxIMAGE_OPTION_RESOLUTIONX) &&
+ image->HasOption(wxIMAGE_OPTION_RESOLUTIONY) )
+ {
+ TIFFSetField(tif, TIFFTAG_XRESOLUTION,
+ image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX));
+ TIFFSetField(tif, TIFFTAG_YRESOLUTION,
+ image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY));
+ }
+
+ 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 )
+ compression=COMPRESSION_LZW;
+
+ 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;
+
+ if (TIFFScanlineSize(tif) > linebytes || (spp * bpp < 24))
+ {
+ buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif));
+ if (!buf)
+ {
+ if (verbose)
+ wxLogError( _("TIFF: Couldn't allocate memory.") );
+
+ TIFFClose( tif );
+
+ return false;
+ }
+ }
+ else
+ {
+ buf = NULL;
+ }