URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-15 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix a bug in io::pbm::save.
* mln/io/pbm/save.hh: Fix a shift of 1 pixel in the image
saved.
* tests/io_pbm.cc: Update the test to ouput more pbm images.
---
mln/io/pbm/save.hh | 13 +++++++++----
tests/io_pbm.cc | 18 +++++++++++-------
2 files changed, 20 insertions(+), 11 deletions(-)
Index: trunk/milena/tests/io_pbm.cc
===================================================================
--- trunk/milena/tests/io_pbm.cc (revision 1481)
+++ trunk/milena/tests/io_pbm.cc (revision 1482)
@@ -42,6 +42,9 @@
#include <mln/level/compare.hh>
#include <mln/level/fill.hh>
+#include <mln/display/show.hh>
+#include <mln/display/save.hh>
+
#include <mln/border/thickness.hh>
int main()
@@ -49,27 +52,28 @@
using namespace mln;
using typename value::int_u8;
+ typedef image2d< bool > I;
+
border::thickness = 0;
image2d< int_u8 >
lena = io::pgm::load("../img/lena.pgm");
- image2d< bool > out(lena.domain());
+ I out(lena.domain());
level::fill(out, pw::value(lena) > pw::cst(127));
io::pbm::save(out, "out.pbm");
{
- image2d< bool >
- lena = io::pbm::load("out.pbm");
+ I lena = io::pbm::load("out.pbm");
image2d<bool> out(lena.domain());
- io::pbm::save(lena, "out.pbm");
+ io::pbm::save(lena, "out2.pbm");
- image2d< bool >
- lena2 = io::pbm::load("out.pbm");
+ I lena2 = io::pbm::load("out2.pbm");
- io::pbm::save(lena2, "out2.pbm");
+ io::pbm::save(lena2, "out3.pbm");
+ mln_assertion(lena.domain() == lena2.domain());
mln_assertion(lena == lena2);
}
}
Index: trunk/milena/mln/io/pbm/save.hh
===================================================================
--- trunk/milena/mln/io/pbm/save.hh (revision 1481)
+++ trunk/milena/mln/io/pbm/save.hh (revision 1482)
@@ -89,15 +89,20 @@
unsigned char c = 0;
int i = 0;
- for (p.row() = min_row; p.row() <= max_row; ++p.row())
- for (p.col() = min_col; p.col() <= max_col; ++p.col())
+
+ mln_piter(I) it(ima.domain());
+ for_all(it)
+ {
+ if (i && (i == 8))
{
- c += ima(p);
- if (i && (i % 8 == 0))
file.write((char*)(&c), 1);
+ i = 0;
+ }
c = c * 2;
+ c += ima(it);
++i;
}
+ file.write((char*)(&c), 1);
}
} // end of namespace mln::io::impl