
Index: ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * oln/io/write_image_2d_pnm.hh (ntg::bin): Write padding bits at the end of each line. * oln/io/read_image_2d_pnm.hh (ntg::bin): Skip padding bits at the end of each line. read_image_2d_pnm.hh | 24 +++++++++++++++++++----- write_image_2d_pnm.hh | 40 ++++++++++++++++++++++------------------ 2 files changed, 41 insertions, 23 deletions Index: oln/io/write_image_2d_pnm.hh --- oln/io/write_image_2d_pnm.hh (revision 163) +++ oln/io/write_image_2d_pnm.hh (working copy) @@ -74,33 +74,43 @@ { point2d p; value_type c; - bool b = false; for (p.row() = 0; p.row() < to_write_.size().nrows(); ++p.row()) - for (p.col() = 0; p.col() < to_write_.size().ncols(); ++p.col()) + { + for (p.col() = 0; p.col() < to_write_.size().ncols(); ++p.col()) // FIXME: SHOULD NOT BE .value() !!! - b = write_value_type(to_write_[p].value()); - while (b == false) - b = write_value_type(c); - bin_offset = 7; - bin_v = 0; + 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> - bool write_value_type(const ntg::real_value<E> &c) + 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)); - return true; } template <typename E> - bool write_value_type(const ntg::vect_value<E> &c) + void write_value_type(const ntg::vect_value<E> &c) { for (unsigned i = 0; i < 3; i++) { @@ -110,25 +120,19 @@ v = c[i]; ostr_.write((char*)&v, sizeof (v_type)); } - return true; } - bool write_value_type(const ntg::bin &c) + void write_value_type(const ntg::bin &c) { - bool ret = false; - if (bin_offset == -1) { - bin_v = ~bin_v; ostr_.write(&bin_v, 1); bin_offset = 7; bin_v = 0; - ret = true; } - if (c == value_type(0)) + if (c == value_type(1)) bin_v |= 1 << bin_offset; bin_offset--; - return ret; } }; Index: oln/io/read_image_2d_pnm.hh --- oln/io/read_image_2d_pnm.hh (revision 163) +++ oln/io/read_image_2d_pnm.hh (working copy) @@ -119,14 +119,28 @@ precond(c); for (p.row() = 0; p.row() < info_.rows && !istr_.eof(); ++p.row()) - for (p.col() = 0; p.col() < info_.cols && !istr_.eof(); ++p.col()) - { - read_value_type(c); - tmp[p] = c; - } + { + offset = -1; + for (p.col() = 0; p.col() < info_.cols && !istr_.eof(); ++p.col()) + { + read_value_type(c); + tmp[p] = c; + } + } this->output = tmp; } + +// template <typename E> +// void read_padding(const ntg::value<E>&) +// { +// } + +// void read_padding(const ntg::bin&) +// { +// offset = -1; +// } + //FIXME: Should work with builtin types. template <typename E>