40IcosIO::IcosIO(
const string & fname,
IOMode rw)
67 if (fread(&
icosh,
sizeof(IcosHeader), 1,
file) != 1) {
88 const int *data =
static_cast < const int *
>(first_block);
90 int stamp1 = data[19];
91 int stamp2 = data[20];
92 int stamp3 = data[26];
116 if(image_index == -1) {
120 if(image_index != 0) {
121 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().");
128 int xlen = 0, ylen = 0, zlen = 0;
148 if(image_index == -1) {
151 if(image_index != 0) {
170 if (fwrite(&
icosh,
sizeof(IcosHeader), 1,
file) != 1) {
194 int xlen = 0, ylen = 0, zlen = 0;
217 size_t float_size =
sizeof(float);
219 float *buf =
new float[nx + 2];
220 buf[0] = (float)float_size * nx;
221 buf[nx + 1] = buf[0];
224 int row_size = (nx + 2) * float_size;
227 for (
int j = 0; j < nrows; j++) {
228 memcpy(&buf[1], &data[nx * j], nx * float_size);
229 if (fwrite(buf, row_size, 1,
file) != 1) {
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)
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 check_write_access(IOMode rw_mode, int image_index, int max_nimg=0)
Validate rw_mode and image_index in file writing.
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)
#define ImageWriteException(imagename, desc)
int portable_fseek(FILE *fp, off_t offset, int whence)