Visual Servoing Platform  version 3.6.1 under development (2024-12-04)
vpImageIo.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software 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  * 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 https://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 
39 #ifndef VP_IMAGE_IO_H
40 #define VP_IMAGE_IO_H
41 
42 #include <visp3/core/vpImage.h>
43 #include <visp3/core/vpImageConvert.h>
44 
45 #include <iostream>
46 #include <stdio.h>
47 
48 BEGIN_VISP_NAMESPACE
49 
103 class VISP_EXPORT vpImageIo
104 {
105 private:
106  typedef enum
107  {
108  FORMAT_PGM,
109  FORMAT_PPM,
110  FORMAT_JPEG,
111  FORMAT_PNG,
112  // Formats supported by opencv
113  FORMAT_TIFF,
114  FORMAT_BMP,
115  FORMAT_DIB,
116  FORMAT_PBM,
117  FORMAT_RASTER,
118  FORMAT_JPEG2000,
119  FORMAT_UNKNOWN
120  } vpImageFormatType;
121 
122  static vpImageFormatType getFormat(const std::string &filename);
123  static std::string getExtension(const std::string &filename);
124 
125 public:
128  {
133  IO_STB_IMAGE_BACKEND
134  };
135 
136  static void read(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
137  static void read(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
138 
139  static void write(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
140  static void write(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
141 
142  static void readPFM(vpImage<float> &I, const std::string &filename);
143  static void readPFM_HDR(vpImage<float> &I, const std::string &filename);
144  static void readPFM_HDR(vpImage<vpRGBf> &I, const std::string &filename);
145 
146  static void readPGM(vpImage<unsigned char> &I, const std::string &filename);
147  static void readPGM(vpImage<vpRGBa> &I, const std::string &filename);
148 
149  static void readPPM(vpImage<unsigned char> &I, const std::string &filename);
150  static void readPPM(vpImage<vpRGBa> &I, const std::string &filename);
151 
152  static void readJPEG(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
153  static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
154 
155  static void readPNG(vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
156  static void readPNG(vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
157 
158  static void readEXR(vpImage<float> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
159  static void readEXR(vpImage<vpRGBf> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
160 
161  static void writePFM(const vpImage<float> &I, const std::string &filename);
162  static void writePFM_HDR(const vpImage<float> &I, const std::string &filename);
163  static void writePFM_HDR(const vpImage<vpRGBf> &I, const std::string &filename);
164 
165  static void writePGM(const vpImage<unsigned char> &I, const std::string &filename);
166  static void writePGM(const vpImage<short> &I, const std::string &filename);
167  static void writePGM(const vpImage<vpRGBa> &I, const std::string &filename);
168 
169  static void writePPM(const vpImage<unsigned char> &I, const std::string &filename);
170  static void writePPM(const vpImage<vpRGBa> &I, const std::string &filename);
171 
172  static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND,
173  int quality = 90);
174  static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND,
175  int quality = 90);
176 
177  static void writePNG(const vpImage<unsigned char> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
178  static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
179 
180  static void writeEXR(const vpImage<float> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
181  static void writeEXR(const vpImage<vpRGBf> &I, const std::string &filename, int backend = IO_DEFAULT_BACKEND);
182 
183  static void readPNGfromMem(const std::vector<unsigned char> &buffer, vpImage<unsigned char> &I,
184  int backend = IO_DEFAULT_BACKEND);
185  static void readPNGfromMem(const std::vector<unsigned char> &buffer, vpImage<vpRGBa> &I,
186  int backend = IO_DEFAULT_BACKEND);
187 
188  static void writePNGtoMem(const vpImage<unsigned char> &I, std::vector<unsigned char> &buffer,
189  int backend = IO_DEFAULT_BACKEND);
190  static void writePNGtoMem(const vpImage<vpRGBa> &I, std::vector<unsigned char> &buffer,
191  int backend = IO_DEFAULT_BACKEND, bool saveAlpha = false);
192 };
193 
194 END_VISP_NAMESPACE
195 
196 #endif
Read/write images with various image format.
Definition: vpImageIo.h:104
vpImageIoBackendType
Image IO backend for only jpeg and png formats image loading and saving.
Definition: vpImageIo.h:128
@ IO_DEFAULT_BACKEND
Default backend.
Definition: vpImageIo.h:129
@ IO_SIMDLIB_BACKEND
Use embedded simd library.
Definition: vpImageIo.h:132
@ IO_SYSTEM_LIB_BACKEND
Use system libraries like libpng or libjpeg-turbo.
Definition: vpImageIo.h:130
@ IO_OPENCV_BACKEND
Use OpenCV imgcodecs module.
Definition: vpImageIo.h:131