proto-1.0 250: Fix PBM (binary) image reading

Rappels : 1. les mauvaises initialisations sont une plaie du C/C++, il faut y faire attention ; 2. il existe des tests dans Olena, c'est bien de les lancer de temps en temps pour voir si on casse pas trop de choses en avançant ! ChangeLog | 29 +++++++++++++++++++++++++++++ oln/core/abstract/grid.hh | 2 ++ oln/core/abstract/image.hh | 4 +++- oln/core/gen/internal/value_box.hh | 32 ++++++++++++++++++++++++++++++-- oln/funobj/invert.hh | 2 ++ oln/io/gz_stream.hh | 6 ++++++ oln/io/pnm_bin.hh | 26 ++++++++++---------------- oln/io/pnm_header.hh | 3 +++ oln/io/pnm_real.hh | 3 ++- oln/io/pnm_vect.hh | 2 ++ oln/level/invert.hh | 1 + tests/io/tests/2d | 2 ++ 12 files changed, 92 insertions(+), 20 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland@lrde.epita.fr> Fix PBM (binary) image reading. * oln/core/abstract/grid.hh (oln_grd_type_of_): New macro. * oln/io/pnm_bin (read_bin<oln::grid2d>::size_type) (read_bin<oln::grid2d>::point_type) (write_bin<oln::grid2d>::size_type) (write_bin<oln::grid2d>::point_type): Define these typedefs using oln_grd_type_of_. (read_bin<oln::grid2d>::read_bin): Initialize v to 0. (write_bin<oln::grid2d>::write_bin): Initialize offset and v. Fix io/2d test. * oln/io/pnm_header.hh (iostream, string): Include these files. * oln/io/pnm_bin.hh, oln/io/pnm_real.hh, oln/io/pnm_vect.hh (oln/core/2d/point2d.hh, oln/core/2d/size2d.hh): Likewise. * oln/funobj/invert.hh (oln/core/gen/internal/value_box.hh): Likewise. * oln/core/abstract/image.hh: Add forward declaration of oln::value_box. * oln/core/gen/internal/value_box.hh (oln/overloaded_cmp_op_operand): New helper. (oln_decl_comp_binop_vb_whatever): Use it. * oln/io/gz_stream.hh: Add forward declarations to please G++ 4.0. * tests/io/tests/2d (oln/core/2d/image2d.hh): Include this file. Index: olena/tests/io/tests/2d --- olena/tests/io/tests/2d (révision 248) +++ olena/tests/io/tests/2d (copie de travail) @@ -29,6 +29,8 @@ #include "loadsave.hh" +#include <oln/core/2d/image2d.hh> + bool check(void) { Index: olena/oln/funobj/invert.hh --- olena/oln/funobj/invert.hh (révision 248) +++ olena/oln/funobj/invert.hh (copie de travail) @@ -32,6 +32,8 @@ # include <ntg/all.hh> +# include <oln/core/gen/internal/value_box.hh> + namespace oln { namespace funobj { Index: olena/oln/core/abstract/image.hh --- olena/oln/core/abstract/image.hh (révision 248) +++ olena/oln/core/abstract/image.hh (copie de travail) @@ -30,7 +30,6 @@ # include <oln/core/typedefs.hh> - # define oln_type_of_(ImageType, Alias) \ mlc_type_of_(oln, oln::category::image, ImageType, Alias) @@ -42,6 +41,9 @@ namespace oln { + // fwd decl + template <typename I> + class value_box; // fwd decls namespace abstract Index: olena/oln/core/abstract/grid.hh --- olena/oln/core/abstract/grid.hh (révision 248) +++ olena/oln/core/abstract/grid.hh (copie de travail) @@ -35,6 +35,8 @@ # define oln_grd_type_of(GridType, Alias) \ mlc_type_of(oln, oln::category::grid, GridType, Alias) +# define oln_grd_type_of_(GridType, Alias) \ +mlc_type_of_(oln, oln::category::grid, GridType, Alias) namespace oln { Index: olena/oln/core/gen/internal/value_box.hh --- olena/oln/core/gen/internal/value_box.hh (révision 248) +++ olena/oln/core/gen/internal/value_box.hh (copie de travail) @@ -350,6 +350,33 @@ | Comparison operators. | `-----------------------*/ +// Helper used in the resolution of right operand of a comparison +// operator having a value_box as left operand. +// FIXME: To be replaced by the oln::utils::overload mechanism. +namespace oln +{ + + template <typename T> + struct overloaded_cmp_op_operand + { + static T value(const T& t) + { + return t; + } + }; + + template <typename I> + struct overloaded_cmp_op_operand<oln::value_box<I> > + { + static typename oln::value_box<I>::value_type + value(const oln::value_box<I>& vb) + { + return vb.value(); + } + }; + +} // end of namespace oln + // oln::value_box<I> and whatever. # define oln_decl_comp_binop_vb_whatever(OpSymbol) \ template <typename I, typename V> \ @@ -357,7 +384,8 @@ operator OpSymbol (const oln::value_box<I>& lhs, \ const V& rhs) \ { \ - return lhs.value() OpSymbol rhs; \ + return \ + lhs.value() OpSymbol oln::overloaded_cmp_op_operand<V>::value(rhs); \ } // ntg::value<V> and oln::value_box<I>. @@ -400,7 +428,7 @@ // Helper used in the resolution of right operand of an arithmetical // operator having a value_box as left operand. -// FIXME: To be replaced by the upcoming oln::utils::overload mechanism. +// FIXME: To be replaced by the oln::utils::overload mechanism. namespace oln { Index: olena/oln/io/pnm_bin.hh --- olena/oln/io/pnm_bin.hh (révision 248) +++ olena/oln/io/pnm_bin.hh (copie de travail) @@ -33,7 +33,8 @@ # include <oln/canvas/io.hh> # include <oln/io/pnm_header.hh> # include <oln/core/2d/grid2d.hh> - +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/size2d.hh> namespace oln { @@ -53,13 +54,8 @@ struct read_bin<oln::grid2d> : public canvas::read_from_file<bool, grid2d, read_bin<grid2d> > { - - // FIXME: these macros should work -// typedef oln_grd_type_of(grid2d, size) size_type; -// typedef oln_grd_type_of(grid2d, point) point_type; - - typedef size2d size_type; - typedef point2d point_type; + typedef oln_grd_type_of_(grid2d, size) size_type; + typedef oln_grd_type_of_(grid2d, point) point_type; unsigned impl_npoints() { @@ -109,6 +105,7 @@ read_bin(std::istream& istr, const header& hdr) : istr(istr), hdr(hdr), + v(0), offset(-1) { p.col() = 0; @@ -130,12 +127,8 @@ struct write_bin<oln::grid2d> : public canvas::write_to_file<bool, grid2d, write_bin<grid2d> > { - // FIXME: these macros should work -// typedef oln_grd_type_of(grid2d, size) size_type; -// typedef oln_grd_type_of(grid2d, point) point_type; - - typedef size2d size_type; - typedef point2d point_type; + typedef oln_grd_type_of_(grid2d, size) size_type; + typedef oln_grd_type_of_(grid2d, point) point_type; void set_size(const size_type& size) { @@ -189,11 +182,12 @@ } write_bin(std::ostream& ostr) : - ostr(ostr) + ostr(ostr), + offset(7), + v(0) { p.col() = 0; p.row() = 0; - offset = 7; } std::ostream& ostr; Index: olena/oln/io/pnm_header.hh --- olena/oln/io/pnm_header.hh (révision 248) +++ olena/oln/io/pnm_header.hh (copie de travail) @@ -28,6 +28,9 @@ #ifndef OLN_IO_PNM_HEADER_HH # define OLN_IO_PNM_HEADER_HH +# include <iostream> +# include <string> + namespace oln { Index: olena/oln/io/gz_stream.hh --- olena/oln/io/gz_stream.hh (révision 248) +++ olena/oln/io/gz_stream.hh (copie de travail) @@ -297,6 +297,12 @@ }; + // Forward declarations. + class zifstream; + class zofstream; + zofstream& setcompressionlevel(zofstream&, int); + zofstream& setcompressionstrategy(zofstream&, int); + ///Define an interface for compressed file stream manipulation. class zfilestream_common : virtual public std::ios { Index: olena/oln/io/pnm_vect.hh --- olena/oln/io/pnm_vect.hh (révision 248) +++ olena/oln/io/pnm_vect.hh (copie de travail) @@ -33,6 +33,8 @@ # include <oln/canvas/io.hh> # include <oln/io/pnm_header.hh> # include <oln/core/2d/grid2d.hh> +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/size2d.hh> Index: olena/oln/io/pnm_real.hh --- olena/oln/io/pnm_real.hh (révision 248) +++ olena/oln/io/pnm_real.hh (copie de travail) @@ -33,7 +33,8 @@ # include <oln/canvas/io.hh> # include <oln/io/pnm_header.hh> # include <oln/core/2d/grid2d.hh> - +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/size2d.hh> namespace oln { Index: olena/oln/level/invert.hh --- olena/oln/level/invert.hh (révision 248) +++ olena/oln/level/invert.hh (copie de travail) @@ -28,6 +28,7 @@ #ifndef OLENA_LEVEL_INVERT_HH # define OLENA_LEVEL_INVERT_HH +# include <oln/utils/record.hh> # include <oln/funobj/invert.hh> namespace oln
participants (1)
-
Roland Levillain