113 const std::string & filename,
117 int bps, spp, photometric;
119 uint16_t sampleformat = SAMPLEFORMAT_UINT;
120 uint16_t extrasampletype = EXTRASAMPLE_UNASSALPHA;
121 uint16_t extrasamplescount = 0;
127 photometric = PHOTOMETRIC_MINISBLACK;
129 else if ( name ==
"S8" )
133 photometric = PHOTOMETRIC_MINISBLACK;
134 sampleformat = SAMPLEFORMAT_INT;
136 else if ( name ==
"U16" )
140 photometric = PHOTOMETRIC_MINISBLACK;
142 else if ( name ==
"S16" )
146 photometric = PHOTOMETRIC_MINISBLACK;
147 sampleformat = SAMPLEFORMAT_INT;
149 else if ( name ==
"U32" )
153 photometric = PHOTOMETRIC_MINISBLACK;
155 else if ( name ==
"S32" )
159 photometric = PHOTOMETRIC_MINISBLACK;
160 sampleformat = SAMPLEFORMAT_INT;
162 else if ( name ==
"FLOAT" )
166 photometric = PHOTOMETRIC_MINISBLACK;
167 sampleformat = SAMPLEFORMAT_IEEEFP;
169 else if ( name ==
"DOUBLE" )
173 photometric = PHOTOMETRIC_MINISBLACK;
174 sampleformat = SAMPLEFORMAT_IEEEFP;
176 else if ( name ==
"CFLOAT" )
180 photometric = PHOTOMETRIC_MINISBLACK;
181 sampleformat = SAMPLEFORMAT_COMPLEXIEEEFP;
183 else if ( name ==
"CDOUBLE" )
187 photometric = PHOTOMETRIC_MINISBLACK;
188 sampleformat = SAMPLEFORMAT_COMPLEXIEEEFP;
190 else if ( name ==
"RGBA" )
194 photometric = PHOTOMETRIC_RGB;
195 extrasamplescount = 1;
201 photometric = PHOTOMETRIC_RGB;
218 tif = TIFFOpen(filename.c_str(),
"w");
223 tif = TIFFOpen(filename.c_str(),
"w8");
228 std::cout <<
"Could not open '" << filename <<
"' for writing." << std::endl;
233 TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, data.
dimX() );
234 TIFFSetField(tif, TIFFTAG_IMAGELENGTH, data.
dimY());
235 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
236 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, spp );
237 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1 );
239 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric);
240 TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
242 TIFFSetField(tif, TIFFTAG_XRESOLUTION, 10. / data.
sizeX());
243 TIFFSetField(tif, TIFFTAG_YRESOLUTION, 10. / data.
sizeY());
244 TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_CENTIMETER);
245 TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, sampleformat);
247 if (extrasamplescount > 0) {
248 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, extrasamplescount, &extrasampletype);
252 int y, ny = data.
dimY(), nx = data.
dimX();
254 long stride = &data( 1 ) - &data( 0 );
255 std::vector<T> buffer;
262 for( y=0; y<ny; ++y )
265 ptr = (
void *) &data(0, y, z, t);
269 const T* p = &data( 0, y, z, t );
270 for(
long x=0; x<nx; ++x, p+=stride )
272 ptr = (
void *) &buffer[0];
278 res = TIFFWriteEncodedStrip(tif, y, ptr, (bps / 8) * spp * data.
dimX() );