ViSP  2.7.0
vpImageIo.h
1 /****************************************************************************
2  *
3  * $Id: vpImageIo.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Read/write images.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
48 #ifndef vpIMAGEIO_H
49 #define vpIMAGEIO_H
50 
51 #include <visp/vpImage.h>
52 #include <visp/vpDebug.h>
53 #include <visp/vpRGBa.h>
54 #include <visp/vpImageConvert.h>
55 
56 #include <stdio.h>
57 #include <iostream>
58 
59 #ifdef WIN32
60 # include <windows.h>
61 #endif
62 
63 #if defined(VISP_HAVE_LIBJPEG)
64 #include <jpeglib.h>
65 #include <jerror.h>
66 #endif
67 
68 #if defined(VISP_HAVE_LIBPNG)
69 #include <png.h>
70 #endif
71 
72 
104 class VISP_EXPORT vpImageIo
105 {
106 
107 private:
108 
109  typedef enum
110  {
111  FORMAT_PGM,
112  FORMAT_PPM,
113  FORMAT_JPEG,
114  FORMAT_PNG,
115  FORMAT_UNKNOWN
116  } vpImageFormatType;
117 
118  static const int vpMAX_LEN;
119 
120  static FILE * openFileRead(const char *filename) ;
121  static FILE * openFileWrite(const char *filename, const char *mode="w") ;
122 
123  static FILE * openFileRead(const std::string filename) ;
124  static FILE * openFileWrite(const std::string filename,
125  const std::string mode="w") ;
126 
127  static vpImageFormatType getFormat(const char *filename) ;
128  static std::string getExtension(const std::string &filename);
129 
130 public:
131 
132  static
133  void read(vpImage<unsigned char> &I, const char *filename) ;
134  static
135  void read(vpImage<unsigned char> &I, const std::string filename) ;
136  static
137  void read(vpImage<vpRGBa> &I, const char *filename) ;
138  static
139  void read(vpImage<vpRGBa> &I, const std::string filename) ;
140 
141  static
142  void write(const vpImage<unsigned char> &I, const char *filename) ;
143  static
144  void write(const vpImage<unsigned char> &I, const std::string filename) ;
145  static
146  void write(const vpImage<vpRGBa> &I, const char *filename) ;
147  static
148  void write(const vpImage<vpRGBa> &I, const std::string filename) ;
149 
150  static
151  void readPFM(vpImage<float> &I, const char *filename) ;
152 
153 
154  static
155  void readPGM(vpImage<unsigned char> &I, const char *filename) ;
156  static
157  void readPGM(vpImage<unsigned char> &I, const std::string filename) ;
158  static
159  void readPGM(vpImage<vpRGBa> &I, const char *filename) ;
160  static
161  void readPGM(vpImage<vpRGBa> &I, const std::string filename) ;
162 
163  static
164  void readPPM(vpImage<unsigned char> &I, const char *filename) ;
165  static
166  void readPPM(vpImage<unsigned char> &I, const std::string filename) ;
167  static
168  void readPPM(vpImage<vpRGBa> &I, const char *filename) ;
169  static
170  void readPPM(vpImage<vpRGBa> &I, const std::string filename) ;
171 
172 #if (defined(VISP_HAVE_LIBJPEG) || defined(VISP_HAVE_OPENCV))
173  static
174  void readJPEG(vpImage<unsigned char> &I, const char *filename) ;
175  static
176  void readJPEG(vpImage<unsigned char> &I, const std::string filename) ;
177  static
178  void readJPEG(vpImage<vpRGBa> &I, const char *filename) ;
179  static
180  void readJPEG(vpImage<vpRGBa> &I, const std::string filename) ;
181 #endif
182 
183 #if (defined(VISP_HAVE_LIBPNG) || defined(VISP_HAVE_OPENCV))
184  static
185  void readPNG(vpImage<unsigned char> &I, const char *filename) ;
186  static
187  void readPNG(vpImage<unsigned char> &I, const std::string filename) ;
188  static
189  void readPNG(vpImage<vpRGBa> &I, const char *filename) ;
190  static
191  void readPNG(vpImage<vpRGBa> &I, const std::string filename) ;
192 #endif
193 
194  static
195  void writePFM(const vpImage<float> &I, const char *filename) ;
196 
197 
198 
199  static
200  void writePGM(const vpImage<unsigned char> &I, const char *filename) ;
201  static
202  void writePGM(const vpImage<unsigned char> &I, const std::string filename) ;
203  static
204  void writePGM(const vpImage<short> &I, const char *filename) ;
205  static
206  void writePGM(const vpImage<short> &I, const std::string filename) ;
207  static
208  void writePGM(const vpImage<vpRGBa> &I, const char *filename) ;
209  static
210  void writePGM(const vpImage<vpRGBa> &I, const std::string filename) ;
211 
212  static
213  void writePPM(const vpImage<unsigned char> &I, const char *filename) ;
214  static
215  void writePPM(const vpImage<unsigned char> &I, const std::string filename) ;
216  static
217  void writePPM(const vpImage<vpRGBa> &I, const char *filename) ;
218  static
219  void writePPM(const vpImage<vpRGBa> &I, const std::string filename) ;
220 
221 #if (defined(VISP_HAVE_LIBJPEG) || defined(VISP_HAVE_OPENCV))
222  static
223  void writeJPEG(const vpImage<unsigned char> &I, const char *filename) ;
224  static
225  void writeJPEG(const vpImage<unsigned char> &I, const std::string filename) ;
226  static
227  void writeJPEG(const vpImage<vpRGBa> &I, const char *filename) ;
228  static
229  void writeJPEG(const vpImage<vpRGBa> &I, const std::string filename) ;
230 #endif
231 
232 #if (defined(VISP_HAVE_LIBPNG) || defined(VISP_HAVE_OPENCV))
233  static
234  void writePNG(const vpImage<unsigned char> &I, const char *filename) ;
235  static
236  void writePNG(const vpImage<unsigned char> &I, const std::string filename) ;
237  static
238  void writePNG(const vpImage<vpRGBa> &I, const char *filename) ;
239  static
240  void writePNG(const vpImage<vpRGBa> &I, const std::string filename) ;
241 #endif
242 
243  } ;
244 #endif
245 
Read/write images with various image format.
Definition: vpImageIo.h:104