EMAN2
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
EMAN::Gatan2IO Class Reference

Gatan2 Image file = header + data. More...

#include <gatan2io.h>

Inheritance diagram for EMAN::Gatan2IO:
Inheritance graph
[legend]
Collaboration diagram for EMAN::Gatan2IO:
Collaboration graph
[legend]

Classes

struct  Gatan2Header
 

Public Member Functions

 Gatan2IO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~Gatan2IO ()
 
- Public Member Functions inherited from EMAN::ImageIO
 ImageIO (const string &fname, IOMode rw)
 
virtual ~ImageIO ()
 
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. More...
 
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. More...
 
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. More...
 
virtual int read_data_8bit (unsigned char *data, int image_index=0, const Region *area=0, bool is_3d=false, float minval=0.0f, float maxval=0.0f)
 Read the data from an image as an 8 bit array, regardless of format. More...
 
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. More...
 
virtual int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
virtual void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual int get_nimg ()
 Return the number of images in this image file. More...
 
virtual bool is_complex_mode ()=0
 Is this an complex image or not. More...
 
virtual bool is_image_big_endian ()=0
 Is this image in big endian or not. More...
 
virtual bool is_single_image_format () const
 Is this image format only storing 1 image or not. More...
 
template<class T >
void become_host_endian (T *data, size_t n=1)
 Convert data of this image into host endian format. More...
 
string get_filename () const
 

Static Public Member Functions

static bool is_valid (const void *first_block)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 

Private Types

enum  DataType {
  GATAN2_SHORT = 1 , GATAN2_FLOAT = 2 , GATAN2_COMPLEX = 3 , GATAN2_PACKED_COMPLEX = 5 ,
  GATAN2_CHAR = 6 , GATAN2_INT = 7 , GATAN2_INVALID
}
 

Private Member Functions

int to_em_datatype (int gatan_type)
 

Private Attributes

Gatan2Header gatanh
 
bool is_big_endian
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- Protected Member Functions inherited from EMAN::ImageIO
virtual void init ()=0
 Do some initialization before doing the read/write. More...
 
void check_read_access (int image_index)
 Validate 'image_index' in file reading. More...
 
void check_read_access (int image_index, const float *data)
 Validate 'image_index' and 'data' in file reading. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg=0)
 Validate rw_mode and image_index in file writing. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg, const float *data)
 Validate rw_mode, image_index, and data pointer in file writing. More...
 
void check_region (const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
void check_region (const Region *area, const IntSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
FILE * sfopen (const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
 Run fopen safely. More...
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

Detailed Description

Gatan2 Image file = header + data.

header is defined in Gatan2Header. data is nx by ny. A Gatan2 file contains 1 2D image.

Definition at line 45 of file gatan2io.h.

Member Enumeration Documentation

◆ DataType

Enumerator
GATAN2_SHORT 
GATAN2_FLOAT 
GATAN2_COMPLEX 
GATAN2_PACKED_COMPLEX 
GATAN2_CHAR 
GATAN2_INT 
GATAN2_INVALID 

Definition at line 54 of file gatan2io.h.

55 {
56 GATAN2_SHORT = 1,
57 GATAN2_FLOAT = 2,
60 GATAN2_CHAR = 6,
61 GATAN2_INT = 7,
63 };
@ GATAN2_PACKED_COMPLEX
Definition: gatan2io.h:59

Constructor & Destructor Documentation

◆ Gatan2IO()

Gatan2IO::Gatan2IO ( const string &  fname,
IOMode  rw_mode = READ_ONLY 
)
explicit

Definition at line 39 of file gatan2io.cpp.

40: ImageIO(fname, rw)
41{
43 memset(&gatanh, 0, sizeof(Gatan2Header));
44}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
Gatan2Header gatanh
Definition: gatan2io.h:79
bool is_big_endian
Definition: gatan2io.h:81
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40

References gatanh, is_big_endian, and EMAN::ByteOrder::is_host_big_endian().

◆ ~Gatan2IO()

Gatan2IO::~Gatan2IO ( )

Definition at line 46 of file gatan2io.cpp.

47{
48 if (file) {
49 fclose(file);
50 file = 0;
51 }
52}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file.

Member Function Documentation

◆ is_valid()

bool Gatan2IO::is_valid ( const void *  first_block)
static

Definition at line 82 of file gatan2io.cpp.

83{
85 bool result = false;
86
87 if (!first_block) {
88 result = false;
89 }
90 else {
91 const short *data = static_cast < const short *>(first_block);
92 short len = data[5];
93 short type = data[6];
94
95 bool data_big_endian = ByteOrder::is_data_big_endian(&len);
96
97 if (data_big_endian != ByteOrder::is_host_big_endian()) {
100 }
101
102 int double_size = sizeof(double);
103 if (len > 0 && len <= double_size && type > 0 && type <= GATAN2_INVALID) {
104 result = true;
105 }
106 }
107 EXITFUNC;
108 return result;
109}
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Definition: byteorder.h:131
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.
Definition: byteorder.h:76
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References ENTERFUNC, EXITFUNC, GATAN2_INVALID, EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), and EMAN::ByteOrder::swap_bytes().

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

◆ to_em_datatype()

int Gatan2IO::to_em_datatype ( int  gatan_type)
private

Definition at line 239 of file gatan2io.cpp.

240{
241 switch (gatan_type) {
242 case GATAN2_SHORT:
243 return EMUtil::EM_SHORT;
244
245 case GATAN2_FLOAT:
246 return EMUtil::EM_FLOAT;
247
248 case GATAN2_CHAR:
249 return EMUtil::EM_CHAR;
250
251 case GATAN2_INT:
252 return EMUtil::EM_INT;
253 }
254
255 return EMUtil::EM_UNKNOWN;
256}
@ EM_UNKNOWN
Definition: emutil.h:93
@ EM_SHORT
Definition: emutil.h:96

References EMAN::EMUtil::EM_CHAR, EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_INT, EMAN::EMUtil::EM_SHORT, EMAN::EMUtil::EM_UNKNOWN, GATAN2_CHAR, GATAN2_FLOAT, GATAN2_INT, and GATAN2_SHORT.

Member Data Documentation

◆ DEFINE_IMAGEIO_FUNC

EMAN::Gatan2IO::DEFINE_IMAGEIO_FUNC

Definition at line 51 of file gatan2io.h.

◆ gatanh

Gatan2Header EMAN::Gatan2IO::gatanh
private

Definition at line 79 of file gatan2io.h.

Referenced by Gatan2IO().

◆ is_big_endian

bool EMAN::Gatan2IO::is_big_endian
private

Definition at line 81 of file gatan2io.h.

Referenced by Gatan2IO().


The documentation for this class was generated from the following files: