34 #ifndef AIMS_IO_QTFORMATSR_H
35 #define AIMS_IO_QTFORMATSR_H
44 #include <soma-io/datasource/filedatasource.h>
48 #include <QImageReader>
49 #include <QImageWriter>
66 const std::string & filename,
unsigned zfame,
71 static T convertColor(
const QRgb & );
76 inline QtFormatsReader<T> &
87 const carto::AllocatorContext & context,
95 catch( std::exception & e )
101 int frame = -1, border = 0;
102 options->getProperty(
"frame", frame );
103 options->getProperty(
"border", border );
107 unsigned tmin = 0, tmax = hdr->
dimT() - 1;
110 if( tmax < (
unsigned) frame )
113 throw std::domain_error(
"frame higher than file dimT" );
115 if( (
unsigned) frame < tmax )
116 files.erase( files.begin() + ( frame + 1 ) * hdr->
dimZ(),
119 files.erase( files.begin(), files.begin() + frame * hdr->
dimZ() );
124 carto::AllocatorContext al
125 ( context.accessMode(),
127 (
new carto::FileDataSource( *files.begin(), 0,
128 carto::DataSource::Read ) ),
129 false, context.useFactor() );
132 tmax - tmin + 1, border, al );
139 std::vector<int> dims(4);
140 dims[0] = hdr->
dimX();
141 dims[1] = hdr->
dimY();
142 dims[2] = hdr->
dimZ();
143 dims[3] = tmax - tmin + 1;
146 if( dims.size() < 1 )
147 dims.push_back( hdr->
dimX() );
148 if( dims.size() < 2 )
149 dims.push_back( hdr->
dimY() );
150 if( dims.size() < 3 )
151 dims.push_back( hdr->
dimZ() );
152 if( dims.size() < 4 )
153 dims.push_back( hdr->
dimT() );
162 unsigned i = 0, s, t, ns = (unsigned) data.
dimZ(),
nt = tmax - tmin + 1;
163 for( t=0; t<
nt; ++t )
164 for( s=0; s<ns; ++s, ++i )
165 readFrame( data, hdr, dir + files[i], s, t );
177 const std::string & name,
unsigned z,
181 const QImage *imp = 0;
186 imp = &hdr->qimage();
191 qio.setFileName( name.c_str() );
192 qio.setFormat( format.c_str() );
194 if( format ==
"JP2" )
207 const QImage & im = *imp;
208 int y, dx = data.
dimX(), dy = data.
dimY();
210 if( im.depth() ==
sizeof(T) && im.colorCount() == 0 )
211 for( y=0; y<dy; ++y )
212 memcpy( &data( 0, y, z, t ), im.scanLine( y ), dx *
sizeof( T ) );
214 for( y=0; y<dy; ++y )
215 for(
int x=0; x<dx; ++x )
216 data( x, y, z, t ) = convertColor( im.pixel( x, y ) );
220 template<
typename T>
inline
223 return (T) sqrt( ( ( (
double) qRed( x ) ) * (
double) qRed( x )
224 + qGreen( x ) * (
double) qGreen( x )
225 + qBlue( x ) * (
double) qBlue( x ) ) / 3 );
230 AimsRGB QtFormatsReader<AimsRGB>::convertColor(
const QRgb & x )
232 return AimsRGB( (
byte) qRed( x ), (
byte) qGreen( x ), (
byte) qBlue( x ) );
237 AimsRGBA QtFormatsReader<AimsRGBA>::convertColor(
const QRgb & x )
239 return AimsRGBA( (
byte) qRed( x ), (
byte) qGreen( x ), (
byte) qBlue( x ),
240 (
byte) qAlpha( x ) );
void setSizeY(float sizey)
void setSizeT(float sizet)
void setHeader(aims::Header *hdr)
void setSizeZ(float sizez)
void setSizeX(float sizex)
static std::string dirname(const std::string &)
virtual bool getProperty(const std::string &, Object &) const
virtual bool removeProperty(const std::string &)
virtual void setProperty(const std::string &, Object)
virtual bool hasProperty(const std::string &) const
GenesisReader< T > & operator>>(GenesisReader< T > &reader, AimsData< T > &thing)