26 #ifndef MLN_IO_PBM_LOAD_HH
27 # define MLN_IO_PBM_LOAD_HH
39 # include <mln/core/image/image2d.hh>
40 # include <mln/core/image/image3d.hh>
41 # include <mln/io/pnm/load_header.hh>
60 void load(image2d<bool>& ima,
61 const std::string& filename);
69 image2d<bool>
load(
const std::string& filename);
72 # ifndef MLN_INCLUDE_ONLY
80 void load_ascii(std::ifstream& file, I& ima)
82 mln_fwd_piter(I) p(ima.domain());
88 mln_assertion(value ==
'0' || value ==
'1');
89 ima(p) = (value ==
'0');
97 void load_raw_2d(std::ifstream& file, I& ima)
100 typedef mln_value(I) V;
101 const mln_deduce(I, site, coord)
102 min_row = geom::min_row(ima),
103 max_row = geom::max_row(ima),
104 min_col = geom::min_col(ima),
105 max_col = geom::max_col(ima);
109 for (p.row() = min_row; p.row() <= max_row; ++p.row())
115 file.read((
char*)(&c), 1);
117 c =
static_cast<char>(c * 2);
130 trace::entering(
"mln::io::pbm::load");
131 std::ifstream file(filename.c_str());
134 std::cerr <<
"error: file '" << filename
140 io::pnm::read_header(
'1',
'4', file, type, nrows, ncols);
144 internal::load_raw_2d(file, ima);
147 internal::load_ascii(file, ima);
149 trace::exiting(
"mln::io::pbm::load");
157 const std::string& filename)
159 ima =
load(filename);
163 # endif // ! MLN_INCLUDE_ONLY
172 #endif // ! MLN_IO_PBM_LOAD_HH