* mln/io/magick/load.hh: Revamp.
* mln/io/magick/save.hh: Fix a bug while saving. RGB values must
be between 0 and 1.
* tests/io/magick/save.cc: Remove useless output.
---
milena/ChangeLog | 11 +++++++++++
milena/mln/io/magick/load.hh | 32 ++++++++++++++++++++------------
milena/mln/io/magick/save.hh | 33 ++++++++++++++++++---------------
milena/tests/io/magick/save.cc | 9 ++++-----
4 files changed, 53 insertions(+), 32 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 62075e5..c7da59f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,14 @@
+2010-06-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Revamp and fix a bug in io::magick::*.
+
+ * mln/io/magick/load.hh: Revamp.
+
+ * mln/io/magick/save.hh: Fix a bug while saving. RGB values must
+ be between 0 and 1.
+
+ * tests/io/magick/save.cc: Remove useless output.
+
2010-06-25 Guillaume Lazzara <z(a)lrde.epita.fr>
Add new tests.
diff --git a/milena/mln/io/magick/load.hh b/milena/mln/io/magick/load.hh
index dfe9197..625134f 100644
--- a/milena/mln/io/magick/load.hh
+++ b/milena/mln/io/magick/load.hh
@@ -116,20 +116,22 @@ namespace mln
I& ima = exact(ima_);
- //std::ifstream file(filename.c_str());
- //if (! file)
- //{
- // std::cerr << "error: cannot open file '" << filename
<< "'!";
- // abort();
- //}
-
Magick::Image im_file;
im_file.ping(filename);
+// if (im_file)
+// {
+// std::cerr << "error: cannot open file '" << filename
<< "'!";
+// abort();
+// }
+
// Force a minimum resolution of 300DPI for PDF document.
if (im_file.magick() == "PDF"
- && (im_file.xResolution() < 300 || im_file.yResolution() < 300))
+ && (im_file.xResolution() < 300
+ || im_file.yResolution() < 300))
+ {
im_file.density(Magick::Geometry(300, 300));
+ }
im_file.read(filename);
@@ -144,7 +146,8 @@ namespace mln
std::cout << "format: " <<im_file.format() << std::endl;
std::cout << "magick: " <<im_file.magick() <<
std::endl;*/
- const Magick::PixelPacket *pixel_cache = im_file.getConstPixels(0, 0, columns, rows);
+ const Magick::PixelPacket *
+ pixel_cache = im_file.getConstPixels(0, 0, columns, rows);
algebra::vec<mln_site_(I)::dim, unsigned int> vmin;
algebra::vec<mln_site_(I)::dim, unsigned int> vmax;
@@ -159,10 +162,15 @@ namespace mln
mln_piter(I) p(ima.domain());
for_all(p)
{
- const Magick::PixelPacket *pixel = pixel_cache + (int) p.to_site().to_vec()[0] *
columns
- + (int) p.to_site().to_vec()[1];
+ const Magick::PixelPacket *
+ pixel = pixel_cache
+ + (int) p.to_site().to_vec()[0] * columns
+ + (int) p.to_site().to_vec()[1];
+
// FIXME: Quantum = 16bits but rgb is 8bits
- value::rgb8 pix(pixel->red % 256, pixel->green % 256, pixel->blue % 256);
+ value::rgb8 pix(pixel->red % 256,
+ pixel->green % 256,
+ pixel->blue % 256);
mln_value(I) res;
if (!do_it(pix, res, filename))
abort();
diff --git a/milena/mln/io/magick/save.hh b/milena/mln/io/magick/save.hh
index bd09224..72613c2 100644
--- a/milena/mln/io/magick/save.hh
+++ b/milena/mln/io/magick/save.hh
@@ -78,26 +78,29 @@ namespace mln
return Magick::ColorMono(value);
}
+ // Gray values must be between 0 and 1.
inline
Magick::Color get_color(const value::int_u8& value)
{
- return Magick::ColorGray(256 - value);
+ return Magick::ColorGray(value / 255.0f);
}
+ // Color values must be between 0 and 1.
inline
Magick::Color get_color(const value::rgb8& value)
{
- return Magick::ColorRGB(256 - value.red(),
- 256 - value.green(),
- 256 - value.blue());
+ return Magick::ColorRGB(value.red() / 255.0f,
+ value.green() / 255.0f,
+ value.blue() / 255.0f);
}
+ // Color values must be between 0 and 1.
inline
Magick::Color get_color(const value::qt::rgb32& value)
{
- return Magick::ColorRGB(256 - value.red(),
- 256 - value.green(),
- 256 - value.blue());
+ return Magick::ColorRGB(value.red() / 255.0f,
+ value.green() / 255.0f,
+ value.blue() / 255.0f);
}
template <typename I>
@@ -119,20 +122,20 @@ namespace mln
}
Magick::Image im_file;
- im_file.size(Magick::Geometry(ima.nrows(), ima.ncols()));
+ im_file.size(Magick::Geometry(ima.ncols(), ima.nrows()));
- Magick::PixelPacket* pixel_cache = im_file.getPixels(0, 0, ima.nrows(), ima.ncols());
- Magick::PixelPacket* pixel;
+ im_file.modifyImage();
+
+ Magick::PixelPacket *
+ pp = im_file.getPixels(0,0, ima.ncols(), ima.nrows());
mln_site(I) pmin = ima.domain().pmin();
mln_piter(I) p(ima.domain());
for_all(p)
- {
- pixel = pixel_cache + (int) (p.to_site().to_vec()[0] - pmin.to_vec()[0]) *
ima.ncols()
- + (int) (p.to_site().to_vec()[1] - pmin.to_vec()[1]);
- *pixel = get_color(ima(p));
- }
+ *pp++ = get_color(ima(p));
+
im_file.syncPixels();
+
im_file.write(filename);
trace::exiting("mln::io::magick::save");
diff --git a/milena/tests/io/magick/save.cc b/milena/tests/io/magick/save.cc
index 666e953..9af3e22 100644
--- a/milena/tests/io/magick/save.cc
+++ b/milena/tests/io/magick/save.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -27,12 +28,10 @@
#include <mln/io/magick/load.hh>
#include <mln/io/magick/save.hh>
#include <mln/io/ppm/load.hh>
-#include <mln/io/ppm/save.hh>
#include <mln/data/compare.hh>
#include "tests/data.hh"
#include <mln/io/magick/load.hh>
-
int main()
{
@@ -48,9 +47,9 @@ int main()
image2d<value::rgb8> lena_im;
io::magick::load(lena_im, "tiny.png");
- mln_assertion(lena_im(p) == c);
- io::ppm::save(lena_im, "tiny.ppm");
+
+ mln_assertion(lena_im(p) == c);
mln_assertion(lena_im.domain() == lena_mln.domain());
mln_assertion(lena_im == lena_mln);
--
1.5.6.5