Visual Servoing Platform  version 3.1.0
vpImageIo.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Read/write images.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #ifndef vpIMAGEIO_H
45 #define vpIMAGEIO_H
46 
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImageConvert.h>
50 #include <visp3/core/vpRGBa.h>
51 
52 #include <iostream>
53 #include <stdio.h>
54 
55 #if defined(_WIN32)
56 // Include WinSock2.h before windows.h to ensure that winsock.h is not
57 // included by windows.h since winsock.h and winsock2.h are incompatible
58 #include <WinSock2.h>
59 #include <windows.h>
60 #endif
61 
62 #if defined(VISP_HAVE_JPEG)
63 #include <jerror.h>
64 #include <jpeglib.h>
65 #endif
66 
67 #if defined(VISP_HAVE_PNG)
68 #include <png.h>
69 #endif
70 
120 class VISP_EXPORT vpImageIo
121 {
122 
123 private:
124  typedef enum {
125  FORMAT_PGM,
126  FORMAT_PPM,
127  FORMAT_JPEG,
128  FORMAT_PNG,
129  // Formats supported by opencv
130  FORMAT_TIFF,
131  FORMAT_BMP,
132  FORMAT_DIB,
133  FORMAT_PBM,
134  FORMAT_RASTER,
135  FORMAT_JPEG2000,
136  FORMAT_UNKNOWN
137  } vpImageFormatType;
138 
139  static vpImageFormatType getFormat(const std::string &filename);
140  static std::string getExtension(const std::string &filename);
141 
142 public:
143  static void read(vpImage<unsigned char> &I, const std::string &filename);
144  static void read(vpImage<vpRGBa> &I, const std::string &filename);
145 
146  static void write(const vpImage<unsigned char> &I, const std::string &filename);
147  static void write(const vpImage<vpRGBa> &I, const std::string &filename);
148 
149  static void readPFM(vpImage<float> &I, const std::string &filename);
150 
151  static void readPGM(vpImage<unsigned char> &I, const std::string &filename);
152  static void readPGM(vpImage<vpRGBa> &I, const std::string &filename);
153 
154  static void readPPM(vpImage<unsigned char> &I, const std::string &filename);
155  static void readPPM(vpImage<vpRGBa> &I, const std::string &filename);
156 
157 #if (defined(VISP_HAVE_JPEG) || defined(VISP_HAVE_OPENCV))
158  static void readJPEG(vpImage<unsigned char> &I, const std::string &filename);
159  static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename);
160 #endif
161 
162 #if (defined(VISP_HAVE_PNG) || defined(VISP_HAVE_OPENCV))
163  static void readPNG(vpImage<unsigned char> &I, const std::string &filename);
164  static void readPNG(vpImage<vpRGBa> &I, const std::string &filename);
165 #endif
166 
167  static void writePFM(const vpImage<float> &I, const std::string &filename);
168 
169  static void writePGM(const vpImage<unsigned char> &I, const std::string &filename);
170  static void writePGM(const vpImage<short> &I, const std::string &filename);
171  static void writePGM(const vpImage<vpRGBa> &I, const std::string &filename);
172 
173  static void writePPM(const vpImage<unsigned char> &I, const std::string &filename);
174  static void writePPM(const vpImage<vpRGBa> &I, const std::string &filename);
175 
176 #if (defined(VISP_HAVE_JPEG) || defined(VISP_HAVE_OPENCV))
177  static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename);
178  static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename);
179 #endif
180 
181 #if (defined(VISP_HAVE_PNG) || defined(VISP_HAVE_OPENCV))
182  static void writePNG(const vpImage<unsigned char> &I, const std::string &filename);
183  static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename);
184 #endif
185 };
186 #endif
Read/write images with various image format.
Definition: vpImageIo.h:120