38#define M_PI 3.14159265358979323846f
39#define MAXPATHLEN (MAX_PATH*4)
50const char *LstIO::MAGIC =
"#LST";
52LstIO::LstIO(
const string & fname,
IOMode rw)
85 bool is_new_file =
false;
92 if (!fgets(buf, MAXPATHLEN,
file)) {
100 for (
nimg = 0; fgets(buf, MAXPATHLEN,
file) != 0;
nimg++) {
132 char buf[MAXPATHLEN];
137 step = image_index + 1;
140 for (
int i = 0; i < step; i++) {
141 if (!fgets(buf, MAXPATHLEN,
file)) {
142 LOGERR(
"reach EOF in file '%s' before reading %dth image",
150 int ref_image_index = 0;
151 char ref_image_path[MAXPATHLEN];
153 sscanf(buf,
" %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused);
155 char fullpath[MAXPATHLEN];
162 strcpy(fullpath, ref_image_path);
234 fprintf(
file,
"%s\n", (
char*)data);
static bool is_host_big_endian()
Dict is a dictionary to store <string, EMObject> pair.
EMDataType
Image pixel data type used in EMAN.
static ImageIO * get_imageio(const string &filename, int rw_mode, ImageType image_type=IMAGE_UNKNOWN)
Get an ImageIO object.
ImageIO classes are designed for reading/writing various electron micrography image formats,...
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.
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
static bool is_valid(const void *first_block)
int get_nimg()
Return the number of images in this image file.
static const char * MAGIC
int calc_ref_image_index(int image_index)
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
static bool check_file_by_magic(const void *first_block, const char *magic)
check whether a file starts with certain magic string.
#define ImageReadException(filename, desc)