26 #ifndef MLN_IO_PFM_LOAD_HH
27 # define MLN_IO_PFM_LOAD_HH
37 # include <mln/core/image/image2d.hh>
38 # include <mln/value/int_u8.hh>
56 void load(image2d<float>& ima,
57 const std::string& filename);
65 image2d<float>
load(
const std::string& filename);
67 # ifndef MLN_INCLUDE_ONLY
75 std::cerr <<
" aborting." << std::endl;
80 bool read_pfm_header(std::istream& file,
81 int& nrows,
int& ncols,
90 if (file.get() !=
'\n')
98 if (file.get() !=
'\n')
106 std::cerr <<
"error: badly formed header!"
115 template <
typename I>
117 void load_raw_2d(std::ifstream& file, I& ima)
121 const mln_deduce(I, site, coord)
122 min_row = geom::min_row(ima),
123 max_row = geom::max_row(ima);
126 ncols = geom::ncols(ima);
128 for (p.row() = min_row; p.row() <= max_row; ++p.row())
129 file.read((
char*)(&(ima(p))),
130 sizeof(
float) * ncols);
140 trace::entering(
"mln::io::pfm::load");
142 std::ifstream file(filename.c_str());
145 std::cerr <<
"error: file '" << filename
150 internal::read_pfm_header(file, nrows, ncols);
153 internal::load_raw_2d(file, ima);
155 trace::exiting(
"mln::io::pfm::load");
163 const std::string& filename)
165 ima =
load(filename);
168 # endif // ! MLN_INCLUDE_ONLY
177 #endif // ! MLN_IO_PFM_LOAD_HH