00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_IO_PNM_SAVE_HEADER_HH
00027 # define MLN_IO_PNM_SAVE_HEADER_HH
00028
00032
00033 # include <iostream>
00034 # include <fstream>
00035
00036 # include <mln/io/pnm/max_component.hh>
00037
00038 # include <mln/value/rgb.hh>
00039 # include <mln/geom/nrows.hh>
00040 # include <mln/geom/ncols.hh>
00041
00042
00043 namespace mln
00044 {
00045
00046 namespace io
00047 {
00048
00049 # ifndef MLN_INCLUDE_ONLY
00050
00051 namespace pnm
00052 {
00053
00054 template <typename V>
00055 inline
00056 void save_max_val(V&, std::ofstream& file)
00057 {
00058 file << max_component(V()) << std::endl;
00059 }
00060
00061 inline
00062 void save_max_val(bool&, std::ofstream&)
00063 {
00064 }
00065
00066 template <typename I>
00067 inline
00068 void save_header(char type,
00069 const I& ima, const std::string& filename,
00070 std::ofstream& file)
00071 {
00072 if (! file)
00073 {
00074 std::cerr << "error: cannot open file '" << filename
00075 << "'!";
00076 abort();
00077 }
00078 file << "P" << type << std::endl;
00079 file << "# Generated by Milena 1.0 http://olena.lrde.epita.fr" << std::endl;
00080 file << "# EPITA Research and Development Laboratory (LRDE)" << std::endl;
00081
00082
00083
00084 file << geom::ncols(ima) << ' ' << geom::nrows(ima) << std::endl;
00085
00086 mln_value(I) i;
00087 save_max_val(i, file);
00088 }
00089
00090 }
00091
00092
00093 # endif // ! MLN_INCLUDE_ONLY
00094
00095 }
00096
00097 }
00098
00099
00100 #endif // ! MLN_IO_PNM_SAVE_HEADER_HH