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