86 const carto::AllocatorContext & context,
94 catch( std::exception & e )
100 int frame = -1, border = 0;
101 options->getProperty(
"frame", frame );
102 options->getProperty(
"border", border );
105 std::vector<int> dims;
108 if( dims.size() < 1 )
109 dims.push_back( hdr->
dimX() );
110 if( dims.size() < 2 )
111 dims.push_back( hdr->
dimY() );
112 if( dims.size() < 3 )
113 dims.push_back( hdr->
dimZ() );
114 if( dims.size() < 4 )
115 dims.push_back( hdr->
dimT() );
117 unsigned tmin = 0, tmax = dims[3] - 1;
120 if( tmax < (
unsigned) frame )
123 throw std::domain_error(
"frame higher than file dimT" );
125 if( (
unsigned) frame < tmax )
126 files.erase( files.begin() + ( frame + 1 ) * hdr->
dimZ(),
129 files.erase( files.begin(), files.begin() + frame * hdr->
dimZ() );
134 carto::AllocatorContext al
135 ( context.accessMode(),
137 (
new carto::FileDataSource( *files.begin(), 0,
138 carto::DataSource::Read ) ),
139 false, context.useFactor() );
159 dims[3] = tmax - tmin + 1;
169 unsigned i = 0, s, t, ns = (unsigned) data.
dimZ(), nt = tmax - tmin + 1;
171 if ( files.size() == ns * nt )
174 for( t=0; t<nt; ++t ) {
175 for( s=0; s<ns; ++s, ++i ) {
181 }
else if ( files.size() == nt )
184 for( t=0; t<nt; ++t ) {
186 readFrame( data, dir + files[t], -1, t );
271 const std::string & name,
int zframe,
274 int tiled, stripSize, rowsPerStrip;
275 uint i, s, zmin, zmax, dx = data.
dimX(), dy = data.
dimY();
278 TIFFSetWarningHandler( 0 );
279 TIFF* tif = TIFFOpen(name.c_str(),
"r");
286 tiled = TIFFIsTiled(tif);
290 "Not a tiled TIFF image : can't read" );
304 zmax = (
uint)zframe + 1;
307 for (
uint z = zmin; z < zmax; z++ )
309 TIFFSetDirectory(tif, z );
310 stripSize = TIFFStripSize(tif);
311 uint16_t bits, samplesize;
314 TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP, &rowsPerStrip);
315 TIFFGetFieldDefaulted(tif, TIFFTAG_PHOTOMETRIC, &photometric);
316 TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bits);
317 samplesize = stripSize / dx / rowsPerStrip;
320 if( photometric != PHOTOMETRIC_PALETTE )
322 std::vector<char> buffer( stripSize, 0 );
323 for(s=0, i=0; s < dy; s += rowsPerStrip, ++i)
325 TIFFReadEncodedStrip(tif, i, &buffer[0], stripSize);
326 if( samplesize ==
sizeof(T) )
327 for(
uint y=s; y<std::min(s+rowsPerStrip, dy); ++y )
328 memcpy( &data(0, y, z, tframe),
329 &buffer[(y-s) * dx * samplesize],
332 for(
uint y=s; y<std::min(s+rowsPerStrip, dy); ++y )
334 T* ibuf = &data( 0, y, z, tframe );
335 for(
uint x=0; x<dx; ++x, ++ibuf )
336 *ibuf = tiff_scaled_value<T>(
337 &buffer[((y-s) * dx + x) * samplesize], bits );
341 if(photometric == PHOTOMETRIC_MINISWHITE)
346 for(
int y = 0; y < data.
dimY(); ++y) {
347 buffer = (
byte*)&data(0, y, z, tframe);
348 for(
unsigned index=0; index<(dx *
sizeof(T)); index++ )
350 buffer[index] =~ buffer[index];
359 uint32_t * rgba_data = (uint32_t *)&data(0, 0, z, tframe);
360 TIFFReadRGBAImageOriented(tif, dx, data.
dimY(),
361 rgba_data, ORIENTATION_TOPLEFT);
void readFrame(AimsData< T > &thing, const std::string &filename, int zframe, unsigned tframe)
called by read(), but you can call it for single frame reading (axial slice)