#include <imagicio.h>
Inheritance diagram for EMAN::ImagicIO:
Public Member Functions | |
ImagicIO (string filename, IOMode rw_mode=READ_ONLY) | |
~ImagicIO () | |
bool | is_single_image_format () const |
Is this image format only storing 1 image or not. | |
int | get_nimg () |
Return the number of images in this image file. | |
Static Public Member Functions | |
static bool | is_valid (const void *first_block) |
Public Attributes | |
DEFINE_IMAGEIO_FUNC | |
Static Public Attributes | |
static const char * | HED_EXT = "hed" |
static const char * | IMG_EXT = "img" |
Private Types | |
IMAGIC_UCHAR | |
IMAGIC_USHORT | |
IMAGIC_FLOAT | |
IMAGIC_FLOAT_COMPLEX | |
IMAGIC_FFT_FLOAT_COMPLEX | |
IMAGIC_UNKNOWN_TYPE | |
NUM_4BYTES_PRE_IXOLD = 14 | |
NUM_4BYTES_AFTER_IXOLD = 14 | |
NUM_4BYTES_AFTER_SPACE = 207 | |
enum | DataType { IMAGIC_UCHAR, IMAGIC_USHORT, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_FFT_FLOAT_COMPLEX, IMAGIC_UNKNOWN_TYPE } |
enum | { NUM_4BYTES_PRE_IXOLD = 14, NUM_4BYTES_AFTER_IXOLD = 14, NUM_4BYTES_AFTER_SPACE = 207 } |
Private Member Functions | |
size_t | get_datatype_size (DataType t) |
int | to_em_datatype (DataType t) |
void | make_header_host_endian (ImagicHeader &hed) |
void | swap_header (ImagicHeader &hed) |
DataType | get_datatype_from_name (const char *name) |
Ctf * | read_ctf (const ImagicHeader &hed) const |
the Ctf object is a EMAN1Ctf object. | |
void | write_ctf (const Ctf *const ctf, int image_index=0) |
Private Attributes | |
string | filename |
string | hed_filename |
string | img_filename |
IOMode | rw_mode |
FILE * | hed_file |
FILE * | img_file |
ImagicHeader | imagich |
bool | is_big_endian |
bool | initialized |
bool | is_new_hed |
bool | is_new_img |
DataType | datatype |
int | nz |
Static Private Attributes | |
static const char * | REAL_TYPE_MAGIC = "REAL" |
static const char * | CTF_MAGIC = "!-" |
Classes | |
struct | ImagicHeader |
An IMAGIC-5 file has 2 files: a) a header file with extension ".hed". It contains information for every image. b) an image file with extension ".img". It contains raw data.
The header file contains one (fixed-size) record per image stored. Every header record consists of 256 REAL/float for every image.
The image file contains only the raw data. Depending on the internal IMAGIC-5 format used, which can be REAL, INTG, PACK or COMP, the data is stored as REAL/float, INTEGER/int, INTEGER*1/byte or 2x REAL/float, respectively. The first pixel stored is the upper left one. The data is stored line by line, section by section, volume by volume.
3D imagic uses the same format to 2D. it is a bunch of 2D slices. use the 'hint' IS_3D to treat "2D slices" as 3D volume.
imagic doesn't store multiple 3D images in one file (header/data pair).
Definition at line 69 of file imagicio.h.
anonymous enum [private] |
Definition at line 103 of file imagicio.h.
00104 { 00105 NUM_4BYTES_PRE_IXOLD = 14, 00106 NUM_4BYTES_AFTER_IXOLD = 14, 00107 NUM_4BYTES_AFTER_SPACE = 207 00108 };
enum EMAN::ImagicIO::DataType [private] |
IMAGIC_UCHAR | |
IMAGIC_USHORT | |
IMAGIC_FLOAT | |
IMAGIC_FLOAT_COMPLEX | |
IMAGIC_FFT_FLOAT_COMPLEX | |
IMAGIC_UNKNOWN_TYPE |
Definition at line 93 of file imagicio.h.
00094 { 00095 IMAGIC_UCHAR, 00096 IMAGIC_USHORT, 00097 IMAGIC_FLOAT, 00098 IMAGIC_FLOAT_COMPLEX, 00099 IMAGIC_FFT_FLOAT_COMPLEX, 00100 IMAGIC_UNKNOWN_TYPE 00101 };
ImagicIO::ImagicIO | ( | string | filename, | |
IOMode | rw_mode = READ_ONLY | |||
) | [explicit] |
Definition at line 56 of file imagicio.cpp.
References EMAN::Util::change_filename_ext(), EMAN::ImagicIO::ImagicHeader::count, datatype, filename, HED_EXT, hed_filename, IMAGIC_UNKNOWN_TYPE, imagich, IMG_EXT, img_filename, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_hed, is_new_img, and nz.
00057 : filename(file), rw_mode(rw), hed_file(0), img_file(0), initialized(false) 00058 { 00059 hed_filename = Util::change_filename_ext(filename, HED_EXT); 00060 img_filename = Util::change_filename_ext(filename, IMG_EXT); 00061 00062 is_big_endian = ByteOrder::is_host_big_endian(); 00063 is_new_hed = false; 00064 is_new_img = false; 00065 memset(&imagich, 0, sizeof(ImagicHeader)); 00066 imagich.count = -1; 00067 datatype = IMAGIC_UNKNOWN_TYPE; 00068 nz = 0; 00069 }
ImagicIO::~ImagicIO | ( | ) |
ImagicIO::DataType ImagicIO::get_datatype_from_name | ( | const char * | name | ) | [private] |
Definition at line 634 of file imagicio.cpp.
References IMAGIC_FFT_FLOAT_COMPLEX, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_UCHAR, IMAGIC_UNKNOWN_TYPE, IMAGIC_USHORT, REAL_TYPE_MAGIC, and t.
00635 { 00636 DataType t = IMAGIC_UNKNOWN_TYPE; 00637 00638 if (strncmp(name, "PACK",4) == 0) { 00639 t = IMAGIC_UCHAR; 00640 } 00641 else if (strncmp(name, "INTG",4) == 0) { 00642 t = IMAGIC_USHORT; 00643 } 00644 else if (strncmp(name, REAL_TYPE_MAGIC,4) == 0) { 00645 t = IMAGIC_FLOAT; 00646 } 00647 else if (strncmp(name, "COMP",4) == 0) { 00648 t = IMAGIC_FLOAT_COMPLEX; 00649 } 00650 else if (strncmp(name, "RECO",4) == 0) { 00651 t = IMAGIC_FFT_FLOAT_COMPLEX; 00652 } 00653 return t; 00654 }
size_t EMAN::ImagicIO::get_datatype_size | ( | DataType | t | ) | [private] |
int ImagicIO::get_nimg | ( | ) | [virtual] |
Return the number of images in this image file.
Reimplemented from EMAN::ImageIO.
Definition at line 628 of file imagicio.cpp.
References EMAN::ImageIO::init().
bool EMAN::ImagicIO::is_single_image_format | ( | ) | const [inline, virtual] |
Is this image format only storing 1 image or not.
Some image formats like MRC only store 1 image in a file, so this function returns 'true' for them. Other image formats like IMAGIC/HDF5 may store mutliple images, so this function returns 'false' for them.
Reimplemented from EMAN::ImageIO.
Definition at line 81 of file imagicio.h.
bool ImagicIO::is_valid | ( | const void * | first_block | ) | [static] |
Definition at line 127 of file imagicio.cpp.
References data, ENTERFUNC, EXITFUNC, EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), nx, ny, and EMAN::ByteOrder::swap_bytes().
Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().
00128 { 00129 ENTERFUNC; 00130 00131 if (!first_block) { 00132 return false; 00133 } 00134 00135 const int *data = static_cast < const int *>(first_block); 00136 int count = data[1]; 00137 int headrec = data[3]; 00138 int month = data[5]; 00139 int hour = data[7]; 00140 int nx = data[13]; 00141 int ny = data[12]; 00142 00143 bool data_big_endian = ByteOrder::is_data_big_endian(&headrec); 00144 00145 if (data_big_endian != ByteOrder::is_host_big_endian()) { 00146 ByteOrder::swap_bytes(&count); 00147 ByteOrder::swap_bytes(&headrec); 00148 ByteOrder::swap_bytes(&month); 00149 ByteOrder::swap_bytes(&hour); 00150 ByteOrder::swap_bytes(&nx); 00151 ByteOrder::swap_bytes(&ny); 00152 } 00153 00154 const int max_dim = 1 << 20; 00155 bool result = false; 00156 00157 if (headrec == 1 && 00158 count >= 0 && count < max_dim && 00159 nx > 0 && nx < max_dim && 00160 ny > 0 && ny < max_dim && month >= 0 && hour >= 0 && hour <= 24) { 00161 result = true; 00162 } 00163 00164 EXITFUNC; 00165 return result; 00166 }
void ImagicIO::make_header_host_endian | ( | ImagicHeader & | hed | ) | [private] |
Definition at line 696 of file imagicio.cpp.
References is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and swap_header().
00697 { 00698 if (is_big_endian != ByteOrder::is_host_big_endian()) { 00699 swap_header(hed); 00700 } 00701 }
Ctf * ImagicIO::read_ctf | ( | const ImagicHeader & | hed | ) | const [private] |
the Ctf object is a EMAN1Ctf object.
Definition at line 573 of file imagicio.cpp.
References CTF_MAGIC, ENTERFUNC, EXITFUNC, EMAN::Ctf::from_string(), and EMAN::ImagicIO::ImagicHeader::label.
00574 { 00575 ENTERFUNC; 00576 00577 Ctf * ctf_ = 0; 00578 size_t n = strlen(CTF_MAGIC); 00579 00580 if (strncmp(imagich.label, CTF_MAGIC, n) == 0) { 00581 ctf_ = new EMAN1Ctf(); 00582 string header_label(hed.label); 00583 // Note: this block was making things crash because it assumed the following if statement 00584 // was true - I added the if statement (d.woolford) 00585 if (header_label.size() > 2) { 00586 string sctf = "O" + header_label.substr(2); 00587 ctf_->from_string(sctf); 00588 } 00589 } 00590 00591 EXITFUNC; 00592 return ctf_; 00593 }
void ImagicIO::swap_header | ( | ImagicHeader & | hed | ) | [private] |
Definition at line 704 of file imagicio.cpp.
References NUM_4BYTES_AFTER_IXOLD, NUM_4BYTES_AFTER_SPACE, NUM_4BYTES_PRE_IXOLD, and EMAN::ByteOrder::swap_bytes().
Referenced by make_header_host_endian().
00705 { 00706 ByteOrder::swap_bytes((int *) &hed, NUM_4BYTES_PRE_IXOLD); 00707 ByteOrder::swap_bytes(&hed.ixold, NUM_4BYTES_AFTER_IXOLD); 00708 ByteOrder::swap_bytes((int *) &hed.space, NUM_4BYTES_AFTER_SPACE); 00709 }
int EMAN::ImagicIO::to_em_datatype | ( | DataType | t | ) | [private] |
void ImagicIO::write_ctf | ( | const Ctf *const | ctf, | |
int | image_index = 0 | |||
) | [private] |
Definition at line 595 of file imagicio.cpp.
References CTF_MAGIC, ENTERFUNC, EXITFUNC, hed_filename, ImageWriteException, EMAN::ImageIO::init(), and EMAN::Ctf::to_string().
00596 { 00597 ENTERFUNC; 00598 init(); 00599 00600 size_t n = strlen(CTF_MAGIC); 00601 strcpy(imagich.label, CTF_MAGIC); 00602 string ctf_ = ctf->to_string().substr(1); 00603 strncpy(&imagich.label[n], ctf_.c_str(), sizeof(imagich.label) - n); 00604 00605 rewind(hed_file); 00606 if (fwrite(&imagich, sizeof(ImagicHeader), 1, hed_file) != 1) { 00607 throw ImageWriteException(hed_filename, "Imagic Header"); 00608 } 00609 00610 EXITFUNC; 00611 }
const char * ImagicIO::CTF_MAGIC = "!-" [static, private] |
DataType EMAN::ImagicIO::datatype [private] |
Definition at line 78 of file imagicio.h.
string EMAN::ImagicIO::filename [private] |
const char * ImagicIO::HED_EXT = "hed" [static] |
Definition at line 72 of file imagicio.h.
Referenced by EMAN::EMUtil::get_image_type(), and ImagicIO().
FILE* EMAN::ImagicIO::hed_file [private] |
string EMAN::ImagicIO::hed_filename [private] |
ImagicHeader EMAN::ImagicIO::imagich [private] |
const char * ImagicIO::IMG_EXT = "img" [static] |
Definition at line 73 of file imagicio.h.
Referenced by EMAN::EMUtil::get_image_type(), and ImagicIO().
FILE* EMAN::ImagicIO::img_file [private] |
string EMAN::ImagicIO::img_filename [private] |
bool EMAN::ImagicIO::initialized [private] |
Definition at line 196 of file imagicio.h.
bool EMAN::ImagicIO::is_big_endian [private] |
bool EMAN::ImagicIO::is_new_hed [private] |
bool EMAN::ImagicIO::is_new_img [private] |
int EMAN::ImagicIO::nz [private] |
const char * ImagicIO::REAL_TYPE_MAGIC = "REAL" [static, private] |
IOMode EMAN::ImagicIO::rw_mode [private] |
Definition at line 190 of file imagicio.h.