1 /*
2  *  OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  *  Copyright (C) 2000 Bruno Levy
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *  If you modify this software, you should include a notice giving the
20  *  name of the person performing the modification, the date of modification,
21  *  and the reason for such modification.
22  *
23  *  Contact: Bruno Levy
24  *
25  *     levy@loria.fr
26  *
27  *     ISA Project
28  *     LORIA, INRIA Lorraine,
29  *     Campus Scientifique, BP 239
30  *     54506 VANDOEUVRE LES NANCY CEDEX
31  *     FRANCE
32  *
33  *  Note that the GNU General Public License does not permit incorporating
34  *  the Software into proprietary programs.
35  */
36 
37 
38 #include <geogram/image/image_serializer.h>
39 #include <geogram/basic/logger.h>
40 
41 #include <fstream>
42 
43 namespace GEO {
44 
45 //_________________________________________________________
46 
47 
serialize_read(const std::string & file_name)48     Image* ImageSerializer::serialize_read(const std::string& file_name) {
49 
50         std::fstream::openmode mode = binary() ?
51             (std::fstream::in | std::fstream::binary) :
52              std::fstream::in ;
53 
54         std::ifstream input(file_name.c_str(),mode) ;
55         if(!input) {
56             Logger::err("ImageSerializer")
57                 << "could not open file\'"
58                 << file_name << "\'" << std::endl ;
59             return nullptr ;
60         }
61         return serialize_read(input) ;
62     }
63 
serialize_write(const std::string & file_name,const Image * image)64     bool ImageSerializer::serialize_write(
65         const std::string& file_name, const Image* image
66     ) {
67         std::fstream::openmode mode = binary() ?
68             (std::fstream::out | std::fstream::trunc | std::fstream::binary) :
69             (std::fstream::out | std::fstream::trunc) ;
70 
71         std::ofstream output(file_name.c_str(), mode) ;
72 
73         if(!output) {
74             Logger::err("ImageSerializer")
75                 << "could not open file\'"
76                 << file_name << "\'" << std::endl ;
77             return false ;
78         }
79 
80         return serialize_write(output, image) ;
81     }
82 
serialize_read(std::istream & stream)83     Image* ImageSerializer::serialize_read(std::istream& stream) {
84         geo_argused(stream);
85         bool implemented = false ;
86         geo_assert(implemented) ;
87         return nullptr ;
88     }
89 
serialize_write(std::ostream & stream,const Image * image)90     bool ImageSerializer::serialize_write(
91         std::ostream& stream, const Image* image
92     ) {
93         geo_argused(stream);
94         geo_argused(image);
95         bool implemented = false ;
96         geo_assert(implemented) ;
97         return false ;
98     }
99 
100 
binary() const101     bool ImageSerializer::binary() const {
102         return true ;
103     }
104 
streams_supported() const105     bool ImageSerializer::streams_supported() const {
106         return true ;
107     }
108 
read_supported() const109     bool ImageSerializer::read_supported() const {
110         return false ;
111     }
112 
write_supported() const113     bool ImageSerializer::write_supported() const {
114         return false ;
115     }
116 
117 //_________________________________________________________
118 
119 }
120 
121