#include <imagicio2.h>
Inheritance diagram for EMAN::ImagicIO2:
Public Member Functions | |
ImagicIO2 (string filename, IOMode rw_mode=READ_ONLY) | |
~ImagicIO2 () | |
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 |
static const char * | IMG_EXT |
Private Types | |
IMAGIC_CHAR | |
IMAGIC_SHORT | |
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 | |
VAX_VMS = 16777216 | |
LINUX_WINDOWS = 33686018 | |
SGI_IBM = 67372036 | |
enum | DataType { IMAGIC_CHAR, IMAGIC_SHORT, 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 } |
enum | RealType { VAX_VMS = 16777216, LINUX_WINDOWS = 33686018, SGI_IBM = 67372036 } |
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 |
Imagic4D | imagich |
bool | is_big_endian |
bool | initialized |
bool | is_new_hed |
bool | is_new_img |
DataType | datatype |
Static Private Attributes | |
static const char * | REAL_TYPE_MAGIC |
static const char * | CTF_MAGIC |
Classes | |
struct | Imagic4D |
IMAGIC-4D file format http://www.imagescience.de/formats/formats.htm. More... |
Renewed 4D version: http://www.imagescience.de/formats/formats.htm
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.
This renewed version support storing multiple 3D images in one file (header/data pair).
EMAN2 will read both old and new Imagic header, but write to new format from - Grant Tang.
Definition at line 73 of file imagicio2.h.
anonymous enum [private] |
Definition at line 107 of file imagicio2.h.
00108 { 00109 NUM_4BYTES_PRE_IXOLD = 14, 00110 NUM_4BYTES_AFTER_IXOLD = 14, 00111 NUM_4BYTES_AFTER_SPACE = 207 00112 };
enum EMAN::ImagicIO2::DataType [private] |
IMAGIC_CHAR | |
IMAGIC_SHORT | |
IMAGIC_FLOAT | |
IMAGIC_FLOAT_COMPLEX | |
IMAGIC_FFT_FLOAT_COMPLEX | |
IMAGIC_UNKNOWN_TYPE |
Definition at line 97 of file imagicio2.h.
00098 { 00099 IMAGIC_CHAR, 00100 IMAGIC_SHORT, 00101 IMAGIC_FLOAT, 00102 IMAGIC_FLOAT_COMPLEX, 00103 IMAGIC_FFT_FLOAT_COMPLEX, 00104 IMAGIC_UNKNOWN_TYPE 00105 };
enum EMAN::ImagicIO2::RealType [private] |
Definition at line 114 of file imagicio2.h.
00115 { 00116 VAX_VMS = 16777216, //for VAX/VMS 00117 LINUX_WINDOWS = 33686018, //for OSF, ULTRIX, LINUX, MS WINDOWS 00118 SGI_IBM = 67372036 //for SiliconGraphics, SUN, HP, IBM 00119 };
ImagicIO2::ImagicIO2 | ( | string | filename, | |
IOMode | rw_mode = READ_ONLY | |||
) | [explicit] |
Definition at line 56 of file imagicio2.cpp.
References EMAN::Util::change_filename_ext(), EMAN::ImagicIO2::Imagic4D::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, and is_new_img.
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(Imagic4D)); 00066 imagich.count = -1; 00067 datatype = IMAGIC_UNKNOWN_TYPE; 00068 nz = 0; 00069 }
ImagicIO2::~ImagicIO2 | ( | ) |
ImagicIO2::DataType ImagicIO2::get_datatype_from_name | ( | const char * | name | ) | [private] |
Definition at line 291 of file imagicio2.cpp.
References IMAGIC_CHAR, IMAGIC_FFT_FLOAT_COMPLEX, IMAGIC_FLOAT, IMAGIC_FLOAT_COMPLEX, IMAGIC_SHORT, IMAGIC_UNKNOWN_TYPE, REAL_TYPE_MAGIC, and t.
00292 { 00293 DataType t = IMAGIC_UNKNOWN_TYPE; 00294 00295 if (strncmp(name, "PACK",4) == 0) { 00296 t = IMAGIC_CHAR; 00297 } 00298 else if (strncmp(name, "INTG",4) == 0) { 00299 t = IMAGIC_SHORT; 00300 } 00301 else if (strncmp(name, REAL_TYPE_MAGIC,4) == 0) { 00302 t = IMAGIC_FLOAT; 00303 } 00304 else if (strncmp(name, "COMP",4) == 0) { 00305 t = IMAGIC_FLOAT_COMPLEX; 00306 } 00307 else if (strncmp(name, "RECO",4) == 0) { 00308 t = IMAGIC_FFT_FLOAT_COMPLEX; 00309 } 00310 return t; 00311 }
size_t EMAN::ImagicIO2::get_datatype_size | ( | DataType | t | ) | [private] |
int EMAN::ImagicIO2::get_nimg | ( | ) | [virtual] |
bool EMAN::ImagicIO2::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 85 of file imagicio2.h.
bool ImagicIO2::is_valid | ( | const void * | first_block | ) | [static] |
Definition at line 127 of file imagicio2.cpp.
References data, ENTERFUNC, EXITFUNC, EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), LINUX_WINDOWS, nx, ny, SGI_IBM, EMAN::ByteOrder::swap_bytes(), and VAX_VMS.
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[4]; 00139 int hour = data[7]; 00140 int nx = data[13]; 00141 int ny = data[12]; 00142 int realtype = data[68]; 00143 00144 bool data_big_endian = ByteOrder::is_data_big_endian(&headrec); 00145 00146 if (data_big_endian != ByteOrder::is_host_big_endian()) { 00147 ByteOrder::swap_bytes(&count); 00148 ByteOrder::swap_bytes(&headrec); 00149 ByteOrder::swap_bytes(&month); 00150 ByteOrder::swap_bytes(&hour); 00151 ByteOrder::swap_bytes(&nx); 00152 ByteOrder::swap_bytes(&ny); 00153 ByteOrder::swap_bytes(&realtype); 00154 } 00155 00156 const int max_dim = 1 << 20; 00157 bool result = false; 00158 00159 // this field realtype is unique to new Imagic-5 format 00160 if(realtype != VAX_VMS && realtype != LINUX_WINDOWS && realtype != SGI_IBM) { 00161 EXITFUNC; 00162 return result; 00163 } 00164 00165 if (headrec == 1 && 00166 count >= 0 && count < max_dim && 00167 nx > 0 && nx < max_dim && 00168 ny > 0 && ny < max_dim && 00169 month >= 0 && month <=12 && 00170 hour >= 0 && hour <= 24) { 00171 result = true; 00172 } 00173 00174 EXITFUNC; 00175 return result; 00176 }
void EMAN::ImagicIO2::make_header_host_endian | ( | ImagicHeader & | hed | ) | [private] |
Ctf* EMAN::ImagicIO2::read_ctf | ( | const ImagicHeader & | hed | ) | const [private] |
void EMAN::ImagicIO2::swap_header | ( | ImagicHeader & | hed | ) | [private] |
int EMAN::ImagicIO2::to_em_datatype | ( | DataType | t | ) | [private] |
void ImagicIO2::write_ctf | ( | const Ctf *const | ctf, | |
int | image_index = 0 | |||
) | [private] |
Definition at line 354 of file imagicio2.cpp.
References CTF_MAGIC, ENTERFUNC, EXITFUNC, hed_file, hed_filename, ImageWriteException, EMAN::ImageIO::init(), and EMAN::Ctf::to_string().
00355 { 00356 ENTERFUNC; 00357 init(); 00358 00359 size_t n = strlen(CTF_MAGIC); 00360 strcpy(imagich.label, CTF_MAGIC); 00361 string ctf_ = ctf->to_string().substr(1); 00362 strncpy(&imagich.label[n], ctf_.c_str(), sizeof(imagich.label) - n); 00363 00364 rewind(hed_file); 00365 if (fwrite(&imagich, sizeof(ImagicHeader), 1, hed_file) != 1) { 00366 throw ImageWriteException(hed_filename, "Imagic Header"); 00367 } 00368 00369 EXITFUNC; 00370 }
const char* EMAN::ImagicIO2::CTF_MAGIC [static, private] |
DataType EMAN::ImagicIO2::datatype [private] |
Definition at line 82 of file imagicio2.h.
string EMAN::ImagicIO2::filename [private] |
const char* EMAN::ImagicIO2::HED_EXT [static] |
FILE* EMAN::ImagicIO2::hed_file [private] |
string EMAN::ImagicIO2::hed_filename [private] |
Imagic4D EMAN::ImagicIO2::imagich [private] |
const char* EMAN::ImagicIO2::IMG_EXT [static] |
FILE* EMAN::ImagicIO2::img_file [private] |
string EMAN::ImagicIO2::img_filename [private] |
bool EMAN::ImagicIO2::initialized [private] |
Definition at line 249 of file imagicio2.h.
bool EMAN::ImagicIO2::is_big_endian [private] |
bool EMAN::ImagicIO2::is_new_hed [private] |
bool EMAN::ImagicIO2::is_new_img [private] |
const char* EMAN::ImagicIO2::REAL_TYPE_MAGIC [static, private] |
IOMode EMAN::ImagicIO2::rw_mode [private] |
Definition at line 243 of file imagicio2.h.