35#include <boost/property_tree/xml_parser.hpp>
38using boost::property_tree::ptree;
43 return std::make_pair(
x(count, sub_pix),
y(count, sub_pix));
46typedef vector<pair<int, int>>
COORDS;
59 coords.push_back(decoder(count, sub_pix));
72 cout << module <<
": ";
79 char *metadata_c =
nullptr;
82 TIFFSetDirectory(tiff, 0);
83 TIFFGetField(tiff, 65001, &count, &metadata_c);
85 return string(metadata_c, count);
91 for(
int i=0; i<s.size(); i++) {
93 if(!isupper(s[i-1])) {
94 ret.insert(i + sh,
"_");
97 ret[i + sh] = ::tolower(s[i]);
106 std::istringstream ins(metadata);
111 for(
auto &v : pt.get_child(
"metadata")) {
112 auto xml_item_name = v.second.get_child(
"<xmlattr>.name").data();
113 auto xml_item_value = v.second.data();
117 dict[key] = xml_item_value;
124 uint16_t compression = 0;
126 TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);
132 auto num_strips = TIFFNumberOfStrips(tiff);
133 vector<unsigned int> strip_sizes(num_strips);
135 for(
size_t i=0; i<num_strips; ++i)
136 strip_sizes[i] = TIFFRawStripSize(tiff, i);
138 std::vector<unsigned char> data;
140 for(
size_t i=0; i<num_strips; ++i) {
141 auto prev_size = data.size();
142 data.resize(prev_size + strip_sizes[i]);
143 TIFFReadRawStrip(tiff, i, data.data() + prev_size, strip_sizes[i]);
151:
ImageIO(fname, rw), decoder(dec)
190 TIFFSetDirectory(
tiff_file, image_index);
195 TIFFGetField(
tiff_file, TIFFTAG_IMAGEWIDTH, &nx);
196 TIFFGetField(
tiff_file, TIFFTAG_IMAGELENGTH, &ny);
205 dict[d.first] = d.second;
225 TIFFSetDirectory(
tiff_file, image_index);
230 for(
auto &c : coords)
virtual unsigned int x(unsigned int count, unsigned int sub_pix) const =0
virtual unsigned int num_pix() const =0
const unsigned int camera_size
virtual unsigned int y(unsigned int count, unsigned int sub_pix) const =0
Dict is a dictionary to store <string, EMObject> pair.
EMDataType
Image pixel data type used in EMAN.
bool is_single_image_format() const override
Is this image format only storing 1 image or not.
int get_nimg()
Return the number of images in this image file.
EerIO(const string &fname, IOMode rw_mode=READ_ONLY, Decoder &dec=decoder0x)
Dict acquisition_data_dict
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.
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.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Dict parse_acquisition_data(string metadata)
void TIFFOutputWarning(const char *module, const char *fmt, va_list ap)
string read_acquisition_metadata(TIFF *tiff)
string to_snake_case(const string &s)
vector< pair< int, int > > COORDS
auto read_raw_data(TIFF *tiff)
auto read_compression(TIFF *tiff)
auto decode_eer_data(EerWord *data, Decoder &decoder)
float & operator()(const int ix, const int iy, const int iz) const
Overload operator() for array indexing.