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