#include <imagicio.h>


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 | |
| 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.
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 };
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 };
| 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 | ( | ) |
| 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 && month <= 12 && hour >= 0 && hour <= 24) { 00161 result = true; 00162 } 00163 00164 EXITFUNC; 00165 return result; 00166 }
| 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.
| int ImagicIO::get_nimg | ( | ) | [virtual] |
Return the number of images in this image file.
Reimplemented from EMAN::ImageIO.
Definition at line 624 of file imagicio.cpp.
References EMAN::ImagicIO::ImagicHeader::count, imagich, and EMAN::ImageIO::init().
| size_t ImagicIO::get_datatype_size | ( | DataType | t | ) | [private] |
Definition at line 652 of file imagicio.cpp.
References IMAGIC_FFT_FLOAT_COMPLEX, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_UCHAR, and IMAGIC_USHORT.
00653 { 00654 size_t s = 0; 00655 switch (t) { 00656 case IMAGIC_UCHAR: 00657 s = sizeof(unsigned char); 00658 break; 00659 case IMAGIC_USHORT: 00660 s = sizeof(unsigned short); 00661 break; 00662 case IMAGIC_FLOAT: 00663 case IMAGIC_FLOAT_COMPLEX: 00664 case IMAGIC_FFT_FLOAT_COMPLEX: 00665 s = sizeof(float); 00666 break; 00667 default: 00668 s = 0; 00669 } 00670 00671 return s; 00672 }
| int ImagicIO::to_em_datatype | ( | DataType | t | ) | [private] |
Definition at line 674 of file imagicio.cpp.
References EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_FLOAT_COMPLEX, EMAN::EMUtil::EM_UCHAR, EMAN::EMUtil::EM_UNKNOWN, EMAN::EMUtil::EM_USHORT, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_UCHAR, and IMAGIC_USHORT.
00675 { 00676 switch (t) { 00677 case IMAGIC_UCHAR: 00678 return EMUtil::EM_UCHAR; 00679 case IMAGIC_USHORT: 00680 return EMUtil::EM_USHORT; 00681 case IMAGIC_FLOAT: 00682 return EMUtil::EM_FLOAT; 00683 case IMAGIC_FLOAT_COMPLEX: 00684 return EMUtil::EM_FLOAT_COMPLEX; 00685 default: 00686 break; 00687 } 00688 00689 return EMUtil::EM_UNKNOWN; 00690 }
| void ImagicIO::make_header_host_endian | ( | ImagicHeader & | hed | ) | [private] |
Definition at line 692 of file imagicio.cpp.
References is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and swap_header().
00693 { 00694 if (is_big_endian != ByteOrder::is_host_big_endian()) { 00695 swap_header(hed); 00696 } 00697 }
| void ImagicIO::swap_header | ( | ImagicHeader & | hed | ) | [private] |
Definition at line 700 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().
00701 { 00702 ByteOrder::swap_bytes((int *) &hed, NUM_4BYTES_PRE_IXOLD); 00703 ByteOrder::swap_bytes(&hed.ixold, NUM_4BYTES_AFTER_IXOLD); 00704 ByteOrder::swap_bytes((int *) &hed.space, NUM_4BYTES_AFTER_SPACE); 00705 }
| ImagicIO::DataType ImagicIO::get_datatype_from_name | ( | const char * | name | ) | [private] |
Definition at line 630 of file imagicio.cpp.
References IMAGIC_FFT_FLOAT_COMPLEX, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_UCHAR, IMAGIC_UNKNOWN_TYPE, IMAGIC_USHORT, and REAL_TYPE_MAGIC.
00631 { 00632 DataType t = IMAGIC_UNKNOWN_TYPE; 00633 00634 if (strncmp(name, "PACK",4) == 0) { 00635 t = IMAGIC_UCHAR; 00636 } 00637 else if (strncmp(name, "INTG",4) == 0) { 00638 t = IMAGIC_USHORT; 00639 } 00640 else if (strncmp(name, REAL_TYPE_MAGIC,4) == 0) { 00641 t = IMAGIC_FLOAT; 00642 } 00643 else if (strncmp(name, "COMP",4) == 0) { 00644 t = IMAGIC_FLOAT_COMPLEX; 00645 } 00646 else if (strncmp(name, "RECO",4) == 0) { 00647 t = IMAGIC_FFT_FLOAT_COMPLEX; 00648 } 00649 return t; 00650 }
| Ctf * ImagicIO::read_ctf | ( | const ImagicHeader & | hed | ) | const [private] |
the Ctf object is a EMAN1Ctf object.
Definition at line 569 of file imagicio.cpp.
References CTF_MAGIC, ENTERFUNC, EXITFUNC, EMAN::Ctf::from_string(), imagich, and EMAN::ImagicIO::ImagicHeader::label.
00570 { 00571 ENTERFUNC; 00572 00573 Ctf * ctf_ = 0; 00574 size_t n = strlen(CTF_MAGIC); 00575 00576 if (strncmp(imagich.label, CTF_MAGIC, n) == 0) { 00577 ctf_ = new EMAN1Ctf(); 00578 string header_label(hed.label); 00579 // Note: this block was making things crash because it assumed the following if statement 00580 // was true - I added the if statement (d.woolford) 00581 if (header_label.size() > 2) { 00582 string sctf = "O" + header_label.substr(2); 00583 ctf_->from_string(sctf); 00584 } 00585 } 00586 00587 EXITFUNC; 00588 return ctf_; 00589 }
| void ImagicIO::write_ctf | ( | const Ctf *const | ctf, | |
| int | image_index = 0 | |||
| ) | [private] |
Definition at line 591 of file imagicio.cpp.
References CTF_MAGIC, ENTERFUNC, EXITFUNC, hed_file, hed_filename, ImageWriteException, imagich, EMAN::ImageIO::init(), EMAN::ImagicIO::ImagicHeader::label, and EMAN::Ctf::to_string().
00592 { 00593 ENTERFUNC; 00594 init(); 00595 00596 size_t n = strlen(CTF_MAGIC); 00597 strcpy(imagich.label, CTF_MAGIC); 00598 string ctf_ = ctf->to_string().substr(1); 00599 strncpy(&imagich.label[n], ctf_.c_str(), sizeof(imagich.label) - n); 00600 00601 rewind(hed_file); 00602 if (fwrite(&imagich, sizeof(ImagicHeader), 1, hed_file) != 1) { 00603 throw ImageWriteException(hed_filename, "Imagic Header"); 00604 } 00605 00606 EXITFUNC; 00607 }
const char * ImagicIO::HED_EXT = "hed" [static] |
Definition at line 72 of file imagicio.h.
Referenced by EMAN::EMUtil::get_image_type(), and ImagicIO().
const char * ImagicIO::IMG_EXT = "img" [static] |
Definition at line 73 of file imagicio.h.
Referenced by EMAN::EMUtil::get_image_type(), and ImagicIO().
Definition at line 78 of file imagicio.h.
const char * ImagicIO::REAL_TYPE_MAGIC = "REAL" [static, private] |
const char * ImagicIO::CTF_MAGIC = "!-" [static, private] |
string EMAN::ImagicIO::filename [private] |
string EMAN::ImagicIO::hed_filename [private] |
string EMAN::ImagicIO::img_filename [private] |
IOMode EMAN::ImagicIO::rw_mode [private] |
Definition at line 190 of file imagicio.h.
FILE* EMAN::ImagicIO::hed_file [private] |
FILE* EMAN::ImagicIO::img_file [private] |
ImagicHeader EMAN::ImagicIO::imagich [private] |
Definition at line 194 of file imagicio.h.
Referenced by get_nimg(), ImagicIO(), read_ctf(), and write_ctf().
bool EMAN::ImagicIO::is_big_endian [private] |
bool EMAN::ImagicIO::initialized [private] |
Definition at line 196 of file imagicio.h.
bool EMAN::ImagicIO::is_new_hed [private] |
bool EMAN::ImagicIO::is_new_img [private] |
DataType EMAN::ImagicIO::datatype [private] |
int EMAN::ImagicIO::nz [private] |
1.5.6