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