26 #ifndef MLN_IO_DUMP_SAVE_HH
27 # define MLN_IO_DUMP_SAVE_HH
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/box_runstart_piter.hh>
40 # include <mln/core/pixel.hh>
41 # include <mln/data/memcpy_.hh>
42 # include <mln/trait/value_.hh>
60 void save(
const Image<I>& ima_,
const std::string& filename);
64 # ifndef MLN_INCLUDE_ONLY
72 void save_header(
const I& ima,
76 file <<
"milena/dump" << std::endl;
79 typedef mln_site(I) P;
80 file << P::dim << std::endl;
83 typedef algebra::vec<P::dim,
unsigned> vec_t;
84 vec_t size = ima.domain().pmax() - ima.domain().pmin();
85 for (
unsigned i = 0; i < P::dim - 1; ++i)
86 file << size[i] + 1 << " ";
87 file << size[P::dim - 1] + 1 << std::endl;
91 file << mln_trait_value_name(mln_value(I)) << std::endl;
100 mln_site(I) p = ima.domain().pmin();
101 file.write((
char*) (&p), sizeof (P));
104 p = ima.domain().pmax();
105 file.write((
char*) (&p), sizeof (P));
109 template <typename I>
111 void save_data(I& ima, std::ofstream& file)
114 unsigned data_size =
sizeof (mln_value(I)) +
sizeof (mln_value(I)) % 2;
116 mln_box_runstart_piter(I) p(ima.domain());
119 pixel<I> src(ima, p);
120 file.write((
char*) (&src.val()), p.run_length() * data_size);
130 template <
typename I>
133 trace::entering(
"mln::io::dump::save");
135 const I& ima = exact(ima_);
137 std::ofstream file(filename.c_str());
140 std::cerr <<
"error: cannot open file '" << filename <<
"'!";
144 internal::save_header(ima, file);
145 internal::save_data(ima, file);
150 trace::exiting(
"mln::io::dump::save");
154 # endif // ! MLN_INCLUDE_ONLY
162 #endif // ! MLN_IO_DUMP_SAVE_HH