34#ifndef AIMS_IO_QTFORMATSR_H
35#define AIMS_IO_QTFORMATSR_H
37#include <cartodata/volume/volume.h>
39#include <aims/io/datatypecode.h>
40#include <aims/rgb/rgb.h>
41#include <cartobase/stream/fileutil.h>
42#include <cartobase/exception/file.h>
43#include <cartobase/exception/format.h>
44#include <soma-io/datasource/filedatasource.h>
45#include <cartobase/thread/mutex.h>
48#include <QImageReader>
49#include <QImageWriter>
62 const carto::AllocatorContext & context,
67 const std::string & filename,
unsigned zfame,
72 static T convertColor(
const QRgb & );
77 inline QtFormatsReader<T> &
88 const carto::AllocatorContext & context,
96 catch( std::exception & e )
102 int frame = -1, border = 0;
103 options->getProperty(
"frame", frame );
104 options->getProperty(
"border", border );
108 unsigned tmin = 0, tmax = hdr->
dimT() - 1;
111 if( tmax < (
unsigned) frame )
114 throw std::domain_error(
"frame higher than file dimT" );
116 if( (
unsigned) frame < tmax )
117 files.erase( files.begin() + ( frame + 1 ) * hdr->
dimZ(),
120 files.erase( files.begin(), files.begin() + frame * hdr->
dimZ() );
125 carto::AllocatorContext al
126 ( context.accessMode(),
128 (
new carto::FileDataSource( *files.begin(), 0,
129 carto::DataSource::Read ) ),
130 false, context.useFactor() );
133 tmax - tmin + 1, border, al );
135 std::vector<float> vs( 4, 1. );
136 vs[0] = hdr->
sizeX();
137 vs[1] = hdr->
sizeY();
138 vs[2] = hdr->
sizeZ();
139 vs[3] = hdr->
sizeT();
142 std::vector<int> dims(4);
143 dims[0] = hdr->
dimX();
144 dims[1] = hdr->
dimY();
145 dims[2] = hdr->
dimZ();
146 dims[3] = tmax - tmin + 1;
156 unsigned i = 0, s, t, ns = (unsigned) data.
getSizeZ(),
157 nt = tmax - tmin + 1;
158 for( t=0; t<nt; ++t )
159 for( s=0; s<ns; ++s, ++i )
160 readFrame( *data, hdr, dir + files[i], s, t );
172 const std::string & name,
unsigned z,
176 const QImage *imp = 0;
181 imp = &hdr->qimage();
186 qio.setFileName( name.c_str() );
187 qio.setFormat( format.c_str() );
189 if( format ==
"JP2" )
202 const QImage & im = *imp;
214 for( y=0; y<dy; ++y )
215 for(
int x=0; x<dx; ++x )
216 data.
at( x, y, z, t ) = convertColor( im.pixel( x, y ) );
220 template<
typename T>
inline
221 T QtFormatsReader<T>::convertColor(
const QRgb & x )
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 ) );
virtual void copyProperties(Object source)
static std::string dirname(const std::string &)
void setProperty(const std::string &, const T &)
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
const PropertySet & header() const
const T & at(long x, long y=0, long z=0, long t=0) const
GenesisReader< T > & operator>>(GenesisReader< T > &reader, AimsData< T > &thing)
carto::VoxelRGBA AimsRGBA