EMAN2
Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes | Static Private Attributes | List of all members
EMAN::PgmIO Class Reference

A PGM file = header + data. More...

#include <pgmio.h>

Inheritance diagram for EMAN::PgmIO:
Inheritance graph
[legend]
Collaboration diagram for EMAN::PgmIO:
Collaboration graph
[legend]

Public Member Functions

 PgmIO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~PgmIO ()
 
- Public Member Functions inherited from EMAN::ImageIO
 ImageIO (const string &fname, IOMode rw)
 
virtual ~ImageIO ()
 
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. More...
 
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. More...
 
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. More...
 
virtual int read_data_8bit (unsigned char *data, int image_index=0, const Region *area=0, bool is_3d=false, float minval=0.0f, float maxval=0.0f)
 Read the data from an image as an 8 bit array, regardless of format. More...
 
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. More...
 
virtual int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
virtual void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual int get_nimg ()
 Return the number of images in this image file. More...
 
virtual bool is_complex_mode ()=0
 Is this an complex image or not. More...
 
virtual bool is_image_big_endian ()=0
 Is this image in big endian or not. More...
 
virtual bool is_single_image_format () const
 Is this image format only storing 1 image or not. More...
 
template<class T >
void become_host_endian (T *data, size_t n=1)
 Convert data of this image into host endian format. More...
 
string get_filename () const
 

Static Public Member Functions

static bool is_valid (const void *first_block)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 

Private Types

enum  FileType { PGM_ASCII , PGM_BINARY , PGM_UNKNOWN_FILE }
 

Private Attributes

bool is_big_endian
 
int nx
 
int ny
 
int maxval
 
int minval
 
off_t file_offset
 
float rendermin
 
float rendermax
 
int renderbits
 

Static Private Attributes

static const char * MAGIC_ASCII = "P2"
 
static const char * MAGIC_BINARY = "P5"
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- Protected Member Functions inherited from EMAN::ImageIO
virtual void init ()=0
 Do some initialization before doing the read/write. More...
 
void check_read_access (int image_index)
 Validate 'image_index' in file reading. More...
 
void check_read_access (int image_index, const float *data)
 Validate 'image_index' and 'data' in file reading. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg=0)
 Validate rw_mode and image_index in file writing. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg, const float *data)
 Validate rw_mode, image_index, and data pointer in file writing. More...
 
void check_region (const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
void check_region (const Region *area, const IntSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
FILE * sfopen (const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
 Run fopen safely. More...
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

Detailed Description

A PGM file = header + data.

Header is always in ASCII format. Data can be in either ASCII or BINARY format. Only Binary format is supported in EMAN so far.

A PGM file contains one 2D image.

Definition at line 46 of file pgmio.h.

Member Enumeration Documentation

◆ FileType

enum EMAN::PgmIO::FileType
private
Enumerator
PGM_ASCII 
PGM_BINARY 
PGM_UNKNOWN_FILE 

Definition at line 59 of file pgmio.h.

60 {
64 };
@ PGM_ASCII
Definition: pgmio.h:61
@ PGM_UNKNOWN_FILE
Definition: pgmio.h:63
@ PGM_BINARY
Definition: pgmio.h:62

Constructor & Destructor Documentation

◆ PgmIO()

PgmIO::PgmIO ( const string &  fname,
IOMode  rw_mode = READ_ONLY 
)
explicit

Definition at line 42 of file pgmio.cpp.

43: ImageIO(fname, rw), is_big_endian(true),
44 nx(0), ny(0), maxval(0), minval(0),
46{}
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40
int nx
Definition: pgmio.h:69
int minval
Definition: pgmio.h:72
int renderbits
Definition: pgmio.h:78
int ny
Definition: pgmio.h:70
float rendermax
Definition: pgmio.h:77
off_t file_offset
Definition: pgmio.h:74
int maxval
Definition: pgmio.h:71
bool is_big_endian
Definition: pgmio.h:67
float rendermin
Definition: pgmio.h:76

◆ ~PgmIO()

PgmIO::~PgmIO ( )

Definition at line 48 of file pgmio.cpp.

49{
50 if (file) {
51 fclose(file);
52 file = 0;
53 }
54}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file.

Member Function Documentation

◆ is_valid()

bool PgmIO::is_valid ( const void *  first_block)
static

Definition at line 120 of file pgmio.cpp.

121{
122 ENTERFUNC;
123 bool result = false;
124 if (first_block) {
125 result = Util::check_file_by_magic(first_block, MAGIC_BINARY);
126 }
127 EXITFUNC;
128 return result;
129}
static const char * MAGIC_BINARY
Definition: pgmio.h:57
static bool check_file_by_magic(const void *first_block, const char *magic)
check whether a file starts with certain magic string.
Definition: util.cpp:239
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References EMAN::Util::check_file_by_magic(), ENTERFUNC, EXITFUNC, and MAGIC_BINARY.

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

Member Data Documentation

◆ DEFINE_IMAGEIO_FUNC

EMAN::PgmIO::DEFINE_IMAGEIO_FUNC

Definition at line 52 of file pgmio.h.

◆ file_offset

off_t EMAN::PgmIO::file_offset
private

Definition at line 74 of file pgmio.h.

◆ is_big_endian

bool EMAN::PgmIO::is_big_endian
private

Definition at line 67 of file pgmio.h.

◆ MAGIC_ASCII

const char * PgmIO::MAGIC_ASCII = "P2"
staticprivate

Definition at line 56 of file pgmio.h.

◆ MAGIC_BINARY

const char * PgmIO::MAGIC_BINARY = "P5"
staticprivate

Definition at line 57 of file pgmio.h.

Referenced by is_valid().

◆ maxval

int EMAN::PgmIO::maxval
private

Definition at line 71 of file pgmio.h.

◆ minval

int EMAN::PgmIO::minval
private

Definition at line 72 of file pgmio.h.

◆ nx

int EMAN::PgmIO::nx
private

Definition at line 69 of file pgmio.h.

◆ ny

int EMAN::PgmIO::ny
private

Definition at line 70 of file pgmio.h.

◆ renderbits

int EMAN::PgmIO::renderbits
private

Definition at line 78 of file pgmio.h.

◆ rendermax

float EMAN::PgmIO::rendermax
private

Definition at line 77 of file pgmio.h.

◆ rendermin

float EMAN::PgmIO::rendermin
private

Definition at line 76 of file pgmio.h.


The documentation for this class was generated from the following files: