Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
save_header.hh
1 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_IO_PNM_SAVE_HEADER_HH
27 # define MLN_IO_PNM_SAVE_HEADER_HH
28 
32 
33 # include <iostream>
34 # include <fstream>
35 
36 # include <mln/io/pnm/max_component.hh>
37 
38 # include <mln/value/rgb.hh>
39 # include <mln/geom/nrows.hh>
40 # include <mln/geom/ncols.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace io
47  {
48 
49 # ifndef MLN_INCLUDE_ONLY
50 
51  namespace pnm
52  {
53 
54  template <typename V>
55  inline
56  void save_max_val(V&, std::ofstream& file)
57  {
58  file << max_component(V()) << std::endl;
59  }
60 
61  inline
62  void save_max_val(bool&, std::ofstream&)
63  {
64  }
65 
66  template <typename I>
67  inline
68  void save_header(char type,
69  const I& ima, const std::string& filename,
70  std::ofstream& file)
71  {
72  if (! file)
73  {
74  std::cerr << "error: cannot open file '" << filename
75  << "'!";
76  abort();
77  }
78  file << "P" << type << std::endl;
79  file << "# Generated by Milena 1.0 http://olena.lrde.epita.fr" << std::endl;
80  file << "# EPITA Research and Development Laboratory (LRDE)" << std::endl;
81  // We have a two-line comment because xv is buggy for some
82  // tiny binary images and their workaround is to have such a
83  // two-line comment...
84  file << geom::ncols(ima) << ' ' << geom::nrows(ima) << std::endl;
85 
86  mln_value(I) i;
87  save_max_val(i, file);
88  }
89 
90  } // end of namespace mln::io::pnm
91 
92 
93 # endif // ! MLN_INCLUDE_ONLY
94 
95  } // end of namespace mln::io
96 
97 } // end of namespace mln
98 
99 
100 #endif // ! MLN_IO_PNM_SAVE_HEADER_HH