27 #ifndef MLN_IO_DUMP_SAVE_HH
28 # define MLN_IO_DUMP_SAVE_HH
39 # include <mln/core/concept/image.hh>
40 # include <mln/core/box_runstart_piter.hh>
41 # include <mln/core/pixel.hh>
42 # include <mln/data/memcpy_.hh>
43 # include <mln/trait/value_.hh>
63 void save(
const Image<I>& ima_,
const std::string&
filename);
67 # ifndef MLN_INCLUDE_ONLY
75 void save_header(
const I& ima,
79 file <<
"milena/dump" << std::endl;
82 typedef mln_site(I) P;
83 file << P::dim << std::endl;
86 typedef algebra::vec<P::dim,
unsigned> vec_t;
87 vec_t size = ima.domain().pmax() - ima.domain().pmin();
88 for (
unsigned i = 0; i < P::dim - 1; ++i)
89 file << size[i] + 1 << " ";
90 file << size[P::dim - 1] + 1 << std::endl;
94 file << mln_trait_value_name(mln_value(I)) << std::endl;
103 mln_site(I)
p = ima.domain().pmin();
104 file.write((
char*) (&
p), sizeof (P));
107 p = ima.domain().pmax();
108 file.write((
char*) (&p), sizeof (P));
112 template <typename I>
114 void save_data(I& ima, std::ofstream& file)
117 unsigned data_size =
sizeof (mln_value(I)) +
sizeof (mln_value(I)) % 2;
119 mln_box_runstart_piter(I) p(ima.domain());
122 pixel<I> src(ima, p);
123 file.write((
char*) (&src.val()), p.run_length() * data_size);
133 template <
typename I>
134 void save(
const Image<I>& ima_,
const std::string&
filename)
136 mln_trace(
"mln::io::dump::save");
138 const I& ima =
exact(ima_);
140 std::ofstream file(filename.c_str());
143 std::cerr <<
"error: cannot open file '" << filename <<
"'!";
147 internal::save_header(ima, file);
148 internal::save_data(ima, file);
156 # endif // ! MLN_INCLUDE_ONLY
164 #endif // ! MLN_IO_DUMP_SAVE_HH