39Gatan2IO::Gatan2IO(
const string & fname,
IOMode rw)
64 bool is_new_file =
false;
68 if (fread(&
gatanh,
sizeof(Gatan2Header), 1,
file) != 1) {
91 const short *data =
static_cast < const short *
>(first_block);
102 int double_size =
sizeof(double);
103 if (len > 0 && len <= double_size && type > 0 && type <=
GATAN2_INVALID) {
115 if(image_index == -1) {
119 if(image_index != 0) {
120 throw ImageReadException(
filename,
"no stack allowed for MRC image. For take 2D slice out of 3D image, read the 3D image first, then use get_clip().");
131 int xlen = 0, ylen = 0;
147 LOGWARN(
"Gatan2 write is not supported.");
175 short *sdata = (
short *) data;
176 unsigned char *cdata = (
unsigned char *) data;
177 int *ldata = (
int *) data;
185 for (
int i = size - 1; i >= 0; i--) {
186 data[i] =
static_cast < float >(sdata[i]);
193 for (
int i = size - 1; i >= 0; i--) {
194 data[i] =
static_cast < float >(cdata[i]);
199 for (
int i = size - 1; i >= 0; i--) {
200 data[i] =
static_cast < float >(ldata[i]);
213 LOGWARN(
"Gatan2 write is not supported.");
241 switch (gatan_type) {
static bool is_host_big_endian()
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
static bool is_data_big_endian(const T *small_num_addr)
given a pointer to a reasonable small integer number, return whether the number is big endian or not.
Dict is a dictionary to store <string, EMObject> pair.
static void process_region_io(void *cdata, FILE *file, int rw_mode, int image_index, size_t mode_size, int nx, int ny, int nz=1, const Region *area=0, bool need_flip=false, ImageType imgtype=IMAGE_UNKNOWN, int pre_row=0, int post_row=0)
Process image region IO.
EMDataType
Image pixel data type used in EMAN.
static void get_region_dims(const Region *area, int nx, int *area_x, int ny, int *area_y, int nz=1, int *area_z=0)
Get a region's dimensions.
static bool is_valid(const void *first_block)
int to_em_datatype(int gatan_type)
ImageIO classes are designed for reading/writing various electron micrography image formats,...
void check_region(const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
Validate image I/O region.
virtual void flush()=0
Flush the IO buffer.
virtual 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)=0
Write a header to an image.
virtual int write_data(float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
Write data to an image.
virtual bool is_complex_mode()=0
Is this an complex image or not.
virtual int read_header(Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the header from an image.
FILE * sfopen(const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
Run fopen safely.
void check_read_access(int image_index)
Validate 'image_index' in file reading.
virtual int read_data(float *data, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the data from an image.
virtual void init()=0
Do some initialization before doing the read/write.
void become_host_endian(T *data, size_t n=1)
Convert data of this image into host endian format.
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
IntSize is used to describe a 1D, 2D or 3D rectangular size in integers.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
#define ImageReadException(filename, desc)
int portable_fseek(FILE *fp, off_t offset, int whence)