00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__imageio_h__
00037 #define eman__imageio_h__ 1
00038
00039 #include "byteorder.h"
00040 #include "emutil.h"
00041
00042 using std::vector;
00043 using std::string;
00044
00045 namespace EMAN
00046 {
00047 class Region;
00048 class FloatSize;
00049 class IntSize;
00050 class Ctf;
00051
00130 class ImageIO
00131 {
00132 public:
00133 enum IOMode
00134 { READ_ONLY = 1, READ_WRITE = 2, WRITE_ONLY = 3 };
00135 public:
00136 virtual ~ ImageIO();
00137
00148 virtual int read_header(Dict & dict, int image_index = 0,
00149 const Region * area = 0, bool is_3d = false) = 0;
00150
00162 virtual int write_header(const Dict & dict,
00163 int image_index = 0,
00164 const Region * area = 0,
00165 EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT,
00166 bool use_host_endian = true) = 0;
00167
00179 virtual int read_data(float *data, int image_index = 0,
00180 const Region * area = 0, bool is_3d = false) = 0;
00181
00193 virtual int write_data(float *data,
00194 int image_index = 0,
00195 const Region * area = 0,
00196 EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT,
00197 bool use_host_endian = true) = 0;
00198
00205 virtual int read_ctf(Ctf & ctf, int image_index = 0);
00206
00213 virtual void write_ctf(const Ctf & ctf, int image_index = 0);
00214
00217 virtual void flush() = 0;
00218
00220 virtual int get_nimg();
00221
00223 virtual bool is_complex_mode() = 0;
00224
00226 virtual bool is_image_big_endian() = 0;
00227
00234 virtual bool is_single_image_format() const
00235 {
00236 return true;
00237 }
00238
00245 template < class T > void become_host_endian(T * data, size_t n = 1)
00246 {
00247 if (is_image_big_endian() != ByteOrder::is_host_big_endian()) {
00248 ByteOrder::swap_bytes(data, n);
00249 }
00250 }
00251
00252 protected:
00255 virtual void init() = 0;
00256
00262 void check_read_access(int image_index);
00263
00271 void check_read_access(int image_index, const float *data);
00272
00282 void check_write_access(IOMode rw_mode, int image_index, int max_nimg = 0);
00283
00294 void check_write_access(IOMode rw_mode, int image_index, int max_nimg,
00295 const float *data);
00296
00306 void check_region(const Region * area, const FloatSize & max_size,
00307 bool is_new_file = false, bool inbounds_only=true);
00308
00318 void check_region(const Region * area, const IntSize & max_size,
00319 bool is_new_file = false, bool inbounds_only=true);
00320
00330 FILE *sfopen(const string & filename, IOMode mode,
00331 bool * is_new = 0, bool overwrite = false);
00332
00346 void getRenderMinMax(float * data, const int nx, const int ny, float& rendermin, float& rendermax, const int nz = 1);
00347 };
00348
00352 #define DEFINE_IMAGEIO_FUNC \
00353 int read_header(Dict & dict, int image_index = 0, const Region* area = 0, bool is_3d = false); \
00354 int write_header(const Dict & dict, int image_index = 0, const Region * area = 0, EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT, bool use_host_endian = true); \
00355 int read_data(float* data, int image_index = 0, const Region* area = 0, bool is_3d = false); \
00356 int write_data(float* data, int image_index = 0, const Region * area = 0, EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT, bool use_host_endian = true); \
00357 void flush(); \
00358 bool is_complex_mode(); \
00359 bool is_image_big_endian(); \
00360 void init()
00361
00362 }
00363
00364
00365 #endif //eman__imageio_h__