37OmapIO::OmapIO(
const string & fname,
IOMode rw) :
39 is_big_endian(false), is_new_file(false)
67 if (fread(record, 512, 1,
file) != 1) {
71 for(
int i=0; i<512; i++) {
72 if(!isprint(record[i])) {
77 if(record[i] ==
'\0')
break;
80 if (fread(&
omaph,
sizeof(OmapHeader), 1,
file) != 1) {
121 float prod = (float)(
omaph.
iprod/(
int)dict[
"OMAP.scale2"]);
124 dict[
"OMAP.min"] = (
omaph.
imin - plus)/prod;
125 dict[
"OMAP.imax"] = (
omaph.
imax - plus)/prod;
127 dict[
"OMAP.mean"] = (
omaph.
imean - plus)/prod;
129 if((
float)dict[
"OMAP.sigma"] < 0.001f || (float)dict[
"OMAP.sigma"] > 10.0f) {
130 std::cout <<
"Warning : Suspect value of sigma : " << (float)dict[
"OMAP.sigma"] << std::endl;
131 dict[
"OMAP.sigma"] = 0;
163 unsigned char record[512];
164 for (
int k=0; k < inz; k++) {
165 for (
int j=0; j < iny; j++) {
166 for (
int i=0; i < inx; i++) {
167 if (fread(record, 512, 1,
file) != 1) {
172 bool byteswap =
false;
177 for (
int ii=0; ii < 511; ii+=2) {
178 char tempchar = record[ii];
179 record[ii] = record[ii+1];
180 record[ii+1] = tempchar;
189 if (xtraX > 0)
if (i == inx-1) cubieSizeX = xtraX;
190 if (xtraY > 0)
if (j == iny-1) cubieSizeY = xtraY;
191 if (xtraZ > 0)
if (k == inz-1) cubieSizeZ = xtraZ;
193 for (
int n=0; n < cubieSizeZ; n++) {
194 for (
int m=0; m < cubieSizeY; m++) {
195 for (
int l=0; l < cubieSizeX; l++) {
196 unsigned char sboxLMN = record[8*8*n+8*m+l];
198 pixel = ((float)sboxLMN - plus)/prod;
244 const short *data =
static_cast < const short *
>(first_block);
245 short xstart = data[0];
246 short ystart = data[1];
247 short zstart = data[2];
251 short const_value = data[18];
263 if(const_value != 100)
return false;
264 if(nx<=0 || ny<=0 || nz<=0 || nx>10000 || ny>10000 || nz>10000)
return false;
static bool is_host_big_endian()
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Dict is a dictionary to store <string, EMObject> pair.
EMDataType
Image pixel data type used in EMAN.
ImageIO classes are designed for reading/writing various electron micrography image formats,...
virtual void flush()=0
Flush the IO buffer.
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.
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.
virtual bool is_complex_mode()=0
Is this an complex image or not.
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.
FILE * sfopen(const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
Run fopen safely.
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.
virtual void init()=0
Do some initialization before doing the read/write.
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
static bool is_valid(const void *first_block, off_t file_size=0)
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
#define ImageReadException(filename, desc)
#define ImageWriteException(imagename, desc)
int portable_fseek(FILE *fp, off_t offset, int whence)