#include <pifio.h>
Inheritance diagram for EMAN::PifIO:
Public Member Functions | |
PifIO (const string &filename, IOMode rw_mode=READ_ONLY) | |
~PifIO () | |
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 | |
bool | is_valid (const void *first_block) |
Public Attributes | |
DEFINE_IMAGEIO_FUNC | |
Private Types | |
enum | { PIF_MAGIC_NUM = 8 } |
enum | PifDataMode { PIF_CHAR = 0, PIF_SHORT = 1, PIF_FLOAT_INT = 2, PIF_SHORT_COMPLEX = 3, PIF_FLOAT_INT_COMPLEX = 4, PIF_BOXED_DATA = 6, PIF_SHORT_FLOAT = 7, PIF_SHORT_FLOAT_COMPLEX = 8, PIF_FLOAT = 9, PIF_FLOAT_COMPLEX = 10, PIF_MAP_FLOAT_SHORT = 20, PIF_MAP_FLOAT_INT = 21, PIF_MAP_FLOAT_INT_2 = 40, PIF_BOXED_FLOAT_INT = 46, PIF_INVALID } |
Private Member Functions | |
int | get_mode_size (PifDataMode mode) |
bool | is_float_int (int mode) |
void | fseek_to (int image_index) |
int | to_em_datatype (int pif_datatype) |
int | to_pif_datatype (int em_datatype) |
Private Attributes | |
string | filename |
IOMode | rw_mode |
PifFileHeader | pfh |
FILE * | pif_file |
int | mode_size |
bool | is_big_endian |
bool | initialized |
bool | is_new_file |
float | real_scale_factor |
A PIF file = file header + (image header + image data) + (image header + image data) ...
A PIF file has a overall file header followed by n images. Each image has a header and data block.
EMAN only supports homogeneous PIF file, which means all images n a PIF should have the same dimensions. We also assume the (nx,ny,nz) in PifFileHeader are equal to (nx,ny,nz) in each Image header.
Definition at line 56 of file pifio.h.
|
Definition at line 72 of file pifio.h. 00073 { 00074 PIF_MAGIC_NUM = 8 00075 };
|
|
Definition at line 77 of file pifio.h. Referenced by is_float_int(), to_em_datatype(), and to_pif_datatype(). 00078 { 00079 PIF_CHAR = 0, 00080 PIF_SHORT = 1, 00081 PIF_FLOAT_INT = 2, 00082 PIF_SHORT_COMPLEX = 3, 00083 PIF_FLOAT_INT_COMPLEX = 4, 00084 PIF_BOXED_DATA = 6, // byte, read as 0 00085 PIF_SHORT_FLOAT = 7, 00086 PIF_SHORT_FLOAT_COMPLEX = 8, 00087 PIF_FLOAT = 9, 00088 PIF_FLOAT_COMPLEX = 10, 00089 PIF_MAP_FLOAT_SHORT = 20, 00090 PIF_MAP_FLOAT_INT = 21, 00091 PIF_MAP_FLOAT_INT_2 = 40, // 4 byte floatint, read as 2 00092 PIF_BOXED_FLOAT_INT = 46, // 4 byte floatint, read as 2 00093 PIF_INVALID 00094 };
|
|
Definition at line 48 of file pifio.cpp. References initialized, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_file, mode_size, pfh, pif_file, and real_scale_factor. 00049 : filename(pif_filename), rw_mode(rw) 00050 { 00051 pif_file = 0; 00052 mode_size = 0; 00053 is_big_endian = ByteOrder::is_host_big_endian(); 00054 initialized = false; 00055 real_scale_factor = 1; 00056 is_new_file = false; 00057 memset(&pfh, 0, sizeof(PifFileHeader)); 00058 }
|
|
Definition at line 60 of file pifio.cpp. References pif_file. 00061 { 00062 if (pif_file) { 00063 fclose(pif_file); 00064 pif_file = 0; 00065 } 00066 }
|
|
Definition at line 198 of file pifio.cpp. References EMAN::PifIO::PifFileHeader::nimg, EMAN::PifIO::PifFileHeader::nx, EMAN::PifIO::PifFileHeader::ny, EMAN::PifIO::PifFileHeader::nz, pfh, pif_file, and portable_fseek(). 00199 { 00200 int pih_sz = sizeof(PifImageHeader); 00201 int image_size = 0; 00202 00203 #if 0 00204 // this works for some images that PURDUE people gave to me. 00205 // But those images don't follow the PIF specification. So 00206 // I believe they are in wrong format. 00207 if (pfh.nimg == 1) { 00208 image_size = pfh.nx * pfh.ny * pfh.nz; 00209 } 00210 else { 00211 image_size = pfh.nx * pfh.ny; 00212 } 00213 #endif 00214 image_size = pfh.nx * pfh.ny * pfh.nz; 00215 00216 size_t file_offset = sizeof(PifFileHeader) + 00217 (pih_sz + image_size * mode_size) * image_index; 00218 00219 portable_fseek(pif_file, file_offset, SEEK_SET); 00220 }
|
|
Definition at line 69 of file pifio.cpp. References PIF_BOXED_DATA, PIF_BOXED_FLOAT_INT, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT, PIF_SHORT_COMPLEX, PIF_SHORT_FLOAT, and PIF_SHORT_FLOAT_COMPLEX. 00070 { 00071 int size = 0; 00072 00073 switch (mode) { 00074 case PIF_CHAR: 00075 case PIF_BOXED_DATA: 00076 size = sizeof(char); 00077 break; 00078 case PIF_SHORT: 00079 case PIF_SHORT_FLOAT: 00080 case PIF_SHORT_COMPLEX: 00081 case PIF_SHORT_FLOAT_COMPLEX: 00082 case PIF_MAP_FLOAT_SHORT: 00083 size = sizeof(short); 00084 break; 00085 case PIF_FLOAT: 00086 case PIF_FLOAT_COMPLEX: 00087 size = sizeof(float); 00088 break; 00089 case PIF_FLOAT_INT: 00090 case PIF_FLOAT_INT_COMPLEX: 00091 case PIF_MAP_FLOAT_INT: 00092 case PIF_MAP_FLOAT_INT_2: 00093 case PIF_BOXED_FLOAT_INT: 00094 size = sizeof(int); 00095 break; 00096 default: 00097 break; 00098 } 00099 return size; 00100 }
|
|
Return the number of images in this image file.
Reimplemented from EMAN::ImageIO. Definition at line 545 of file pifio.cpp. References EMAN::ImageIO::init(), EMAN::PifIO::PifFileHeader::nimg, and pfh.
|
|
Definition at line 102 of file pifio.cpp. References PIF_BOXED_FLOAT_INT, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT_FLOAT, PIF_SHORT_FLOAT_COMPLEX, and PifDataMode. 00103 { 00104 PifDataMode mode = static_cast < PifDataMode > (m); 00105 switch (mode) { 00106 case PIF_SHORT_FLOAT: 00107 case PIF_SHORT_FLOAT_COMPLEX: 00108 //case PIF_FLOAT: 00109 case PIF_FLOAT_INT: 00110 //case PIF_FLOAT_COMPLEX: 00111 case PIF_FLOAT_INT_COMPLEX: 00112 case PIF_MAP_FLOAT_SHORT: 00113 case PIF_MAP_FLOAT_INT: 00114 case PIF_MAP_FLOAT_INT_2: 00115 case PIF_BOXED_FLOAT_INT: 00116 return true; 00117 default: 00118 break; 00119 } 00120 return false; 00121 }
|
|
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 65 of file pifio.h. 00066 { 00067 return false; 00068 }
|
|
Definition at line 169 of file pifio.cpp. References data, EMAN::ByteOrder::is_host_big_endian(), PIF_MAGIC_NUM, and EMAN::ByteOrder::swap_bytes(). Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type(). 00170 { 00171 ENTERFUNC; 00172 bool result = false; 00173 00174 if (first_block) { 00175 const int *data = static_cast < const int *>(first_block); 00176 int m1 = data[0]; 00177 int m2 = data[1]; 00178 int endian = data[7]; 00179 bool data_big_endian = false; 00180 if (endian) { 00181 data_big_endian = true; 00182 } 00183 00184 if (data_big_endian != ByteOrder::is_host_big_endian()) { 00185 ByteOrder::swap_bytes(&m1); 00186 ByteOrder::swap_bytes(&m2); 00187 } 00188 00189 if (m1 == PIF_MAGIC_NUM && m2 == PIF_MAGIC_NUM) { 00190 result = true; 00191 } 00192 } 00193 00194 EXITFUNC; 00195 return result; 00196 }
|
|
Definition at line 552 of file pifio.cpp. References PIF_BOXED_DATA, PIF_BOXED_FLOAT_INT, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_INVALID, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT, PIF_SHORT_COMPLEX, PIF_SHORT_FLOAT, PIF_SHORT_FLOAT_COMPLEX, and PifDataMode. 00553 { 00554 PifDataMode mode = static_cast < PifDataMode > (p); 00555 EMUtil::EMDataType e = EMUtil::EM_UNKNOWN; 00556 00557 switch (mode) { 00558 case PIF_CHAR: 00559 case PIF_BOXED_DATA: 00560 e = EMUtil::EM_CHAR; 00561 break; 00562 00563 case PIF_SHORT: 00564 case PIF_SHORT_FLOAT: 00565 case PIF_MAP_FLOAT_SHORT: 00566 e = EMUtil::EM_SHORT; 00567 break; 00568 00569 case PIF_SHORT_COMPLEX: 00570 case PIF_SHORT_FLOAT_COMPLEX: 00571 e = EMUtil::EM_SHORT_COMPLEX; 00572 break; 00573 00574 case PIF_FLOAT: 00575 case PIF_FLOAT_INT: 00576 case PIF_MAP_FLOAT_INT: 00577 case PIF_MAP_FLOAT_INT_2: 00578 case PIF_BOXED_FLOAT_INT: 00579 e = EMUtil::EM_FLOAT; 00580 break; 00581 case PIF_FLOAT_COMPLEX: 00582 case PIF_FLOAT_INT_COMPLEX: 00583 e = EMUtil::EM_FLOAT_COMPLEX; 00584 break; 00585 case PIF_INVALID: 00586 e = EMUtil::EM_UNKNOWN; 00587 break; 00588 } 00589 return e; 00590 }
|
|
Definition at line 592 of file pifio.cpp. References LOGERR, and PifDataMode. 00593 { 00594 PifDataMode m = PIF_INVALID; 00595 00596 switch (e) { 00597 case EMUtil::EM_CHAR: 00598 m = PIF_BOXED_DATA; 00599 break; 00600 case EMUtil::EM_SHORT: 00601 m = PIF_SHORT; 00602 break; 00603 case EMUtil::EM_SHORT_COMPLEX: 00604 m = PIF_SHORT_COMPLEX; 00605 break; 00606 case EMUtil::EM_FLOAT: 00607 m = PIF_FLOAT_INT; 00608 break; 00609 case EMUtil::EM_FLOAT_COMPLEX: 00610 m = PIF_FLOAT_COMPLEX; 00611 break; 00612 default: 00613 LOGERR("unknown PIF mode: %d", e); 00614 } 00615 00616 return m; 00617 }
|
|
|
|
|
|
Definition at line 184 of file pifio.h. Referenced by PifIO(). |
|
Definition at line 183 of file pifio.h. Referenced by PifIO(). |
|
Definition at line 185 of file pifio.h. Referenced by PifIO(). |
|
Definition at line 182 of file pifio.h. Referenced by PifIO(). |
|
Definition at line 180 of file pifio.h. Referenced by fseek_to(), get_nimg(), and PifIO(). |
|
Definition at line 181 of file pifio.h. Referenced by fseek_to(), PifIO(), and ~PifIO(). |
|
Definition at line 186 of file pifio.h. Referenced by PifIO(). |
|
|