Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/io/tests/2d: Add tests.
* tests/io/loadsave.hh: Adapt to new iterators API.
* oln/core/2d/image2d.hh: Restore I/O operator=.
* oln/core/gen/regular_window.hh: Add missing `this->'.
* oln/io/write_image_pnm.hh: New. Add a generic front end for pnm files
writing.
* oln/io/read_image_pnm.hh: New. Add a generic front end for pnm files
reading.
* oln/io/write_image_2d_pnm.hh: Remove.
* oln/io/gz_stream.hh: Restore file.
* oln/io/write_image_pnm_2d.hh: New. Add 2D implementations for pnm
output.
* oln/io/read_image_2d_pnm.hh: Remove.
* oln/io/write_image.hh: Adapt to changes that occured in the pnm front
end.
* oln/io/read_image_pnm_2d.hh: New. Add 2D implementations for pnm
input.
* oln/io/read_image.hh: Adapt to changes that occured in the pnm front
end.
* oln/io/write_image_pnm_decl.hh: New. Forward declarations.
* oln/io/read_image_pnm_decl.hh: New. Forward declarations.
* oln/io/utils.hh: Restore file.
* oln/canvas/reconstruction.hh: Add use of oln::box.
* oln/canvas/io.hh: Add canvas for 1D and 2D images.
oln/canvas/io.hh | 116 ++++++
oln/canvas/reconstruction.hh | 8
oln/core/2d/image2d.hh | 6
oln/core/gen/regular_window.hh | 2
oln/io/gz_stream.hh | 728 ++++++++++++++++++++---------------------
oln/io/read_image.hh | 139 +++----
oln/io/read_image_2d_pnm.hh | 187 ----------
oln/io/read_image_pnm.hh | 157 ++++++++
oln/io/read_image_pnm_2d.hh | 166 +++++++++
oln/io/read_image_pnm_decl.hh | 57 +++
oln/io/utils.hh | 233 ++++++-------
oln/io/write_image.hh | 126 +++----
oln/io/write_image_2d_pnm.hh | 225 ------------
oln/io/write_image_pnm.hh | 173 +++++++++
oln/io/write_image_pnm_2d.hh | 153 ++++++++
oln/io/write_image_pnm_decl.hh | 57 +++
tests/io/loadsave.hh | 10
tests/io/tests/2d | 12
18 files changed, 1492 insertions(+), 1063 deletions(-)
Index: tests/io/tests/2d
--- tests/io/tests/2d (revision 188)
+++ tests/io/tests/2d (working copy)
@@ -37,15 +37,27 @@
typedef oln::image2d<ntg::int_u8> ima_int_u8;
typedef oln::image2d<ntg::rgb_8> ima_rgb_8;
typedef oln::image2d<ntg::bin> ima_bin;
+ typedef oln::image2d<ntg::int_s8> ima_int_s8;
+ typedef oln::image2d<bool> ima_bool;
+ typedef oln::image2d<unsigned char> ima_uchar;
+ typedef oln::image2d<signed char> ima_schar;
fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm"),
"16x16.pgm");
fail |= loadsave< ima_bin >(rdata("16x16.pbm"),
"16x16.pbm");
fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm"),
"16x16.ppm");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm"),
"16x16.pgm");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm"),
"16x16.pbm");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm"),
"16x16.pgm");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm"),
"16x16.pgm");
#if HAVE_ZLIB
fail |= loadsave< ima_bin >(rdata("16x16.pbm.gz"),
"16x16.pbm.gz");
fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm.gz"),
"16x16.pgm.gz");
fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm.gz"),
"16x16.ppm.gz");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm.gz"),
"16x16.pgm.gz");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm.gz"),
"16x16.pbm.gz");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm.gz"),
"16x16.pgm.gz");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm.gz"),
"16x16.pgm.gz");
#endif
return fail;
Index: tests/io/loadsave.hh
--- tests/io/loadsave.hh (revision 188)
+++ tests/io/loadsave.hh (working copy)
@@ -1,8 +1,8 @@
-#include <oln/basics1d.hh>
-#include <oln/basics2d.hh>
-#include <oln/basics3d.hh>
-#include <oln/all.hh>
+#include <oln/io/write_image.hh>
+#include <oln/io/read_image.hh>
+#include <oln/core/abstract/piter.hh>
+
#include <ntg/all.hh>
#include "check.hh"
@@ -20,7 +20,7 @@
a.size().ncols() != b.size().ncols())
return false;
- for_all(it)
+ for_all_p(it)
{
if (a[it] != b[it])
return false;
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 188)
+++ oln/core/2d/image2d.hh (working copy)
@@ -190,9 +190,9 @@
image2d& operator=(const io::filename& rhs)
{
// FIXME HERE: hack to avoid calling io
-// io::do_read(*this, rhs);
- image2d tmp(4, 4);
- *this = tmp;
+ io::do_read(*this, rhs);
+// image2d tmp(4, 4);
+// *this = tmp;
return *this;
}
Index: oln/core/gen/regular_window.hh
--- oln/core/gen/regular_window.hh (revision 188)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -198,7 +198,7 @@
for (unsigned i = 0; i < card(); ++i)
{
- const dpoint_type& dp = win.get_dp()[i];
+ const dpoint_type& dp = this->win.get_dp()[i];
unsigned n;
for (n = 0; n < dim; ++n)
Index: oln/io/write_image_pnm.hh
--- oln/io/write_image_pnm.hh (revision 0)
+++ oln/io/write_image_pnm.hh (revision 0)
@@ -0,0 +1,173 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_WRITE_IMAGE_PNM_HH
+# define OLN_IO_WRITE_IMAGE_PNM_HH
+
+# include <oln/io/write_image_pnm_decl.hh>
+# include <oln/io/write_image_pnm_2d.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::real_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& istr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (ext == "pgm")
+ {
+ write_pnm_real<I, size_type> tmp(ima, istr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::enum_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (ext == "pbm")
+ {
+ write_pnm_bin<I, size_type> tmp(ima, ostr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::vect_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+ precondition(ntg_nb_comp(V) == 3);
+
+ if (ext == "ppm")
+ {
+ write_pnm_vect<I, size_type> tmp(ima, ostr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm(const ntg::value<V>& v,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ write_pnm_(v.exact(), ima.exact(), ostr, ext);
+ }
+
+ }
+
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::enum_value<V>&)
+ {
+ return "P4";
+ }
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::real_value<V>&)
+ {
+ return "P5";
+ }
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::vect_value<V>&)
+ {
+ return "P6";
+ }
+
+ template <typename V>
+ int get_max_val(const ntg::value<V>&)
+ {
+ return ntg_max_val(V) - ntg_min_val(V);
+ }
+
+ template <typename V>
+ int get_max_val(const ntg::vect_value<V>&)
+ {
+ return ntg_max_val(ntg_comp_type(V)) - ntg_min_val(ntg_comp_type(V));
+ }
+
+
+ template <typename I>
+ void write_pnm(const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ int max_val = get_max_val(ntg_value_type());
+
+ if (max_val <= 65535)
+ {
+ internal::write_pnm_header(ostr, get_pnm_type(ntg_value_type()),
+ ima.exact().size().ncols(),
+ ima.exact().size().nrows(),
+ max_val);
+
+ impl::write_pnm(ntg_value_type(), ima.exact(), ostr, ext);
+ }
+ else
+ std::cerr << "io error: data type too large" << std::endl;
+
+
+ }
+
+
+ }
+
+
+}
+
+
+
+# endif // ! OLN_IO_WRITE_IMAGE_PNM_HH
Index: oln/io/read_image_pnm.hh
--- oln/io/read_image_pnm.hh (revision 0)
+++ oln/io/read_image_pnm.hh (revision 0)
@@ -0,0 +1,157 @@
+ // Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_READ_IMAGE_PNM_HH
+# define OLN_IO_READ_IMAGE_PNM_HH
+
+# include <iostream>
+# include <string>
+
+# include <oln/io/read_image_pnm_decl.hh>
+# include <oln/io/read_image_pnm_2d.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/io/utils.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::real_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P5")
+ {
+ read_pnm_real<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::enum_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P4")
+ {
+ read_pnm_bin<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::vect_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P6")
+ {
+ read_pnm_vect<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" <<
std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm(const ntg::value<V>& v,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ read_pnm_(v.exact(), ima.exact(), istr, hdr);
+ }
+
+ }
+
+
+ void check_hdr_ext(const internal::pnm_header& hdr,
+ const std::string& ext)
+ {
+ if ((ext == "pbm" && hdr.type != "P4") ||
+ (ext == "pgm" && hdr.type != "P5") ||
+ (ext == "ppm" && hdr.type != "P6"))
+ std::cerr << "io warning: extension mismatch pnm type." <<
std::cerr;
+ }
+
+
+
+ template <typename I>
+ void read_pnm(abstract::image<I>& ima,
+ std::istream& istr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ internal::pnm_header hdr;
+
+ if (!internal::read_pnm_header(istr, hdr))
+ {
+ std::cerr << "io error: invalid pnm header." << std::cerr;
+ return;
+ }
+
+ if (hdr.type == "P1" || hdr.type == "P2" || hdr.type ==
"P3")
+ std::cerr << "io error: ascii pnm format not supported." <<
std::endl;
+
+ check_hdr_ext(hdr, ext);
+
+ impl::read_pnm(ntg_value_type(), ima, istr, hdr);
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_HH
Index: oln/io/write_image_2d_pnm.hh
--- oln/io/write_image_2d_pnm.hh (revision 188)
+++ oln/io/write_image_2d_pnm.hh (working copy)
@@ -1,225 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLN_IO_WRITE_IMAGE_2D_PNM_HH
-# define OLN_IO_WRITE_IMAGE_2D_PNM_HH
-
-// # include <iostream>
-// # include <string>
-
-// # include <mlc/box.hh>
-
-// # include <ntg/all.hh>
-
-// # include <oln/core/2d/image2d.hh>
-
-// // commented cause 'void_op' was removed
-// //# include <oln/core/abstract/op.hh>
-
-// # include <oln/io/utils.hh>
-
-// namespace oln {
-
-// namespace io {
-
-// namespace impl {
-
-// template <typename I>
-// struct write_image_2d_raw
-// // commented below cause 'void_op' was removed
-// // : public oln::abstract::void_op<write_image_2d_raw<I> >
-// {
-// typedef oln_type_of(I, value) value_type;
-
-// const I& to_write_;
-// std::ostream& ostr_;
-// int bin_offset;
-// char bin_v;
-
-
-// write_image_2d_raw(const I& to_write, std::ostream& ostr):
-// to_write_(to_write),
-// ostr_(ostr)
-// {
-// bin_offset = 7;
-// bin_v = 0;
-// }
-
-// void run()
-// {
-// point2d p;
-// value_type c;
-
-// for (p.row() = 0; p.row() < to_write_.size().nrows(); ++p.row())
-// {
-// for (p.col() = 0; p.col() < to_write_.size().ncols(); ++p.col())
-// // FIXME: SHOULD NOT BE .value() !!!
-// write_value_type(to_write_[p].value());
-// write_padding(c);
-// }
-// }
-
-// template <typename E>
-// void write_padding(const ntg::value<E>&) {}
-
-// void write_padding(const ntg::bin&)
-// {
-// if (bin_offset != 7)
-// {
-// ostr_.write(&bin_v, 1);
-// bin_offset = 7;
-// bin_v = 0;
-// }
-// }
-
-// //FIXME: Should work with builtin types.
-
-// template <typename E>
-// void write_value_type(const ntg::real_value<E> &c)
-// {
-// typedef oln_io_type(ntg_nbits(E)) v_type;
-
-// v_type v;
-// v = ntg::cast::bound<E, v_type>(c.exact());
-// ostr_.write((char*)&v, sizeof (v_type));
-// }
-
-// template <typename E>
-// void write_value_type(const ntg::vect_value<E> &c)
-// {
-// for (unsigned i = 0; i < 3; i++)
-// {
-// typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
-
-// v_type v;
-// v = c[i];
-// ostr_.write((char*)&v, sizeof (v_type));
-// }
-// }
-
-// void write_value_type(const ntg::bin &c)
-// {
-// if (bin_offset == -1)
-// {
-// ostr_.write(&bin_v, 1);
-// bin_offset = 7;
-// bin_v = 0;
-// }
-// if (c == value_type(1))
-// bin_v |= 1 << bin_offset;
-// bin_offset--;
-// }
-// };
-
-
-// template <typename I, typename T>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::real_value<T>&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-
-// point2d p;
-// size2d s = to_write.size();
-
-// precondition(ntg_nbits(T) <= 16);
-// if (ext == "pgm")
-// if (internal::write_pnm_header(ostr, "P5",
-// s.ncols(), s.nrows(),
-// ntg_max_val(T)))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write file header" <<
std::endl;
-// else
-// std::cerr << "error: image data type (`integer') does not
match"
-// << " file extension (`" << ext << "')"
<< std::endl;
-// }
-
-// template <typename I, typename T>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::color_value<T>&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-
-// point2d p;
-// size2d s = to_write.size();
-
-// precondition(ntg_nbits(ntg_comp_type(T)) <= 16);
-// precondition(ntg_nb_comp(T) == 3);
-// if (ext == "ppm")
-// if (internal::write_pnm_header(ostr, "P6",
-// s.ncols(), s.nrows(),
-// ntg_max_val(ntg_comp_type(T))))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write header" << std::endl;
-// else
-// std::cerr << "error: image data type (`color') does not match"
-// << " file extension (`" << ext << "')"
<< std::endl;
-// }
-
-// template <typename I>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::bin&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-// point2d p;
-// size2d s = to_write.size();
-
-// if (ext == "pbm")
-// if (internal::write_pnm_header(ostr, "P4",
-// s.ncols(), s.nrows(),
-// 1))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write header" << std::endl;
-// else
-// std::cerr << "error: image data type (`enum_value') does not
match"
-// << " file extension (`" << ext << "')"
<< std::endl;
-// }
-
-// }
-
-// }
-
-// }
-
-
-
-#endif // ! OLN_IO_WRITE_IMAGE_2D_PNM_HH
Index: oln/io/gz_stream.hh
--- oln/io/gz_stream.hh (revision 188)
+++ oln/io/gz_stream.hh (working copy)
@@ -28,455 +28,455 @@
#ifndef OLN_IO_GZ_STREAM_HH
# define OLN_IO_GZ_STREAM_HH
-// # include <oln/config/system.hh>
+# include <oln/config/system.hh>
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// # include <cassert>
-// # include <fstream>
-// # include <string>
-// # include <zlib.h>
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+# include <cassert>
+# include <fstream>
+# include <string>
+# include <zlib.h>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// /// Functions for gz files
-// namespace gz {
+ /// Functions for gz files
+ namespace gz {
-// ///Performs operation on compressed files.
-// class zfilebuf : public std::streambuf
-// {
-// public:
+ ///Performs operation on compressed files.
+ class zfilebuf : public std::streambuf
+ {
+ public:
-// zfilebuf() : file(0), mode(0), own_file_descriptor(0)
-// {
-// inbuf = new char[lenbuf];
-// outbuf = new char[lenbuf];
-// setg(0, 0, 0);
-// setp(outbuf, outbuf + lenbuf);
-// }
+ zfilebuf() : file(0), mode(0), own_file_descriptor(0)
+ {
+ inbuf = new char[lenbuf];
+ outbuf = new char[lenbuf];
+ setg(0, 0, 0);
+ setp(outbuf, outbuf + lenbuf);
+ }
-// virtual ~zfilebuf()
-// {
-// sync();
-// delete[] inbuf;
-// delete[] outbuf;
-// if (own_file_descriptor)
-// close();
-// }
+ virtual ~zfilebuf()
+ {
+ sync();
+ delete[] inbuf;
+ delete[] outbuf;
+ if (own_file_descriptor)
+ close();
+ }
-// /*! \brief Return a stream on the file \a name regarding
-// ** the opening mode: \a io_mode.
-// */
-// zfilebuf*
-// open(const char *name, int io_mode)
-// {
-// if (is_open())
-// return 0;
+ /*! \brief Return a stream on the file \a name regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ open(const char *name, int io_mode)
+ {
+ if (is_open())
+ return 0;
-// char char_mode[10];
-// char *p;
-// memset(char_mode,'\0',10);
-// p = char_mode;
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
-// if (io_mode & std::ios::in)
-// {
-// mode = std::ios::in;
-// *p++ = 'r';
-// }
-// else
-// if (io_mode & std::ios::app)
-// {
-// mode = std::ios::app;
-// *p++ = 'a';
-// }
-// else
-// {
-// mode = std::ios::out;
-// *p++ = 'w';
-// }
-// if (io_mode & std::ios::binary)
-// {
-// mode |= std::ios::binary;
-// *p++ = 'b';
-// }
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
-// // Hard code the compression level
-// if (io_mode & (std::ios::out|std::ios::app))
-// *p++ = '9';
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
-// if ((file = gzopen(name, char_mode)) == 0)
-// return 0;
+ if ((file = gzopen(name, char_mode)) == 0)
+ return 0;
-// name_ = name;
-// own_file_descriptor = 1;
-// return this;
-// }
+ name_ = name;
+ own_file_descriptor = 1;
+ return this;
+ }
-// /*! \brief Attach a stream on \a file_descriptor regarding
-// ** the opening mode: \a io_mode.
-// */
-// zfilebuf*
-// attach(int file_descriptor, int io_mode)
-// {
-// if (is_open())
-// return 0;
+ /*! \brief Attach a stream on \a file_descriptor regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ attach(int file_descriptor, int io_mode)
+ {
+ if (is_open())
+ return 0;
-// char char_mode[10];
-// char *p;
-// memset(char_mode,'\0',10);
-// p = char_mode;
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
-// if (io_mode & std::ios::in)
-// {
-// mode = std::ios::in;
-// *p++ = 'r';
-// }
-// else
-// if (io_mode & std::ios::app)
-// {
-// mode = std::ios::app;
-// *p++ = 'a';
-// }
-// else
-// {
-// mode = std::ios::out;
-// *p++ = 'w';
-// }
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
-// if (io_mode & std::ios::binary)
-// {
-// mode |= std::ios::binary;
-// *p++ = 'b';
-// }
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
-// // Hard code the compression level
-// if (io_mode & (std::ios::out|std::ios::app))
-// *p++ = '9';
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
-// if ((file = gzdopen(file_descriptor, char_mode)) == 0)
-// return 0;
+ if ((file = gzdopen(file_descriptor, char_mode)) == 0)
+ return 0;
-// own_file_descriptor = 0;
-// return this;
-// }
+ own_file_descriptor = 0;
+ return this;
+ }
-// /// Close the stream.
-// zfilebuf*
-// close()
-// {
-// if (is_open())
-// {
-// sync();
-// gzclose(file);
-// file = 0;
-// }
-// return this;
-// }
+ /// Close the stream.
+ zfilebuf*
+ close()
+ {
+ if (is_open())
+ {
+ sync();
+ gzclose(file);
+ file = 0;
+ }
+ return this;
+ }
-// int
-// setcompressionlevel(short comp_level)
-// {
-// return gzsetparams(file, comp_level, -2);
-// }
+ int
+ setcompressionlevel(short comp_level)
+ {
+ return gzsetparams(file, comp_level, -2);
+ }
-// int
-// setcompressionstrategy(short comp_strategy)
-// {
-// return gzsetparams(file, -2, comp_strategy);
-// }
+ int
+ setcompressionstrategy(short comp_strategy)
+ {
+ return gzsetparams(file, -2, comp_strategy);
+ }
-// /// Return true if the stream is open, false otherwise.
-// inline int
-// is_open() const
-// { return (file != 0); }
+ /// Return true if the stream is open, false otherwise.
+ inline int
+ is_open() const
+ { return (file != 0); }
-// virtual std::streampos
-// seekoff(std::streamoff off, std::ios::seekdir dir, int) // which)
-// {
-// return std::streampos(gzseek(file, off, dir));
-// }
+ virtual std::streampos
+ seekoff(std::streamoff off, std::ios::seekdir dir, int) // which)
+ {
+ return std::streampos(gzseek(file, off, dir));
+ }
-// /// Flush the buffer associated to the stream.
-// virtual int
-// sync()
-// {
-// if (!is_open())
-// return EOF;
-// return flushbuf();
-// }
+ /// Flush the buffer associated to the stream.
+ virtual int
+ sync()
+ {
+ if (!is_open())
+ return EOF;
+ return flushbuf();
+ }
-// protected:
+ protected:
-// /*! \brief Return the next character in the stream.
-// ** On failure, \a EOF is returned.
-// */
-// virtual int
-// underflow()
-// {
-// // If the file hasn't been opened for reading, error.
-// if (!is_open() || !(mode & std::ios::in))
-// return EOF;
+ /*! \brief Return the next character in the stream.
+ ** On failure, \a EOF is returned.
+ */
+ virtual int
+ underflow()
+ {
+ // If the file hasn't been opened for reading, error.
+ if (!is_open() || !(mode & std::ios::in))
+ return EOF;
-// if (in_avail())
-// return (unsigned char) *gptr();
+ if (in_avail())
+ return (unsigned char) *gptr();
-// if (flushbuf() == EOF)
-// return EOF;
+ if (flushbuf() == EOF)
+ return EOF;
-// // Attempt to fill the buffer.
-// if (fillbuf() == EOF)
-// return EOF;
+ // Attempt to fill the buffer.
+ if (fillbuf() == EOF)
+ return EOF;
-// assert (eback());
+ assert (eback());
-// return (unsigned char) *gptr();
-// }
+ return (unsigned char) *gptr();
+ }
-// /*! \brief Flush the output buffer associated to the stream
-// ** then write \a c. On failure, \a EOF is returned.
-// */
+ /*! \brief Flush the output buffer associated to the stream
+ ** then write \a c. On failure, \a EOF is returned.
+ */
-// virtual int
-// overflow(int c = EOF)
-// {
-// if (!is_open() || !(mode & std::ios::out))
-// return EOF;
+ virtual int
+ overflow(int c = EOF)
+ {
+ if (!is_open() || !(mode & std::ios::out))
+ return EOF;
-// assert (pbase());
+ assert (pbase());
-// if (flushbuf() == EOF)
-// return EOF;
+ if (flushbuf() == EOF)
+ return EOF;
-// if (c != EOF)
-// {
-// *pptr() = c;
-// pbump(1);
-// }
-// return 0;
-// }
+ if (c != EOF)
+ {
+ *pptr() = c;
+ pbump(1);
+ }
+ return 0;
+ }
-// private:
+ private:
-// gzFile file;
-// short mode;
-// short own_file_descriptor;
-// std::string name_;
-// char *inbuf;
-// char *outbuf;
-// static const int lenbuf = 16 * 1024;
+ gzFile file;
+ short mode;
+ short own_file_descriptor;
+ std::string name_;
+ char *inbuf;
+ char *outbuf;
+ static const int lenbuf = 16 * 1024;
-// /// Flush the output buffer
-// int
-// flushbuf()
-// {
-// int n = pptr() - outbuf;
+ /// Flush the output buffer
+ int
+ flushbuf()
+ {
+ int n = pptr() - outbuf;
-// if (n == 0)
-// return 0;
+ if (n == 0)
+ return 0;
-// if (gzwrite(file, outbuf, n) < n)
-// return EOF;
+ if (gzwrite(file, outbuf, n) < n)
+ return EOF;
-// setp(outbuf, outbuf + lenbuf);
-// return 0;
-// }
-// /// Fill the input buffer.
-// int
-// fillbuf()
-// {
-// int t = gzread(file, inbuf, lenbuf);
-// if (t <= 0) return EOF;
-// setg(inbuf, inbuf, inbuf + t);
-// return t;
-// }
+ setp(outbuf, outbuf + lenbuf);
+ return 0;
+ }
+ /// Fill the input buffer.
+ int
+ fillbuf()
+ {
+ int t = gzread(file, inbuf, lenbuf);
+ if (t <= 0) return EOF;
+ setg(inbuf, inbuf, inbuf + t);
+ return t;
+ }
-// };
+ };
-// ///Define an interface for compressed file stream manipulation.
-// class zfilestream_common : virtual public std::ios
-// {
-// friend class zifstream;
-// friend class zofstream;
-// friend zofstream &setcompressionlevel(zofstream &, int);
-// friend zofstream &setcompressionstrategy(zofstream &, int);
+ ///Define an interface for compressed file stream manipulation.
+ class zfilestream_common : virtual public std::ios
+ {
+ friend class zifstream;
+ friend class zofstream;
+ friend zofstream &setcompressionlevel(zofstream &, int);
+ friend zofstream &setcompressionstrategy(zofstream &, int);
-// public:
-// virtual ~zfilestream_common() {}
+ public:
+ virtual ~zfilestream_common() {}
-// /*! \brief Open the stream on the file descriptor:
-// ** \a fd regarding the opening mode.
-// */
-// void
-// attach(int fd, int io_mode)
-// {
-// if (!buffer.attach(fd, io_mode))
-// clear(std::ios::failbit | std::ios::badbit);
-// else
-// clear();
-// }
+ /*! \brief Open the stream on the file descriptor:
+ ** \a fd regarding the opening mode.
+ */
+ void
+ attach(int fd, int io_mode)
+ {
+ if (!buffer.attach(fd, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
-// /*! \brief Open the stream on the file named \a name
-// ** regarding the opening mode.
-// */
-// void
-// open(const char *name, int io_mode)
-// {
-// if (!buffer.open(name, io_mode))
-// clear(std::ios::failbit | std::ios::badbit);
-// else
-// clear();
-// }
+ /*! \brief Open the stream on the file named \a name
+ ** regarding the opening mode.
+ */
+ void
+ open(const char *name, int io_mode)
+ {
+ if (!buffer.open(name, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
-// /// Close the current stream.
-// void
-// close()
-// {
-// if (!buffer.close())
-// clear(std::ios::failbit | std::ios::badbit);
-// }
+ /// Close the current stream.
+ void
+ close()
+ {
+ if (!buffer.close())
+ clear(std::ios::failbit | std::ios::badbit);
+ }
-// bool
-// is_open()
-// {
-// return buffer.is_open();
-// }
+ bool
+ is_open()
+ {
+ return buffer.is_open();
+ }
-// protected:
-// /// Prevent instantiation.
-// zfilestream_common() : std::ios(zfilestream_common::rdbuf())
-// { }
+ protected:
+ /// Prevent instantiation.
+ zfilestream_common() : std::ios(zfilestream_common::rdbuf())
+ { }
-// private:
-// zfilebuf*
-// rdbuf()
-// {
-// return &buffer;
-// }
+ private:
+ zfilebuf*
+ rdbuf()
+ {
+ return &buffer;
+ }
-// zfilebuf buffer;
-// };
+ zfilebuf buffer;
+ };
-// /// Read only zstream.
-// class zifstream : public zfilestream_common, public std::istream
-// {
-// public:
+ /// Read only zstream.
+ class zifstream : public zfilestream_common, public std::istream
+ {
+ public:
-// zifstream() : std::istream(zfilestream_common::rdbuf())
-// {
-// clear(std::ios::badbit);
-// }
+ zifstream() : std::istream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
-// /// Open a read only stream on the file named \a name.
-// zifstream(const char *name, int io_mode = std::ios::in) :
-// std::istream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::open(name, io_mode);
-// }
+ /// Open a read only stream on the file named \a name.
+ zifstream(const char *name, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
-// /// Open a read only stream on the file descriptor \a fd.
-// zifstream(int fd, int io_mode = std::ios::in) :
-// std::istream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::attach(fd, io_mode);
-// }
+ /// Open a read only stream on the file descriptor \a fd.
+ zifstream(int fd, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
-// virtual ~zifstream() {}
-// };
+ virtual ~zifstream() {}
+ };
-// class zofstream : public zfilestream_common, public std::ostream {
+ class zofstream : public zfilestream_common, public std::ostream {
-// public:
+ public:
-// zofstream() : std::ostream(zfilestream_common::rdbuf())
-// {
-// clear(std::ios::badbit);
-// }
+ zofstream() : std::ostream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
-// /// Open a write only stream on the file named \a name.
-// zofstream(const char *name, int io_mode = std::ios::out) :
-// std::ostream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::open(name, io_mode);
-// }
+ /// Open a write only stream on the file named \a name.
+ zofstream(const char *name, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
-// /// Open a write only stream on the file descriptor \a fd.
-// zofstream(int fd, int io_mode = std::ios::out) :
-// std::ostream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::attach(fd, io_mode);
-// }
+ /// Open a write only stream on the file descriptor \a fd.
+ zofstream(int fd, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
-// virtual ~zofstream() {}
+ virtual ~zofstream() {}
-// };
+ };
-// // Forward declaration.
-// template <class T>
-// class zomanip;
+ // Forward declaration.
+ template <class T>
+ class zomanip;
-// /// Apply a function on \a s via the operator <<.
-// template <class T>
-// zofstream&
-// operator<<(zofstream &s, const zomanip<T> &m) {
-// return (*m.func)(s, m.val);
-// }
+ /// Apply a function on \a s via the operator <<.
+ template <class T>
+ zofstream&
+ operator<<(zofstream &s, const zomanip<T> &m) {
+ return (*m.func)(s, m.val);
+ }
-// /// Define a pair func / val to perform manipulation on zofstream.
-// template<class T> class zomanip
-// {
-// friend zofstream &operator<< <T>(zofstream &, const
zomanip<T> &);
-// public:
-// zomanip(zofstream &(*f)(zofstream &, T), T v) : func(f), val(v) { }
-// private:
-// zofstream &(*func)(zofstream &, T);
-// T val;
-// };
+ /// Define a pair func / val to perform manipulation on zofstream.
+ template<class T> class zomanip
+ {
+ friend zofstream &operator<< <T>(zofstream &, const zomanip<T>
&);
+ public:
+ zomanip(zofstream &(*f)(zofstream &, T), T v) : func(f), val(v) { }
+ private:
+ zofstream &(*func)(zofstream &, T);
+ T val;
+ };
-// /// Set the compression level of \a s to \a l.
-// inline zofstream&
-// setcompressionlevel(zofstream &s, int l) {
-// (s.rdbuf())->setcompressionlevel(l);
-// return s;
-// }
+ /// Set the compression level of \a s to \a l.
+ inline zofstream&
+ setcompressionlevel(zofstream &s, int l) {
+ (s.rdbuf())->setcompressionlevel(l);
+ return s;
+ }
-// /// Set the compression strategy of \a s to \a l.
-// inline zofstream&
-// setcompressionstrategy(zofstream &s, int l)
-// {
-// (s.rdbuf())->setcompressionstrategy(l);
-// return s;
-// }
+ /// Set the compression strategy of \a s to \a l.
+ inline zofstream&
+ setcompressionstrategy(zofstream &s, int l)
+ {
+ (s.rdbuf())->setcompressionstrategy(l);
+ return s;
+ }
-// /// Specialized version for zomanip<int>
-// inline zomanip<int>
-// setcompressionlevel(int l)
-// {
-// return zomanip<int>(&setcompressionlevel,l);
-// }
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionlevel(int l)
+ {
+ return zomanip<int>(&setcompressionlevel,l);
+ }
-// /// Specialized version for zomanip<int>
-// inline zomanip<int>
-// setcompressionstrategy(int l)
-// {
-// return zomanip<int>(&setcompressionstrategy,l);
-// }
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionstrategy(int l)
+ {
+ return zomanip<int>(&setcompressionstrategy,l);
+ }
-// } // end of namespace gz
+ } // end of namespace gz
-// } // end of namespace io
+ } // end of namespace io
-// } // end of namespace oln
+} // end of namespace oln
-// # endif // ! HAVE_ZLIB
+# endif // ! HAVE_ZLIB
#endif // ! OLN_IO_GZ_STREAM_HH
Index: oln/io/write_image_pnm_2d.hh
--- oln/io/write_image_pnm_2d.hh (revision 0)
+++ oln/io/write_image_pnm_2d.hh (revision 0)
@@ -0,0 +1,153 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_WRITE_IMAGE_PNM_2D_HH
+# define OLN_IO_WRITE_IMAGE_PNM_2D_HH
+
+# include <ntg/all.hh>
+
+# include <oln/canvas/io.hh>
+
+# include <oln/core/2d/image2d.hh>
+# include <oln/io/write_image_pnm_decl.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I>
+ struct write_pnm_vect<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_vect<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_vect<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_comp_type(value_type) comp_type;
+ typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
+
+ void impl_write_point()
+ {
+ value_type c = this->input[this->p];
+ for (unsigned i = 0; i < ntg_nb_comp(value_type); ++i)
+ {
+ v_type v;
+ v = c[i];
+ this->ostr.write((char*)&v, sizeof (v_type));
+ }
+ }
+
+ write_pnm_vect(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+ template <typename I>
+ struct write_pnm_real<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_real<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_real<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+
+ void impl_write_point()
+ {
+ v_type v;
+ v = this->input[this->p];
+ this->ostr.write((char*)&v, sizeof (v_type));
+ }
+
+ write_pnm_real(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+ template <typename I>
+ struct write_pnm_bin<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_bin<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_bin<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+ int offset;
+ char v;
+
+ void extra_work()
+ {
+ if (offset != 7)
+ {
+ this->ostr.write(&v, 1);
+ offset = 7;
+ v = 0;
+ }
+ }
+
+ void impl_write_point()
+ {
+ if (offset == -1)
+ {
+ this->ostr.write(&v, 1);
+ offset = 7;
+ v = 0;
+ }
+ if (this->input[this->p] == value_type(1))
+ v |= 1 << offset;
+ offset--;
+ }
+
+ write_pnm_bin(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr),
+ offset(7),
+ v(0)
+ {
+ }
+
+ };
+
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_WRITE_IMAGE_PNM_2D_HH
Index: oln/io/read_image_2d_pnm.hh
--- oln/io/read_image_2d_pnm.hh (revision 188)
+++ oln/io/read_image_2d_pnm.hh (working copy)
@@ -1,187 +0,0 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLN_IO_READ_IMAGE_2D_PNM_HH
-# define OLN_IO_READ_IMAGE_2D_PNM_HH
-
-// # include <iostream>
-// # include <string>
-
-// # include <mlc/box.hh>
-// # include <mlc/math.hh>
-
-// # include <ntg/all.hh>
-
-// # include <oln/core/2d/image2d.hh>
-
-// # include <oln/core/abstract/image_operator.hh>
-
-// # include <oln/io/utils.hh>
-
-
-// namespace oln {
-
-// template <typename I>
-// struct image2d;
-
-// // fwd decl
-// namespace io {
-// namespace impl {
-// template <typename I> struct read_image_2d_raw;
-// }
-// }
-
-// // super_type
-// template <typename I>
-// struct set_super_type < io::impl::read_image_2d_raw<I> >
-// {
-// typedef abstract::image_operator<I, io::impl::read_image_2d_raw<I> >
ret;
-// };
-
-
-// namespace io {
-
-// namespace impl {
-
-// template <typename I>
-// struct read_image_2d_raw :
-// public oln::abstract::image_operator<I, read_image_2d_raw<I> >
-// {
-// typedef oln::abstract::image_operator<I, read_image_2d_raw<I> >
-// super_type;
-// typedef oln_type_of(I, value) value_type;
-
-// std::istream& istr_;
-// internal::pnm_info& info_;
-// char v;
-// int offset;
-
-// read_image_2d_raw(std::istream &istr,
-// internal::pnm_info &info) :
-// super_type(),
-// istr_(istr),
-// info_(info),
-// offset(-1)
-// {
-// }
-
-// template <typename E>
-// void precond(ntg::real_value<E>& c)
-// {
-// precondition(ntg_max_val(value_type) <= info_.max_val);
-// precondition(info_.type == "P5");
-// }
-
-// template <typename E>
-// void precond(ntg::vect_value<E>& c)
-// {
-// precondition(ntg_max_val(ntg_comp_type(value_type)) <=
-// info_.max_val);
-// precondition(info_.type == "P6");
-// precondition(ntg_nb_comp(value_type) == 3);
-// }
-
-// void precond(ntg::bin& c)
-// {
-// precondition(info_.type == "P4");
-// }
-
-// void impl_run()
-// {
-// value_type c;
-// point2d p;
-// oln::image2d<value_type> tmp(info_.rows, info_.cols);
-
-// precond(c);
-
-// for (p.row() = 0; p.row() < info_.rows && !istr_.eof(); ++p.row())
-// {
-// offset = -1;
-// for (p.col() = 0; p.col() < info_.cols && !istr_.eof(); ++p.col())
-// {
-// read_value_type(c);
-// tmp[p] = c;
-// }
-// }
-// this->output = tmp;
-// }
-
-// //FIXME: Should work with builtin types.
-
-// template <typename E>
-// void read_value_type(ntg::real_value<E> &c)
-// {
-// typedef oln_io_type(ntg_nbits(E)) v_type;
-// v_type v;
-// istr_.read((char*)&v, sizeof (v_type));
-// c = ntg::cast::force<E, v_type>(v);
-// }
-
-// template <typename E>
-// void read_value_type(ntg::vect_value<E> &c)
-// {
-// for (unsigned i = 0; i < ntg_nb_comp(E); i++)
-// {
-// typedef oln_io_type(ntg_nbits(ntg_comp_type(E))) v_type;
-// v_type v;
-// istr_.read((char*)&v, sizeof (v_type));
-// c[i] = ntg::cast::force<ntg_comp_type(E), v_type>(v);
-// }
-// }
-
-// void read_value_type(ntg::bin &c)
-// {
-
-// if (offset == -1)
-// {
-// istr_.read(&v, 1);
-// offset = 7;
-// }
-// if ((int)(v & (1<<offset--)) == 0)
-// c = 0;
-// else
-// c = 1;
-// }
-// };
-
-// template <typename I>
-// read_image_2d_raw<I>
-// read(std::istream& istr, internal::pnm_info info)
-// {
-// read_image_2d_raw<I> tmp(istr, info);
-// tmp.run();
-// return tmp;
-// }
-
-// }
-
-// }
-
-// }
-
-
-#endif // ! OLN_IO_READ_IMAGE_2D_PNM_HH
Index: oln/io/write_image.hh
--- oln/io/write_image.hh (revision 188)
+++ oln/io/write_image.hh (working copy)
@@ -28,84 +28,84 @@
#ifndef OLN_IO_WRITE_IMAGE_HH
# define OLN_IO_WRITE_IMAGE_HH
-// # include <string>
+# include <string>
-// # include <oln/io/gz_stream.hh>
-// # include <oln/io/utils.hh>
-// # include <oln/io/write_image_2d_pnm.hh>
+# include <oln/io/gz_stream.hh>
+# include <oln/io/utils.hh>
+# include <oln/io/write_image_pnm.hh>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// template <typename I>
-// void do_write(const abstract::image<I>& ima,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-// typedef oln_type_of(I, value) value_type;
-// value_type t;
+ template <typename I>
+ void write_dispatch_ext(const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
+ ext == "pnm")
+ write_pnm(ima, ostr, ext);
+ else
+ std::cout << "io error: format not supported."
+ << std::endl;
+ }
-// impl::write(ima.exact(), t, ostr, ext);
-// }
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void write_gz(const abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zofstream zostr(name.c_str(), std::ios::out);
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// template <typename I>
-// void write_gz(const abstract::image<I>& ima, const std::string&
name)
-// {
-// gz::zofstream zostr(name.c_str(), std::ios::out);
+ if (zostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name <<
std::endl;
+ else
+ {
+ std::string ext;
-// if (zostr.is_open() == false)
-// std::cerr << "error: couldn't open " << name <<
std::endl;
-// else
-// {
-// std::string ext;
+ ext = internal::extension(name.substr(0, name.size() - 3));
+ write_dispatch_ext(ima, zostr, ext);
+ }
+ zostr.close();
+ }
-// ext = internal::utils::extension(name.substr(0, name.size() - 3));
-// do_write(ima, zostr, ext);
-// }
-// zostr.close();
-// }
+#endif // ! HAVE_ZLIB
-// #endif // ! HAVE_ZLIB
+ template <typename I>
+ void write_non_gz(const abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ofstream ostr;
-// template <typename I>
-// void write_non_gz(const abstract::image<I>& ima,
-// const std::string& name,
-// const std::string& ext)
-// {
-// std::ofstream ostr;
+ ostr.open(name.c_str(), std::ifstream::out);
-// ostr.open(name.c_str(), std::ifstream::out);
+ if (ostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name <<
std::endl;
+ else
+ write_dispatch_ext(ima, ostr, ext);
+ ostr.close();
+ }
-// if (ostr.is_open() == false)
-// std::cerr << "error: couldn't open " << name <<
std::endl;
-// else
-// do_write(ima, ostr, ext);
-// ostr.close();
-// }
+ template <typename I>
+ void write(const abstract::image<I>& ima, const std::string& name)
+ {
+ std::string ext;
-// template <typename I>
-// void write(const abstract::image<I>& ima, const std::string& name)
-// {
-// std::string ext;
-// // FIXME: Unused?
-// // oln_type_of(I, value) t;
+ ext = internal::extension(name);
-// ext = internal::utils::extension(name);
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ if (ext == "gz")
+ write_gz(ima, name);
+ else
+ write_non_gz(ima, name, ext);
+# else
+ write_non_gz(ima, name, ext);
+#endif // ! HAVE_ZLIB
+ }
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// if (ext == "gz")
-// write_gz(ima, name);
-// else
-// write_non_gz(ima, name, ext);
-// # else
-// write_non_gz(ima, name, ext);
-// #endif // ! HAVE_ZLIB
-// }
+ }
-// }
+}
-// }
-
#endif // ! OLN_IO_WRITE_IMAGE_HH
Index: oln/io/read_image_pnm_2d.hh
--- oln/io/read_image_pnm_2d.hh (revision 0)
+++ oln/io/read_image_pnm_2d.hh (revision 0)
@@ -0,0 +1,166 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_READ_IMAGE_PNM_2D_HH
+# define OLN_IO_READ_IMAGE_PNM_2D_HH
+
+# include <ntg/all.hh>
+
+# include <oln/canvas/io.hh>
+
+# include <oln/core/2d/image2d.hh>
+# include <oln/io/read_image_pnm_decl.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I>
+ struct read_pnm_vect<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_vect<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_vect<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_comp_type(value_type) comp_type;
+ typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
+
+ void impl_read_point()
+ {
+ value_type c;
+ for (unsigned i = 0; i < ntg_nb_comp(value_type); ++i)
+ {
+ v_type v;
+ this->istr.read((char*)&v, sizeof (v_type));
+ c[i] = (ntg_storage_type(ntg_comp_type(value_type)))v;
+ }
+ this->output[this->p] = c;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(comp_type) - ntg_min_val(comp_type)
+ <= this->hdr.max_val);
+ precondition(ntg_nb_comp(value_type) == 3);
+ }
+
+ read_pnm_vect(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+ template <typename I>
+ struct read_pnm_real<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_real<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_real<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+
+ void impl_read_point()
+ {
+ v_type v;
+ this->istr.read((char*)&v, sizeof (v_type));
+ this->output[this->p] = (ntg_storage_type(value_type))v;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(value_type) - ntg_min_val(value_type)
+ <= this->hdr.max_val);
+ }
+
+ read_pnm_real(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+ template <typename I>
+ struct read_pnm_bin<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_bin<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_bin<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+ char v;
+ int offset;
+
+ void impl_extra_work()
+ {
+ offset = -1;
+ }
+
+ void impl_read_point()
+ {
+ if (offset == -1)
+ {
+ this->istr.read(&v, 1);
+ offset = 7;
+ }
+ if ((int)(v & (1<<offset--)) == 0)
+ this->output[this->p] = 0;
+ else
+ this->output[this->p] = 1;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(value_type) - ntg_min_val(value_type)
+ <= this->hdr.max_val);
+ }
+
+ read_pnm_bin(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr),
+ offset(-1)
+ {}
+
+ };
+
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_2D_HH
Index: oln/io/read_image.hh
--- oln/io/read_image.hh (revision 188)
+++ oln/io/read_image.hh (working copy)
@@ -35,7 +35,7 @@
# include <ntg/core/macros.hh>
-# include <oln/io/read_image_2d_pnm.hh>
+# include <oln/io/read_image_pnm.hh>
# include <oln/io/utils.hh>
# include <oln/io/gz_stream.hh>
@@ -63,101 +63,74 @@
}
-// template <typename I>
-// void read_dispatch_ext(abstract::image<I>& ima,
-// std::istream& istr,
-// const std::string& ext)
+ template <typename I>
+ void read_dispatch_ext(abstract::image<I>& ima,
+ std::istream& istr,
+ const std::string& ext)
-// {
-// if (ext == "pgm" || ext == "pbm" || ext == "ppm"
||
-// ext == "pnm")
-// {
-// internal::pnm_info info;
+ {
+ if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
+ ext == "pnm")
+ read_pnm(ima, istr, ext);
+ else
+ std::cout << "io error: format not supported."
+ << std::endl;
+ }
-// if (internal::read_pnm_header(istr, info))
-// if ((ext == "ppm" || ext == "pnm") && info.type ==
"P6")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "ppm" || ext == "pnm") && info.type
== "P3")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else if ((ext == "pbm" || ext == "pnm") && info.type
== "P4")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "pbm" || ext == "pnm") && info.type
== "P1")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else if ((ext == "pgm" || ext == "pnm") && info.type
== "P5")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "pgm" || ext == "pnm") && info.type
== "P2")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else
-// std::cerr << "error: file header (`" << info.type
-// << "') does not match file extension (`"
-// << ext << "')" << std::endl;
-// else
-// std::cerr << "error: unable to get a valid header" <<
std::endl;
-// }
-// else
-// std::cout << "no input method for '"
-// << ext << "' file extension"
-// << std::endl;
-// }
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void do_read_gz(abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zifstream zistr(name.c_str(), std::ios::in);
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// template <typename I>
-// void do_read_gz(abstract::image<I>& ima, const std::string& name)
-// {
-// gz::zifstream zistr(name.c_str(), std::ios::in);
+ if (zistr.is_open() == false)
+ std::cerr << "io error: couldn't open " << name <<
std::endl;
+ else
+ {
+ std::string ext;
-// if (zistr.is_open() == false)
-// std::cerr << "error: couldn't open " << name <<
std::endl;
-// else
-// {
-// std::string ext;
+ ext = internal::extension(name.substr(0, name.size() - 3));
+ read_dispatch_ext(ima, zistr, ext);
+ }
+ zistr.close();
+ }
+#endif // ! HAVE_ZLIB
-// ext = internal::utils::extension(name.substr(0, name.size() - 3));
-// read_dispatch_ext(ima, zistr, ext);
-// }
-// zistr.close();
-// }
+ template <typename I>
+ void do_read_non_gz(abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ifstream istr;
-// #endif // ! HAVE_ZLIB
+ istr.open(name.c_str(), std::ifstream::in);
-// template <typename I>
-// void do_read_non_gz(abstract::image<I>& ima,
-// const std::string& name,
-// const std::string& ext)
-// {
-// std::ifstream istr;
+ if (istr.is_open() == false)
+ std::cerr << "io error: couldn't open " << name <<
std::endl;
+ else
+ read_dispatch_ext(ima, istr, ext);
+ istr.close();
+ }
-// istr.open(name.c_str(), std::ifstream::in);
+ template <typename I>
+ void do_read(abstract::image<I>& ima, const filename& name)
+ {
+ std::string ext;
-// if (istr.is_open() == false)
-// std::cerr << "error: couldn't open " << name <<
std::endl;
-// else
-// read_dispatch_ext(ima, istr, ext);
-// istr.close();
-// }
+ ext = internal::extension(name.get());
-// template <typename I>
-// void do_read(abstract::image<I>& ima, const filename& name)
-// {
-// std::string ext;
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// ext = internal::utils::extension(name.get());
+ if (ext == "gz")
+ do_read_gz(ima, name.get());
+ else
+ do_read_non_gz(ima, name.get(), ext);
+#else
+ do_read_non_gz(ima, name.get(), ext);
+#endif // ! HAVE_ZLIB
+ }
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// if (ext == "gz")
-// do_read_gz(ima, name.get());
-// else
-// do_read_non_gz(ima, name.get(), ext);
-// #else
-// do_read_non_gz(ima, name.get(), ext);
-// #endif // ! HAVE_ZLIB
-// }
-
-
}
}
Index: oln/io/write_image_pnm_decl.hh
--- oln/io/write_image_pnm_decl.hh (revision 0)
+++ oln/io/write_image_pnm_decl.hh (revision 0)
@@ -0,0 +1,57 @@
+// Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_WRITE_IMAGE_PNM_DECL_HH
+# define OLN_IO_WRITE_IMAGE_PNM_DECL_HH
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+ template <typename I, typename S>
+ struct write_pnm_vect {};
+
+ template <typename I, typename S>
+ struct write_pnm_real {};
+
+ template <typename I, typename S>
+ struct write_pnm_bin {};
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_WRITE_IMAGE_PNM_DECL_HH
Index: oln/io/read_image_pnm_decl.hh
--- oln/io/read_image_pnm_decl.hh (revision 0)
+++ oln/io/read_image_pnm_decl.hh (revision 0)
@@ -0,0 +1,57 @@
+ // Copyright (C) 2005 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_IO_READ_IMAGE_PNM_DECL_HH
+# define OLN_IO_READ_IMAGE_PNM_DECL_HH
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I, typename S>
+ struct read_pnm_vect {};
+
+ template <typename I, typename S>
+ struct read_pnm_real {};
+
+ template <typename I, typename S>
+ struct read_pnm_bin {};
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_DECL_HH
Index: oln/io/utils.hh
--- oln/io/utils.hh (revision 188)
+++ oln/io/utils.hh (working copy)
@@ -28,153 +28,144 @@
#ifndef OLENA_IO_UTILS_HH
# define OLENA_IO_UTILS_HH
-// # include <oln/config/system.hh>
+# include <oln/config/system.hh>
-// # include <iostream>
-// # include <fstream>
-// # include <string>
+# include <iostream>
+# include <fstream>
+# include <string>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// namespace internal {
+ namespace internal {
-// /*!
-// ** \brief Utils for io (get extension of a file).
-// */
-// struct utils
-// {
+ /*!
+ ** \brief Return the extension of a filename.
+ ** \arg name The filename.
+ ** \return The extension (lower case).
+ */
+ std::string extension(const std::string& name)
+ {
+ std::string ext;
+ int pos = name.rfind('.');
+ if (pos > 0)
+ {
+ ext.assign(name, pos + 1, name.size() - pos);
+ for (std::string::iterator i = ext.begin(); i != ext.end(); ++i)
+ *i = tolower(*i);
+ }
+ return ext;
+ }
-// /*!
-// ** \brief Return the extension of a filename.
-// ** \arg name The filename.
-// ** \return The extension (lower case).
-// */
-// static std::string
-// extension(const std::string& name)
-// {
-// std::string ext;
-// int pos = name.rfind('.');
-// if (pos > 0)
-// {
-// ext.assign(name, pos + 1, name.size() - pos);
-// for (std::string::iterator i = ext.begin(); i != ext.end(); ++i)
-// *i = tolower(*i);
-// }
-// return ext;
-// }
-// };
+ struct pnm_header
+ {
+ int max_val;
+ int rows;
+ int cols;
+ std::string type;
+ };
+ bool read_pnm_header(std::istream& istr,
+ internal::pnm_header& hdr)
+ {
+ std::getline(istr, hdr.type);
-// struct pnm_info
-// {
-// int max_val;
-// int rows;
-// int cols;
-// std::string type;
-// };
+ hdr.max_val = 1;
-// bool read_pnm_header(std::istream& istr,
-// internal::pnm_info& info)
-// {
-// std::getline(istr, info.type);
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// info.max_val = 1;
+ // read size
+ istr >> hdr.cols;
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
-// // read size
-// istr >> info.cols;
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ istr >> hdr.rows;
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
+ if (hdr.cols <= 0 || hdr.rows <= 0) return false;
-// istr >> info.rows;
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// if (info.cols <= 0 || info.rows <= 0) return false;
+ // FIXME: it can be either '\n', 'whitespace', ..., not only
'\n'!
+ if (istr.get() != '\n') return false;
+ // extract or skip maxvalue
+ if (hdr.type != "P1" && hdr.type != "P4")
+ {
+ istr >> hdr.max_val;
+ if (hdr.max_val > 65535 ||
+ istr.get() != '\n' ||
+ hdr.max_val <= 0)
+ return false;
+ }
+ return true;
+ }
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ bool write_pnm_header(std::ostream& ostr,
+ const std::string& type,
+ int ncols,
+ int nrows,
+ int max_val)
+ {
+ if (max_val > 65535)
+ return false;
-// // FIXME: it can be either '\n', 'whitespace', ..., not only
'\n'!
-// if (istr.get() != '\n') return false;
-// // extract or skip maxvalue
-// if (info.type != "P1" && info.type != "P4")
-// {
-// istr >> info.max_val;
-// if (info.max_val > 65535 ||
-// istr.get() != '\n' ||
-// info.max_val <= 0)
-// return false;
-// }
-// return true;
-// }
+ ostr << type << std::endl
+ << "# Olena 1.0" << std::endl
+ << ncols << " " << nrows << std::endl;
+ if (type != "P1" && type != "P4")
+ ostr << max_val << std::endl;
+ return true;
+ }
-// bool write_pnm_header(std::ostream& ostr,
-// const std::string& type,
-// int ncols,
-// int nrows,
-// int max_val)
-// {
-// if (max_val > 65535)
-// return false;
+ template <bool b>
+ struct pnm_io_helper_bool
+ {
+ typedef unsigned char type;
+ };
-// ostr << type << std::endl
-// << "# Olena 1.0" << std::endl
-// << ncols << " " << nrows << std::endl;
-// if (type != "P1" && type != "P4")
-// ostr << max_val << std::endl;
-// return true;
-// }
+ template <>
+ struct pnm_io_helper_bool<false>
+ {
+ typedef unsigned short type;
+ };
-// template <bool b>
-// struct pnm_io_helper_bool
-// {
-// typedef unsigned char type;
-// };
+ template <unsigned N>
+ struct pnm_io_helper
+ {
+ typedef typename pnm_io_helper_bool<N <= 8>::type type;
+ };
-// template <>
-// struct pnm_io_helper_bool<false>
-// {
-// typedef unsigned short type;
-// };
+ } // end of namespace internal
-// template <unsigned N>
-// struct pnm_io_helper
-// {
-// typedef typename pnm_io_helper_bool<N <= 8>::type type;
-// };
+ } // end of namespace io
-// } // end of namespace internal
+} // end of namespace oln
-// } // end of namespace io
+# define oln_io_type(N) typename oln::io::internal::pnm_io_helper<N>::type
+# define oln_io_type_(N) oln::io::internal::pnm_io_helper<N>::type
-// } // end of namespace oln
-// # define oln_io_type(N) typename oln::io::internal::pnm_io_helper<N>::type
-// # define oln_io_type_(N) oln::io::internal::pnm_io_helper<N>::type
-
-
#endif // ! OLENA_IO_UTILS_HH
Index: oln/canvas/reconstruction.hh
--- oln/canvas/reconstruction.hh (revision 188)
+++ oln/canvas/reconstruction.hh (working copy)
@@ -161,8 +161,8 @@
box<oln_type_of(I1, concrete)> work;
box<oln_type_of(I1, concrete)> output;
- box<I1> marker;
- box<I2> mask;
+ box<const I1> marker;
+ box<const I2> mask;
std::queue<oln_type_of(I1, point) > fifo;
@@ -209,8 +209,8 @@
box<oln_type_of(I1, concrete)> work;
box<oln_type_of(I1, concrete)> output;
- box<I1> marker;
- box<I2> mask;
+ box<const I1> marker;
+ box<const I2> mask;
};
Index: oln/canvas/io.hh
--- oln/canvas/io.hh (revision 188)
+++ oln/canvas/io.hh (working copy)
@@ -31,6 +31,7 @@
# include <iostream>
# include <mlc/any.hh>
+# include <oln/core/box.hh>
# include <oln/core/abstract/image.hh>
# include <oln/io/utils.hh>
@@ -49,6 +50,11 @@
{
}
+ void work()
+ {
+ this->exact().impl_work();
+ }
+
void extra_work()
{
this->exact().impl_extra_work();
@@ -61,10 +67,9 @@
void run()
{
- for (p.row() = 0; p.row() < out.size().nrows(); ++p.row())
+ for (p.row() = 0; p.row() < input.size().nrows(); ++p.row())
{
- for (p.col() = 0; p.col() < out.size().ncols(); ++p.col())
- write_point();
+ work();
extra_work();
}
}
@@ -74,18 +79,60 @@
write(const oln::abstract::image<I>& input,
std::ostream& ostr) :
- input(input),
+ input(input.exact()),
ostr(ostr)
{}
- const I& input;
+ box<const I> input;
std::ostream& ostr;
oln_type_of(I, point) p;
+ };
+
+
+ template <typename I, typename E>
+ struct write_2d: public write<I, E>
+ {
+
+ void impl_work()
+ {
+ for (this->p.col() = 0;
+ this->p.col() < this->input.size().ncols();
+ ++this->p.col())
+ this->write_point();
+ }
+
+ protected:
+ typedef write<I, E> super_type;
+
+ write_2d(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
};
+ template <typename I, typename E>
+ struct write_1d: public write<I, E>
+ {
+ void impl_work()
+ {
+ this->write_point();
+ }
+
+ protected:
+ typedef write<I, E> super_type;
+
+ write_1d(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+
template <typename I, typename E>
struct read : public mlc::any<E>
{
@@ -107,15 +154,28 @@
this->exact().impl_preconditions();
}
+ void work()
+ {
+ this->exact().impl_work();
+ }
+
+ void get_output(I& ima)
+ {
+ ima = output.unbox();
+ }
+
void run()
{
preconditions();
+ I tmp(hdr.rows, hdr.cols);
+
+ output = tmp;
+
for (p.row() = 0; p.row() < hdr.rows && !istr.eof(); ++p.row())
{
extra_work();
- for (p.col() = 0; p.col() < hdr.cols && !istr_.eof(); ++p.col())
- read_point();
+ work();
}
}
@@ -134,7 +194,49 @@
};
+ template <typename I, typename E>
+ struct read_2d: public read<I, E>
+ {
+ void impl_work()
+ {
+ for (this->p.col() = 0;
+ this->p.col() < this->hdr.cols && !this->istr.eof();
+ ++this->p.col())
+ this->read_point();
+ }
+
+ protected:
+ typedef read<I, E> super_type;
+
+ read_2d(std::istream& istr,
+ const io::internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+
+ template <typename I, typename E>
+ struct read_1d: public read<I, E>
+ {
+
+ void impl_work()
+ {
+ this->read_point();
+ }
+
+ protected:
+ typedef read<I, E> super_type;
+
+ read_1d(std::istream& istr,
+ const io::internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+
}