Visual Servoing Platform  version 3.5.1 under development (2022-07-07)
vpImageIo.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 #include <visp3/core/vpIoTools.h>
45 #include <visp3/io/vpImageIo.h>
46 
47 #include "private/vpImageIoBackend.h"
48 
49 vpImageIo::vpImageFormatType vpImageIo::getFormat(const std::string &filename)
50 {
51  std::string ext = vpImageIo::getExtension(filename);
52 
53  if (ext.compare(".PGM") == 0)
54  return FORMAT_PGM;
55  else if (ext.compare(".pgm") == 0)
56  return FORMAT_PGM;
57  else if (ext.compare(".PPM") == 0)
58  return FORMAT_PPM;
59  else if (ext.compare(".ppm") == 0)
60  return FORMAT_PPM;
61  else if (ext.compare(".JPG") == 0)
62  return FORMAT_JPEG;
63  else if (ext.compare(".jpg") == 0)
64  return FORMAT_JPEG;
65  else if (ext.compare(".JPEG") == 0)
66  return FORMAT_JPEG;
67  else if (ext.compare(".jpeg") == 0)
68  return FORMAT_JPEG;
69  else if (ext.compare(".PNG") == 0)
70  return FORMAT_PNG;
71  else if (ext.compare(".png") == 0)
72  return FORMAT_PNG;
73  // Formats supported by opencv
74  else if (ext.compare(".TIFF") == 0)
75  return FORMAT_TIFF;
76  else if (ext.compare(".tiff") == 0)
77  return FORMAT_TIFF;
78  else if (ext.compare(".TIF") == 0)
79  return FORMAT_TIFF;
80  else if (ext.compare(".tif") == 0)
81  return FORMAT_TIFF;
82  else if (ext.compare(".BMP") == 0)
83  return FORMAT_BMP;
84  else if (ext.compare(".bmp") == 0)
85  return FORMAT_BMP;
86  else if (ext.compare(".DIB") == 0)
87  return FORMAT_DIB;
88  else if (ext.compare(".dib") == 0)
89  return FORMAT_DIB;
90  else if (ext.compare(".PBM") == 0)
91  return FORMAT_PBM;
92  else if (ext.compare(".pbm") == 0)
93  return FORMAT_PBM;
94  else if (ext.compare(".SR") == 0)
95  return FORMAT_RASTER;
96  else if (ext.compare(".sr") == 0)
97  return FORMAT_RASTER;
98  else if (ext.compare(".RAS") == 0)
99  return FORMAT_RASTER;
100  else if (ext.compare(".ras") == 0)
101  return FORMAT_RASTER;
102  else if (ext.compare(".JP2") == 0)
103  return FORMAT_JPEG2000;
104  else if (ext.compare(".jp2") == 0)
105  return FORMAT_JPEG2000;
106  else
107  return FORMAT_UNKNOWN;
108 }
109 
110 // return the extension of the file including the dot
111 std::string vpImageIo::getExtension(const std::string &filename)
112 {
113  // extract the extension
114  size_t dot = filename.find_last_of(".");
115  std::string ext = filename.substr(dot, filename.size() - 1);
116  return ext;
117 }
118 
148 void vpImageIo::read(vpImage<unsigned char> &I, const std::string &filename, int backend)
149 {
150  bool exist = vpIoTools::checkFilename(filename);
151  if (!exist) {
152  std::string message = "Cannot read file: \"" + std::string(filename) + "\" doesn't exist";
154  }
155 
156  // Allows to use ~ symbol or env variables in path
157  std::string final_filename = vpIoTools::path(filename);
158 
159  bool try_opencv_reader = false;
160 
161  switch (getFormat(final_filename)) {
162  case FORMAT_PGM:
163  readPGM(I, final_filename);
164  break;
165  case FORMAT_PPM:
166  readPPM(I, final_filename);
167  break;
168  case FORMAT_JPEG:
169  readJPEG(I, final_filename, backend);
170  break;
171  case FORMAT_PNG:
172  readPNG(I, final_filename, backend);
173  break;
174  case FORMAT_TIFF:
175  case FORMAT_BMP:
176  case FORMAT_DIB:
177  case FORMAT_PBM:
178  case FORMAT_RASTER:
179  case FORMAT_JPEG2000:
180  case FORMAT_UNKNOWN:
181  try_opencv_reader = true;
182  break;
183  }
184 
185  if (try_opencv_reader) {
186 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
187  readOpenCV(I, filename);
188 #else
189  std::string message = "Cannot read file \"" + filename + "\": No backend able to support this image format";
191 #endif
192  }
193 }
194 
224 void vpImageIo::read(vpImage<vpRGBa> &I, const std::string &filename, int backend)
225 {
226  bool exist = vpIoTools::checkFilename(filename);
227  if (!exist) {
228  std::string message = "Cannot read file: \"" + std::string(filename) + "\" doesn't exist";
230  }
231  // Allows to use ~ symbol or env variables in path
232  std::string final_filename = vpIoTools::path(filename);
233 
234  bool try_opencv_reader = false;
235 
236  switch (getFormat(final_filename)) {
237  case FORMAT_PGM:
238  readPGM(I, final_filename);
239  break;
240  case FORMAT_PPM:
241  readPPM(I, final_filename);
242  break;
243  case FORMAT_JPEG:
244  readJPEG(I, final_filename, backend);
245  break;
246  case FORMAT_PNG:
247  readPNG(I, final_filename, backend);
248  break;
249  case FORMAT_TIFF:
250  case FORMAT_BMP:
251  case FORMAT_DIB:
252  case FORMAT_PBM:
253  case FORMAT_RASTER:
254  case FORMAT_JPEG2000:
255  case FORMAT_UNKNOWN:
256  try_opencv_reader = true;
257  break;
258  }
259 
260  if (try_opencv_reader) {
261 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
262  readOpenCV(I, filename);
263 #else
264  std::string message = "Cannot read file \"" + filename + "\": No backend able to support this image format";
266 #endif
267  }
268 }
269 
292 void vpImageIo::write(const vpImage<unsigned char> &I, const std::string &filename, int backend)
293 {
294  bool try_opencv_writer = false;
295 
296  switch (getFormat(filename)) {
297  case FORMAT_PGM:
298  writePGM(I, filename);
299  break;
300  case FORMAT_PPM:
301  writePPM(I, filename);
302  break;
303  case FORMAT_JPEG:
304  writeJPEG(I, filename, backend);
305  break;
306  case FORMAT_PNG:
307  writePNG(I, filename, backend);
308  break;
309  case FORMAT_TIFF:
310  case FORMAT_BMP:
311  case FORMAT_DIB:
312  case FORMAT_PBM:
313  case FORMAT_RASTER:
314  case FORMAT_JPEG2000:
315  case FORMAT_UNKNOWN:
316  try_opencv_writer = true;
317  break;
318  }
319 
320  if (try_opencv_writer) {
321 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
322  writeOpenCV(I, filename, 90);
323 #else
324  std::string message = "Cannot write file \"" + filename + "\": No backend able to support this image format";
326 #endif
327  }
328 }
329 
352 void vpImageIo::write(const vpImage<vpRGBa> &I, const std::string &filename, int backend)
353 {
354  bool try_opencv_writer = false;
355 
356  switch (getFormat(filename)) {
357  case FORMAT_PGM:
358  writePGM(I, filename);
359  break;
360  case FORMAT_PPM:
361  writePPM(I, filename);
362  break;
363  case FORMAT_JPEG:
364  writeJPEG(I, filename, backend);
365  break;
366  case FORMAT_PNG:
367  writePNG(I, filename, backend);
368  break;
369  case FORMAT_TIFF:
370  case FORMAT_BMP:
371  case FORMAT_DIB:
372  case FORMAT_PBM:
373  case FORMAT_RASTER:
374  case FORMAT_JPEG2000:
375  case FORMAT_UNKNOWN:
376  try_opencv_writer = true;
377  break;
378  }
379 
380  if (try_opencv_writer) {
381 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
382  writeOpenCV(I, filename, 90);
383 #else
384  std::string message = "Cannot write file \"" + filename + "\": No backend able to support this image format";
386 #endif
387  }
388 }
389 
398 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
399 // Default: 1. opencv, 2. system, 3. stb_image
400 void vpImageIo::readJPEG(vpImage<unsigned char> &I, const std::string &filename, int backend)
401 {
402  if (backend == IO_SYSTEM_LIB_BACKEND) {
403 #if !defined(VISP_HAVE_JPEG)
404  std::string message =
405  "Libjpeg backend is not available to read file \"" + filename + "\": switch to stb_image backend";
406  backend = IO_STB_IMAGE_BACKEND;
407 #endif
408  } else if (backend == IO_OPENCV_BACKEND) {
409 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
410  std::string message =
411  "OpenCV backend is not available to read file \"" + filename + "\": switch to stb_image backend";
412  backend = IO_STB_IMAGE_BACKEND;
413 #endif
414  } else if (backend == IO_DEFAULT_BACKEND) {
415 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
416  backend = IO_OPENCV_BACKEND;
417 #elif defined(VISP_HAVE_JPEG)
418  backend = IO_SYSTEM_LIB_BACKEND;
419 #else
420  backend = IO_STB_IMAGE_BACKEND;
421 #endif
422  }
423 
424  if (backend == IO_SYSTEM_LIB_BACKEND) {
425 #if defined(VISP_HAVE_JPEG)
426  readJPEGLibjpeg(I, filename);
427 #endif
428  } else if (backend == IO_OPENCV_BACKEND) {
429 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
430  readOpenCV(I, filename);
431 #endif
432  } else if (backend == IO_STB_IMAGE_BACKEND) {
433  readStb(I, filename);
434  } else if (backend == IO_SIMDLIB_BACKEND) {
435  readSimdlib(I, filename);
436  }
437 }
438 
447 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
448 // Default: 1. opencv, 2. system, 3. stb_image
449 void vpImageIo::readJPEG(vpImage<vpRGBa> &I, const std::string &filename, int backend)
450 {
451  if (backend == IO_SYSTEM_LIB_BACKEND) {
452 #if !defined(VISP_HAVE_JPEG)
453  std::string message =
454  "Libjpeg backend is not available to read file \"" + filename + "\": switch to stb_image backend";
455  backend = IO_STB_IMAGE_BACKEND;
456 #endif
457  } else if (backend == IO_OPENCV_BACKEND) {
458 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
459  std::string message =
460  "OpenCV backend is not available to read file \"" + filename + "\": switch to stb_image backend";
461  backend = IO_STB_IMAGE_BACKEND;
462 #endif
463  } else if (backend == IO_DEFAULT_BACKEND) {
464 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
465  backend = IO_OPENCV_BACKEND;
466 #elif defined(VISP_HAVE_JPEG)
467  backend = IO_SYSTEM_LIB_BACKEND;
468 #else
469  backend = IO_STB_IMAGE_BACKEND;
470 #endif
471  }
472 
473  if (backend == IO_SYSTEM_LIB_BACKEND) {
474 #if defined(VISP_HAVE_JPEG)
475  readJPEGLibjpeg(I, filename);
476 #endif
477  } else if (backend == IO_OPENCV_BACKEND) {
478 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
479  readOpenCV(I, filename);
480 #endif
481  } else if (backend == IO_STB_IMAGE_BACKEND) {
482  readStb(I, filename);
483  } else if (backend == IO_SIMDLIB_BACKEND) {
484  readSimdlib(I, filename);
485  }
486 }
487 
496 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
497 // Default: 1. system, 2. opencv, 3. stb_image
498 void vpImageIo::readPNG(vpImage<unsigned char> &I, const std::string &filename, int backend)
499 {
500  if (backend == IO_SYSTEM_LIB_BACKEND) {
501 #if !defined(VISP_HAVE_PNG)
502  std::string message =
503  "Libpng backend is not available to read file \"" + filename + "\": switch to stb_image backend";
504  backend = IO_STB_IMAGE_BACKEND;
505 #endif
506  } else if (backend == IO_OPENCV_BACKEND) {
507 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
508  std::string message =
509  "OpenCV backend is not available to read file \"" + filename + "\": switch to stb_image backend";
510  backend = IO_STB_IMAGE_BACKEND;
511 #endif
512  } else if (backend == IO_DEFAULT_BACKEND) {
513 #if defined(VISP_HAVE_PNG)
514  backend = IO_SYSTEM_LIB_BACKEND;
515 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
516  backend = IO_OPENCV_BACKEND;
517 #else
518  backend = IO_STB_IMAGE_BACKEND;
519 #endif
520  }
521 
522  if (backend == IO_SYSTEM_LIB_BACKEND) {
523 #if defined(VISP_HAVE_PNG)
524  readPNGLibpng(I, filename);
525 #endif
526  } else if (backend == IO_OPENCV_BACKEND) {
527 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
528  readOpenCV(I, filename);
529 #endif
530  } else if (backend == IO_STB_IMAGE_BACKEND) {
531  readStb(I, filename);
532  } else if (backend == IO_SIMDLIB_BACKEND) {
533  readSimdlib(I, filename);
534  }
535 }
536 
545 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
546 // Default: 1. opencv, 2. stb_image
547 void vpImageIo::readPNG(vpImage<vpRGBa> &I, const std::string &filename, int backend)
548 {
549  if (backend == IO_SYSTEM_LIB_BACKEND) {
550 #if !defined(VISP_HAVE_PNG)
551  std::string message =
552  "Libpng backend is not available to read file \"" + filename + "\": switch to stb_image backend";
553  backend = IO_STB_IMAGE_BACKEND;
554 #endif
555  } else if (backend == IO_OPENCV_BACKEND) {
556 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
557  std::string message =
558  "OpenCV backend is not available to read file \"" + filename + "\": switch to stb_image backend";
559  backend = IO_STB_IMAGE_BACKEND;
560 #endif
561  } else if (backend == IO_DEFAULT_BACKEND) {
562 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
563  backend = IO_OPENCV_BACKEND;
564 #else
565  backend = IO_STB_IMAGE_BACKEND;
566 #endif
567  }
568 
569  if (backend == IO_SYSTEM_LIB_BACKEND) {
570 #if defined(VISP_HAVE_PNG)
571  readPNGLibpng(I, filename);
572 #endif
573  } else if (backend == IO_OPENCV_BACKEND) {
574 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
575  readOpenCV(I, filename);
576 #endif
577  } else if (backend == IO_STB_IMAGE_BACKEND) {
578  readStb(I, filename);
579  } else if (backend == IO_SIMDLIB_BACKEND) {
580  readSimdlib(I, filename);
581  }
582 }
583 
593 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
594 // Default: 1. system, 2. opencv, 3. simd
595 void vpImageIo::writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int backend, int quality)
596 {
597  if (backend == IO_SYSTEM_LIB_BACKEND) {
598 #if !defined(VISP_HAVE_JPEG)
599  std::string message = "Libjpeg backend is not available to save file \"" + filename + "\": switch to simd backend";
600  backend = IO_SIMDLIB_BACKEND;
601 #endif
602  } else if (backend == IO_OPENCV_BACKEND) {
603 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
604  std::string message = "OpenCV backend is not available to save file \"" + filename + "\": switch to simd backend";
605  backend = IO_SIMDLIB_BACKEND;
606 #endif
607  } else if (backend == IO_DEFAULT_BACKEND) {
608 #if defined(VISP_HAVE_JPEG)
609  backend = IO_SYSTEM_LIB_BACKEND;
610 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
611  backend = IO_OPENCV_BACKEND;
612 #else
613  backend = IO_SIMDLIB_BACKEND;
614 #endif
615  }
616 
617  if (backend == IO_SYSTEM_LIB_BACKEND) {
618 #if defined(VISP_HAVE_JPEG)
619  writeJPEGLibjpeg(I, filename, quality);
620 #endif
621  } else if (backend == IO_OPENCV_BACKEND) {
622 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
623  writeOpenCV(I, filename, quality);
624 #endif
625  } else if (backend == IO_SIMDLIB_BACKEND) {
626  writeJPEGSimdlib(I, filename, quality);
627  } else if (backend == IO_STB_IMAGE_BACKEND) {
628  writeJPEGStb(I, filename, quality);
629  }
630 }
631 
641 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
642 // Default: 1. system, 2. opencv, , 3. simd
643 void vpImageIo::writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int backend, int quality)
644 {
645  if (backend == IO_SYSTEM_LIB_BACKEND) {
646 #if !defined(VISP_HAVE_JPEG)
647  std::string message = "Libjpeg backend is not available to save file \"" + filename + "\": switch to simd backend";
648  backend = IO_SIMDLIB_BACKEND;
649 #endif
650  } else if (backend == IO_OPENCV_BACKEND) {
651 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
652  std::string message = "OpenCV backend is not available to save file \"" + filename + "\": switch to simd backend";
653  backend = IO_SIMDLIB_BACKEND;
654 #endif
655  } else if (backend == IO_DEFAULT_BACKEND) {
656 #if defined(VISP_HAVE_JPEG)
657  backend = IO_SYSTEM_LIB_BACKEND;
658 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
659  backend = IO_OPENCV_BACKEND;
660 #else
661  backend = IO_SIMDLIB_BACKEND;
662 #endif
663  }
664 
665  if (backend == IO_SYSTEM_LIB_BACKEND) {
666 #if defined(VISP_HAVE_JPEG)
667  writeJPEGLibjpeg(I, filename, quality);
668 #endif
669  } else if (backend == IO_OPENCV_BACKEND) {
670 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
671  writeOpenCV(I, filename, quality);
672 #endif
673  } else if (backend == IO_SIMDLIB_BACKEND) {
674  writeJPEGSimdlib(I, filename, quality);
675  } else if (backend == IO_STB_IMAGE_BACKEND) {
676  writeJPEGStb(I, filename, quality);
677  }
678 }
679 
688 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
689 // Default: 1. opencv, 2. simd
690 void vpImageIo::writePNG(const vpImage<unsigned char> &I, const std::string &filename, int backend)
691 {
692  if (backend == IO_SYSTEM_LIB_BACKEND) {
693 #if !defined(VISP_HAVE_PNG)
694  std::string message = "Libpng backend is not available to save file \"" + filename + "\": switch to simd backend";
695  backend = IO_SIMDLIB_BACKEND;
696 #endif
697  } else if (backend == IO_OPENCV_BACKEND) {
698 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
699  std::string message = "OpenCV backend is not available to save file \"" + filename + "\": switch to simd backend";
700  backend = IO_SIMDLIB_BACKEND;
701 #endif
702  } else if (backend == IO_DEFAULT_BACKEND) {
703 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
704  backend = IO_OPENCV_BACKEND;
705 #else
706  backend = IO_SIMDLIB_BACKEND;
707 #endif
708  }
709 
710  if (backend == IO_OPENCV_BACKEND) {
711 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
712  writeOpenCV(I, filename, 90);
713 #endif
714  } else if (backend == IO_SIMDLIB_BACKEND) {
715  writePNGSimdlib(I, filename);
716  } else if (backend == IO_STB_IMAGE_BACKEND) {
717  writePNGStb(I, filename);
718  } else if (backend == IO_SYSTEM_LIB_BACKEND) {
719 #if defined(VISP_HAVE_PNG)
720  writePNGLibpng(I, filename);
721 #endif
722  }
723 }
724 
733 // Strategy based on benchmark: see https://github.com/lagadic/visp/pull/1004
734 // Default: 1. opencv, 2. system, 3. simd
735 void vpImageIo::writePNG(const vpImage<vpRGBa> &I, const std::string &filename, int backend)
736 {
737  if (backend == IO_SYSTEM_LIB_BACKEND) {
738 #if !defined(VISP_HAVE_PNG)
739  std::string message = "Libpng backend is not available to save file \"" + filename + "\": switch to simd backend";
740  backend = IO_SIMDLIB_BACKEND;
741 #endif
742  } else if (backend == IO_OPENCV_BACKEND) {
743 #if !(defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100)
744  std::string message = "OpenCV backend is not available to save file \"" + filename + "\": switch to simd backend";
745  backend = IO_SIMDLIB_BACKEND;
746 #endif
747  } else if (backend == IO_DEFAULT_BACKEND) {
748 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
749  backend = IO_OPENCV_BACKEND;
750 #else
751  backend = IO_SIMDLIB_BACKEND;
752 #endif
753  }
754 
755  if (backend == IO_OPENCV_BACKEND) {
756 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100
757  writeOpenCV(I, filename, 90);
758 #endif
759  } else if (backend == IO_SIMDLIB_BACKEND) {
760  writePNGSimdlib(I, filename);
761  } else if (backend == IO_STB_IMAGE_BACKEND) {
762  writePNGStb(I, filename);
763  } else if (backend == IO_SYSTEM_LIB_BACKEND) {
764 #if defined(VISP_HAVE_PNG)
765  writePNGLibpng(I, filename);
766 #endif
767  }
768 }
769 
775 void vpImageIo::writePFM(const vpImage<float> &I, const std::string &filename) { vp_writePFM(I, filename); }
776 
782 void vpImageIo::writePGM(const vpImage<unsigned char> &I, const std::string &filename) { vp_writePGM(I, filename); }
783 
789 void vpImageIo::writePGM(const vpImage<short> &I, const std::string &filename) { vp_writePGM(I, filename); }
790 
796 void vpImageIo::writePGM(const vpImage<vpRGBa> &I, const std::string &filename) { vp_writePGM(I, filename); }
797 
803 void vpImageIo::readPFM(vpImage<float> &I, const std::string &filename) { vp_readPFM(I, filename); }
804 
810 void vpImageIo::readPGM(vpImage<unsigned char> &I, const std::string &filename) { vp_readPGM(I, filename); }
811 
817 void vpImageIo::readPGM(vpImage<vpRGBa> &I, const std::string &filename) { vp_readPGM(I, filename); }
818 
824 void vpImageIo::readPPM(vpImage<unsigned char> &I, const std::string &filename) { vp_readPPM(I, filename); }
825 
831 void vpImageIo::readPPM(vpImage<vpRGBa> &I, const std::string &filename) { vp_readPPM(I, filename); }
832 
838 void vpImageIo::writePPM(const vpImage<unsigned char> &I, const std::string &filename) { vp_writePPM(I, filename); }
839 
845 void vpImageIo::writePPM(const vpImage<vpRGBa> &I, const std::string &filename) { vp_writePPM(I, filename); }
Error that can be emited by the vpImage class and its derivates.
static void writePFM(const vpImage< float > &I, const std::string &filename)
Definition: vpImageIo.cpp:775
static void readPGM(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:810
@ IO_STB_IMAGE_BACKEND
Use embedded stb_image library.
Definition: vpImageIo.h:132
@ IO_DEFAULT_BACKEND
Default backend.
Definition: vpImageIo.h:128
@ IO_SIMDLIB_BACKEND
Use embedded simd library.
Definition: vpImageIo.h:131
@ IO_SYSTEM_LIB_BACKEND
Use system libraries like libpng or libjpeg.
Definition: vpImageIo.h:129
@ IO_OPENCV_BACKEND
Use OpenCV.
Definition: vpImageIo.h:130
static void writeJPEG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90)
Definition: vpImageIo.cpp:595
static void readJPEG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:400
static void readPFM(vpImage< float > &I, const std::string &filename)
Definition: vpImageIo.cpp:803
static void writePNG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:690
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:148
static void readPPM(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:824
static void writePGM(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:782
static void readPNG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:498
static void writePPM(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:838
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:292
static std::string path(const std::string &pathname)
Definition: vpIoTools.cpp:1006
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:800