ViSP  2.9.0
vpImageIo.h
1 /****************************************************************************
2  *
3  * $Id: vpImageIo.h 4604 2014-01-21 14:15:23Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 #if defined(_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 
108 class VISP_EXPORT vpImageIo
109 {
110 
111 private:
112 
113  typedef enum
114  {
115  FORMAT_PGM,
116  FORMAT_PPM,
117  FORMAT_JPEG,
118  FORMAT_PNG,
119  // Formats supported by opencv
120  FORMAT_TIFF,
121  FORMAT_BMP,
122  FORMAT_DIB,
123  FORMAT_PBM,
124  FORMAT_RASTER,
125  FORMAT_JPEG2000,
126  FORMAT_UNKNOWN
127  } vpImageFormatType;
128 
129  static const int vpMAX_LEN;
130 
131  static FILE * openFileRead(const char *filename) ;
132  static FILE * openFileWrite(const char *filename, const char *mode="w") ;
133 
134  static FILE * openFileRead(const std::string filename) ;
135  static FILE * openFileWrite(const std::string filename,
136  const std::string mode="w") ;
137 
138  static vpImageFormatType getFormat(const char *filename) ;
139  static std::string getExtension(const std::string &filename);
140 
141 public:
142 
143  static
144  void read(vpImage<unsigned char> &I, const char *filename) ;
145  static
146  void read(vpImage<unsigned char> &I, const std::string filename) ;
147  static
148  void read(vpImage<vpRGBa> &I, const char *filename) ;
149  static
150  void read(vpImage<vpRGBa> &I, const std::string filename) ;
151 
152  static
153  void write(const vpImage<unsigned char> &I, const char *filename) ;
154  static
155  void write(const vpImage<unsigned char> &I, const std::string filename) ;
156  static
157  void write(const vpImage<vpRGBa> &I, const char *filename) ;
158  static
159  void write(const vpImage<vpRGBa> &I, const std::string filename) ;
160 
161  static
162  void readPFM(vpImage<float> &I, const char *filename) ;
163 
164 
165  static
166  void readPGM(vpImage<unsigned char> &I, const char *filename) ;
167  static
168  void readPGM(vpImage<unsigned char> &I, const std::string filename) ;
169  static
170  void readPGM(vpImage<vpRGBa> &I, const char *filename) ;
171  static
172  void readPGM(vpImage<vpRGBa> &I, const std::string filename) ;
173 
174  static
175  void readPPM(vpImage<unsigned char> &I, const char *filename) ;
176  static
177  void readPPM(vpImage<unsigned char> &I, const std::string filename) ;
178  static
179  void readPPM(vpImage<vpRGBa> &I, const char *filename) ;
180  static
181  void readPPM(vpImage<vpRGBa> &I, const std::string filename) ;
182 
183 #if (defined(VISP_HAVE_LIBJPEG) || defined(VISP_HAVE_OPENCV))
184  static
185  void readJPEG(vpImage<unsigned char> &I, const char *filename) ;
186  static
187  void readJPEG(vpImage<unsigned char> &I, const std::string filename) ;
188  static
189  void readJPEG(vpImage<vpRGBa> &I, const char *filename) ;
190  static
191  void readJPEG(vpImage<vpRGBa> &I, const std::string filename) ;
192 #endif
193 
194 #if (defined(VISP_HAVE_LIBPNG) || defined(VISP_HAVE_OPENCV))
195  static
196  void readPNG(vpImage<unsigned char> &I, const char *filename) ;
197  static
198  void readPNG(vpImage<unsigned char> &I, const std::string filename) ;
199  static
200  void readPNG(vpImage<vpRGBa> &I, const char *filename) ;
201  static
202  void readPNG(vpImage<vpRGBa> &I, const std::string filename) ;
203 #endif
204 
205  static
206  void writePFM(const vpImage<float> &I, const char *filename) ;
207 
208 
209 
210  static
211  void writePGM(const vpImage<unsigned char> &I, const char *filename) ;
212  static
213  void writePGM(const vpImage<unsigned char> &I, const std::string filename) ;
214  static
215  void writePGM(const vpImage<short> &I, const char *filename) ;
216  static
217  void writePGM(const vpImage<short> &I, const std::string filename) ;
218  static
219  void writePGM(const vpImage<vpRGBa> &I, const char *filename) ;
220  static
221  void writePGM(const vpImage<vpRGBa> &I, const std::string filename) ;
222 
223  static
224  void writePPM(const vpImage<unsigned char> &I, const char *filename) ;
225  static
226  void writePPM(const vpImage<unsigned char> &I, const std::string filename) ;
227  static
228  void writePPM(const vpImage<vpRGBa> &I, const char *filename) ;
229  static
230  void writePPM(const vpImage<vpRGBa> &I, const std::string filename) ;
231 
232 #if (defined(VISP_HAVE_LIBJPEG) || defined(VISP_HAVE_OPENCV))
233  static
234  void writeJPEG(const vpImage<unsigned char> &I, const char *filename) ;
235  static
236  void writeJPEG(const vpImage<unsigned char> &I, const std::string filename) ;
237  static
238  void writeJPEG(const vpImage<vpRGBa> &I, const char *filename) ;
239  static
240  void writeJPEG(const vpImage<vpRGBa> &I, const std::string filename) ;
241 #endif
242 
243 #if (defined(VISP_HAVE_LIBPNG) || defined(VISP_HAVE_OPENCV))
244  static
245  void writePNG(const vpImage<unsigned char> &I, const char *filename) ;
246  static
247  void writePNG(const vpImage<unsigned char> &I, const std::string filename) ;
248  static
249  void writePNG(const vpImage<vpRGBa> &I, const char *filename) ;
250  static
251  void writePNG(const vpImage<vpRGBa> &I, const std::string filename) ;
252 #endif
253 
254  } ;
255 #endif
256 
Read/write images with various image format.
Definition: vpImageIo.h:108