39 #include <visp3/core/vpIoTools.h>
40 #include <visp3/io/vpImageIo.h>
42 #include "private/vpImageIoBackend.h"
44 #ifdef ENABLE_VISP_NAMESPACE
48 vpImageIo::vpImageFormatType vpImageIo::getFormat(
const std::string &filename)
50 std::string ext = vpImageIo::getExtension(filename);
52 if (ext.compare(
".PGM") == 0)
54 else if (ext.compare(
".pgm") == 0)
56 else if (ext.compare(
".PPM") == 0)
58 else if (ext.compare(
".ppm") == 0)
60 else if (ext.compare(
".JPG") == 0)
62 else if (ext.compare(
".jpg") == 0)
64 else if (ext.compare(
".JPEG") == 0)
66 else if (ext.compare(
".jpeg") == 0)
68 else if (ext.compare(
".PNG") == 0)
70 else if (ext.compare(
".png") == 0)
73 else if (ext.compare(
".TIFF") == 0)
75 else if (ext.compare(
".tiff") == 0)
77 else if (ext.compare(
".TIF") == 0)
79 else if (ext.compare(
".tif") == 0)
81 else if (ext.compare(
".BMP") == 0)
83 else if (ext.compare(
".bmp") == 0)
85 else if (ext.compare(
".DIB") == 0)
87 else if (ext.compare(
".dib") == 0)
89 else if (ext.compare(
".PBM") == 0)
91 else if (ext.compare(
".pbm") == 0)
93 else if (ext.compare(
".SR") == 0)
95 else if (ext.compare(
".sr") == 0)
97 else if (ext.compare(
".RAS") == 0)
99 else if (ext.compare(
".ras") == 0)
100 return FORMAT_RASTER;
101 else if (ext.compare(
".JP2") == 0)
102 return FORMAT_JPEG2000;
103 else if (ext.compare(
".jp2") == 0)
104 return FORMAT_JPEG2000;
106 return FORMAT_UNKNOWN;
110 std::string vpImageIo::getExtension(
const std::string &filename)
113 size_t dot = filename.find_last_of(
".");
114 std::string ext = filename.substr(dot, filename.size() - 1);
151 const std::string message =
"Cannot read file: \"" + std::string(filename) +
"\" doesn't exist";
158 bool try_opencv_reader =
false;
160 switch (getFormat(final_filename)) {
162 readPGM(I, final_filename);
165 readPPM(I, final_filename);
168 readJPEG(I, final_filename, backend);
171 readPNG(I, final_filename, backend);
178 case FORMAT_JPEG2000:
180 try_opencv_reader =
true;
184 if (try_opencv_reader) {
185 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
186 readOpenCV(I, filename);
188 const std::string message =
"Cannot read file \"" + filename +
"\": No backend able to support this image format";
227 const std::string message =
"Cannot read file: \"" + std::string(filename) +
"\" doesn't exist";
233 bool try_opencv_reader =
false;
235 switch (getFormat(final_filename)) {
237 readPGM(I, final_filename);
240 readPPM(I, final_filename);
243 readJPEG(I, final_filename, backend);
246 readPNG(I, final_filename, backend);
253 case FORMAT_JPEG2000:
255 try_opencv_reader =
true;
259 if (try_opencv_reader) {
260 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
261 readOpenCV(I, filename);
263 const std::string message =
"Cannot read file \"" + filename +
"\": No backend able to support this image format";
293 bool try_opencv_writer =
false;
295 switch (getFormat(filename)) {
297 writePGM(I, filename);
300 writePPM(I, filename);
303 writeJPEG(I, filename, backend);
306 writePNG(I, filename, backend);
313 case FORMAT_JPEG2000:
315 try_opencv_writer =
true;
319 if (try_opencv_writer) {
320 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
321 writeOpenCV(I, filename, 90);
323 const std::string message =
"Cannot write file \"" + filename +
"\": No backend able to support this image format";
353 bool try_opencv_writer =
false;
355 switch (getFormat(filename)) {
357 writePGM(I, filename);
360 writePPM(I, filename);
363 writeJPEG(I, filename, backend);
366 writePNG(I, filename, backend);
373 case FORMAT_JPEG2000:
375 try_opencv_writer =
true;
379 if (try_opencv_writer) {
380 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
381 writeOpenCV(I, filename, 90);
383 const std::string message =
"Cannot write file \"" + filename +
"\": No backend able to support this image format";
401 if (backend == IO_SYSTEM_LIB_BACKEND) {
402 #if !defined(VISP_HAVE_JPEG)
404 backend = IO_STB_IMAGE_BACKEND;
407 else if (backend == IO_OPENCV_BACKEND) {
408 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
410 backend = IO_STB_IMAGE_BACKEND;
413 else if (backend == IO_DEFAULT_BACKEND) {
414 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
415 backend = IO_OPENCV_BACKEND;
416 #elif defined(VISP_HAVE_JPEG)
417 backend = IO_SYSTEM_LIB_BACKEND;
418 #elif defined(VISP_HAVE_SIMDLIB)
419 backend = IO_SIMDLIB_BACKEND;
420 #elif defined(VISP_HAVE_STBIMAGE)
421 backend = IO_STB_IMAGE_BACKEND;
425 const std::string message =
"Cannot read file \"" + filename +
"\": no backend available";
430 if (backend == IO_SYSTEM_LIB_BACKEND) {
431 #if defined(VISP_HAVE_JPEG)
432 readJPEGLibjpeg(I, filename);
436 const std::string message =
"Cannot read file \"" + filename +
"\": jpeg library backend is not available";
440 else if (backend == IO_OPENCV_BACKEND) {
441 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
442 readOpenCV(I, filename);
446 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV library backend is not available";
450 else if (backend == IO_STB_IMAGE_BACKEND) {
451 #if defined(VISP_HAVE_STBIMAGE)
452 readStb(I, filename);
456 const std::string message =
"Cannot read file \"" + filename +
"\": stb_image backend is not available";
460 else if (backend == IO_SIMDLIB_BACKEND) {
461 #if defined(VISP_HAVE_SIMDLIB)
462 readSimdlib(I, filename);
466 const std::string message =
"Cannot read file \"" + filename +
"\": Simd library backend is not available";
484 if (backend == IO_SYSTEM_LIB_BACKEND) {
485 #if !defined(VISP_HAVE_JPEG)
487 backend = IO_STB_IMAGE_BACKEND;
490 else if (backend == IO_OPENCV_BACKEND) {
491 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
493 backend = IO_STB_IMAGE_BACKEND;
496 else if (backend == IO_DEFAULT_BACKEND) {
497 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
498 backend = IO_OPENCV_BACKEND;
499 #elif defined(VISP_HAVE_JPEG)
500 backend = IO_SYSTEM_LIB_BACKEND;
501 #elif defined(VISP_HAVE_SIMDLIB)
502 backend = IO_SIMDLIB_BACKEND;
503 #elif defined(VISP_HAVE_STBIMAGE)
504 backend = IO_STB_IMAGE_BACKEND;
508 const std::string message =
"Cannot read file \"" + filename +
"\": no backend available";
513 if (backend == IO_SYSTEM_LIB_BACKEND) {
514 #if defined(VISP_HAVE_JPEG)
515 readJPEGLibjpeg(I, filename);
519 const std::string message =
"Cannot read file \"" + filename +
"\": jpeg library backend is not available";
523 else if (backend == IO_OPENCV_BACKEND) {
524 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
525 readOpenCV(I, filename);
529 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV library backend is not available";
533 else if (backend == IO_STB_IMAGE_BACKEND) {
534 #if defined(VISP_HAVE_STBIMAGE)
535 readStb(I, filename);
539 const std::string message =
"Cannot read file \"" + filename +
"\": stb_image backend is not available";
543 else if (backend == IO_SIMDLIB_BACKEND) {
544 #if defined(VISP_HAVE_SIMDLIB)
545 readSimdlib(I, filename);
549 const std::string message =
"Cannot read file \"" + filename +
"\": Simd library backend is not available";
567 if (backend == IO_SYSTEM_LIB_BACKEND) {
568 #if !defined(VISP_HAVE_PNG)
570 backend = IO_STB_IMAGE_BACKEND;
573 else if (backend == IO_OPENCV_BACKEND) {
574 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
576 backend = IO_STB_IMAGE_BACKEND;
579 else if (backend == IO_DEFAULT_BACKEND) {
580 #if defined(VISP_HAVE_PNG)
581 backend = IO_SYSTEM_LIB_BACKEND;
582 #elif defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
583 backend = IO_OPENCV_BACKEND;
584 #elif defined(VISP_HAVE_SIMDLIB)
585 backend = IO_SIMDLIB_BACKEND;
586 #elif defined(VISP_HAVE_STBIMAGE)
587 backend = IO_STB_IMAGE_BACKEND;
591 const std::string message =
"Cannot read file \"" + filename +
"\": no backend available";
596 if (backend == IO_SYSTEM_LIB_BACKEND) {
597 #if defined(VISP_HAVE_PNG)
598 readPNGLibpng(I, filename);
602 const std::string message =
"Cannot read file \"" + filename +
"\": png library backend is not available";
606 else if (backend == IO_OPENCV_BACKEND) {
607 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
608 readOpenCV(I, filename);
612 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV library backend is not available";
616 else if (backend == IO_STB_IMAGE_BACKEND) {
617 #if defined(VISP_HAVE_STBIMAGE)
618 readStb(I, filename);
622 const std::string message =
"Cannot read file \"" + filename +
"\": stb_image backend is not available";
626 else if (backend == IO_SIMDLIB_BACKEND) {
627 #if defined(VISP_HAVE_SIMDLIB)
628 readSimdlib(I, filename);
632 const std::string message =
"Cannot read file \"" + filename +
"\": Simd library backend is not available";
650 if (backend == IO_SYSTEM_LIB_BACKEND) {
651 #if !defined(VISP_HAVE_PNG)
653 backend = IO_STB_IMAGE_BACKEND;
656 else if (backend == IO_OPENCV_BACKEND) {
657 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
659 backend = IO_STB_IMAGE_BACKEND;
662 else if (backend == IO_DEFAULT_BACKEND) {
663 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
664 backend = IO_OPENCV_BACKEND;
665 #elif defined(VISP_HAVE_SIMDLIB)
666 backend = IO_SIMDLIB_BACKEND;
667 #elif defined(VISP_HAVE_STBIMAGE)
668 backend = IO_STB_IMAGE_BACKEND;
672 const std::string message =
"Cannot read file \"" + filename +
"\": no backend available";
677 if (backend == IO_SYSTEM_LIB_BACKEND) {
678 #if defined(VISP_HAVE_PNG)
679 readPNGLibpng(I, filename);
683 const std::string message =
"Cannot read file \"" + filename +
"\": png library backend is not available";
687 else if (backend == IO_OPENCV_BACKEND) {
688 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
689 readOpenCV(I, filename);
693 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV library backend is not available";
697 else if (backend == IO_STB_IMAGE_BACKEND) {
698 #if defined(VISP_HAVE_STBIMAGE)
699 readStb(I, filename);
703 const std::string message =
"Cannot read file \"" + filename +
"\": stb_image backend is not available";
707 else if (backend == IO_SIMDLIB_BACKEND) {
708 #if defined(VISP_HAVE_SIMDLIB)
709 readSimdlib(I, filename);
713 const std::string message =
"Cannot read file \"" + filename +
"\": Simd library backend is not available";
729 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND || backend == IO_STB_IMAGE_BACKEND) {
731 backend = IO_DEFAULT_BACKEND;
733 else if (backend == IO_OPENCV_BACKEND) {
734 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
736 backend = IO_DEFAULT_BACKEND;
739 else if (backend == IO_DEFAULT_BACKEND) {
740 #if !defined(VISP_HAVE_TINYEXR)
742 backend = IO_OPENCV_BACKEND;
746 if (backend == IO_OPENCV_BACKEND) {
747 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
748 readOpenCV(I, filename);
752 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV backend is not available";
756 else if (backend == IO_DEFAULT_BACKEND) {
757 #if defined(VISP_HAVE_TINYEXR)
758 readEXRTiny(I, filename);
762 const std::string message =
"Cannot read file \"" + filename +
"\": Default TinyEXR backend is not available";
778 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND || backend == IO_STB_IMAGE_BACKEND) {
780 backend = IO_DEFAULT_BACKEND;
782 else if (backend == IO_OPENCV_BACKEND) {
783 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
785 backend = IO_DEFAULT_BACKEND;
788 else if (backend == IO_DEFAULT_BACKEND) {
789 #if !defined(VISP_HAVE_TINYEXR)
791 backend = IO_OPENCV_BACKEND;
795 if (backend == IO_OPENCV_BACKEND) {
796 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
797 readOpenCV(I, filename);
801 const std::string message =
"Cannot read file \"" + filename +
"\": OpenCV backend is not available";
805 else if (backend == IO_DEFAULT_BACKEND) {
806 #if defined(VISP_HAVE_TINYEXR)
807 readEXRTiny(I, filename);
811 const std::string message =
"Cannot read file \"" + filename +
"\": TinyEXR backend is not available";
830 if (backend == IO_SYSTEM_LIB_BACKEND) {
831 #if !defined(VISP_HAVE_JPEG)
832 #if defined(VISP_HAVE_SIMDLIB)
834 backend = IO_SIMDLIB_BACKEND;
837 backend = IO_STB_IMAGE_BACKEND;
841 else if (backend == IO_OPENCV_BACKEND) {
842 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
843 #if defined(VISP_HAVE_SIMDLIB)
845 backend = IO_SIMDLIB_BACKEND;
848 backend = IO_STB_IMAGE_BACKEND;
852 else if (backend == IO_DEFAULT_BACKEND) {
853 #if defined(VISP_HAVE_JPEG)
854 backend = IO_SYSTEM_LIB_BACKEND;
855 #elif defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
856 backend = IO_OPENCV_BACKEND;
857 #elif defined(VISP_HAVE_SIMDLIB)
858 backend = IO_SIMDLIB_BACKEND;
859 #elif defined(VISP_HAVE_STBIMAGE)
860 backend = IO_STB_IMAGE_BACKEND;
864 const std::string message =
"Cannot save file \"" + filename +
"\": no available backend";
869 if (backend == IO_SYSTEM_LIB_BACKEND) {
870 #if defined(VISP_HAVE_JPEG)
871 writeJPEGLibjpeg(I, filename, quality);
876 const std::string message =
"Cannot save file \"" + filename +
"\": jpeg backend is not available";
880 else if (backend == IO_OPENCV_BACKEND) {
881 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) \
882 && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
883 writeOpenCV(I, filename, quality);
888 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV backend is not available";
892 else if (backend == IO_SIMDLIB_BACKEND) {
893 #if defined(VISP_HAVE_SIMDLIB)
894 writeJPEGSimdlib(I, filename, quality);
899 const std::string message =
"Cannot save file \"" + filename +
"\": Simd library backend is not available";
903 else if (backend == IO_STB_IMAGE_BACKEND) {
904 #if defined(VISP_HAVE_STBIMAGE)
905 writeJPEGStb(I, filename, quality);
910 const std::string message =
"Cannot save file \"" + filename +
"\": stb_image backend is not available";
929 if (backend == IO_SYSTEM_LIB_BACKEND) {
930 #if !defined(VISP_HAVE_JPEG)
931 #if defined(VISP_HAVE_SIMDLIB)
933 backend = IO_SIMDLIB_BACKEND;
936 backend = IO_STB_IMAGE_BACKEND;
940 else if (backend == IO_OPENCV_BACKEND) {
941 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
942 #if defined(VISP_HAVE_SIMDLIB)
944 backend = IO_SIMDLIB_BACKEND;
947 backend = IO_STB_IMAGE_BACKEND;
951 else if (backend == IO_DEFAULT_BACKEND) {
952 #if defined(VISP_HAVE_JPEG)
953 backend = IO_SYSTEM_LIB_BACKEND;
954 #elif defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
955 backend = IO_OPENCV_BACKEND;
956 #elif defined(VISP_HAVE_SIMDLIB)
957 backend = IO_SIMDLIB_BACKEND;
958 #elif defined(VISP_HAVE_STBIMAGE)
959 backend = IO_STB_IMAGE_BACKEND;
963 const std::string message =
"Cannot save file \"" + filename +
"\": no backend available";
968 if (backend == IO_SYSTEM_LIB_BACKEND) {
969 #if defined(VISP_HAVE_JPEG)
970 writeJPEGLibjpeg(I, filename, quality);
975 const std::string message =
"Cannot save file \"" + filename +
"\": jpeg library backend is not available";
979 else if (backend == IO_OPENCV_BACKEND) {
980 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
981 writeOpenCV(I, filename, quality);
986 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV library backend is not available";
990 else if (backend == IO_SIMDLIB_BACKEND) {
991 #if defined(VISP_HAVE_SIMDLIB)
992 writeJPEGSimdlib(I, filename, quality);
997 const std::string message =
"Cannot save file \"" + filename +
"\": Simd library backend is not available";
1001 else if (backend == IO_STB_IMAGE_BACKEND) {
1002 #if defined(VISP_HAVE_STBIMAGE)
1003 writeJPEGStb(I, filename, quality);
1008 const std::string message =
"Cannot save file \"" + filename +
"\": stb_image backend is not available";
1026 if (backend == IO_SYSTEM_LIB_BACKEND) {
1027 #if !defined(VISP_HAVE_PNG)
1028 #if defined(VISP_HAVE_SIMDLIB)
1030 backend = IO_SIMDLIB_BACKEND;
1033 backend = IO_STB_IMAGE_BACKEND;
1037 else if (backend == IO_OPENCV_BACKEND) {
1038 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1039 #if defined(VISP_HAVE_SIMDLIB)
1041 backend = IO_SIMDLIB_BACKEND;
1044 backend = IO_STB_IMAGE_BACKEND;
1048 else if (backend == IO_DEFAULT_BACKEND) {
1049 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1050 backend = IO_OPENCV_BACKEND;
1051 #elif defined(VISP_HAVE_SIMDLIB)
1052 backend = IO_SIMDLIB_BACKEND;
1053 #elif defined(VISP_HAVE_STBIMAGE)
1054 backend = IO_STB_IMAGE_BACKEND;
1058 const std::string message =
"Cannot save file \"" + filename +
"\": no backend available";
1063 if (backend == IO_OPENCV_BACKEND) {
1064 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1065 writeOpenCV(I, filename, 90);
1069 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV library backend is not available";
1073 else if (backend == IO_SIMDLIB_BACKEND) {
1074 #if defined(VISP_HAVE_SIMDLIB)
1075 writePNGSimdlib(I, filename);
1079 const std::string message =
"Cannot save file \"" + filename +
"\": Simd library backend is not available";
1083 else if (backend == IO_STB_IMAGE_BACKEND) {
1084 #if defined(VISP_HAVE_STBIMAGE)
1085 writePNGStb(I, filename);
1089 const std::string message =
"Cannot save file \"" + filename +
"\": stb_image backend is not available";
1093 else if (backend == IO_SYSTEM_LIB_BACKEND) {
1094 #if defined(VISP_HAVE_PNG)
1095 writePNGLibpng(I, filename);
1099 const std::string message =
"Cannot save file \"" + filename +
"\": png library backend is not available";
1117 if (backend == IO_SYSTEM_LIB_BACKEND) {
1118 #if !defined(VISP_HAVE_PNG)
1119 #if defined(VISP_HAVE_SIMDLIB)
1121 backend = IO_SIMDLIB_BACKEND;
1124 backend = IO_STB_IMAGE_BACKEND;
1128 else if (backend == IO_OPENCV_BACKEND) {
1129 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1130 #if defined(VISP_HAVE_SIMDLIB)
1132 backend = IO_SIMDLIB_BACKEND;
1135 backend = IO_STB_IMAGE_BACKEND;
1139 else if (backend == IO_DEFAULT_BACKEND) {
1140 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1141 backend = IO_OPENCV_BACKEND;
1142 #elif defined(VISP_HAVE_SIMDLIB)
1143 backend = IO_SIMDLIB_BACKEND;
1144 #elif defined(VISP_HAVE_STBIMAGE)
1145 backend = IO_STB_IMAGE_BACKEND;
1149 const std::string message =
"Cannot save file \"" + filename +
"\": no backend available";
1154 if (backend == IO_OPENCV_BACKEND) {
1155 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1156 writeOpenCV(I, filename, 90);
1160 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV backend is not available";
1164 else if (backend == IO_SIMDLIB_BACKEND) {
1165 #if defined(VISP_HAVE_SIMDLIB)
1166 writePNGSimdlib(I, filename);
1170 const std::string message =
"Cannot save file \"" + filename +
"\": Simd library backend is not available";
1174 else if (backend == IO_STB_IMAGE_BACKEND) {
1175 #if defined(VISP_HAVE_STBIMAGE)
1176 writePNGStb(I, filename);
1180 const std::string message =
"Cannot save file \"" + filename +
"\": stb_image backend is not available";
1184 else if (backend == IO_SYSTEM_LIB_BACKEND) {
1185 #if defined(VISP_HAVE_PNG)
1186 writePNGLibpng(I, filename);
1190 const std::string message =
"Cannot save file \"" + filename +
"\": libpng backend is not available";
1206 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND || backend == IO_STB_IMAGE_BACKEND) {
1208 backend = IO_DEFAULT_BACKEND;
1210 else if (backend == IO_OPENCV_BACKEND) {
1211 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1214 backend = IO_DEFAULT_BACKEND;
1217 else if (backend == IO_DEFAULT_BACKEND) {
1218 #if !defined(VISP_HAVE_TINYEXR)
1220 backend = IO_OPENCV_BACKEND;
1224 if (backend == IO_OPENCV_BACKEND) {
1225 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1226 writeOpenCV(I, filename);
1230 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV backend is not available";
1234 else if (backend == IO_DEFAULT_BACKEND) {
1235 #if defined(VISP_HAVE_TINYEXR)
1236 writeEXRTiny(I, filename);
1240 const std::string message =
"Cannot save file \"" + filename +
"\": TinyEXR backend is not available";
1256 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND || backend == IO_STB_IMAGE_BACKEND) {
1258 backend = IO_DEFAULT_BACKEND;
1260 else if (backend == IO_OPENCV_BACKEND) {
1261 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1263 backend = IO_DEFAULT_BACKEND;
1266 else if (backend == IO_DEFAULT_BACKEND) {
1267 #if !defined(VISP_HAVE_TINYEXR)
1269 backend = IO_OPENCV_BACKEND;
1273 if (backend == IO_OPENCV_BACKEND) {
1274 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1275 writeOpenCV(I, filename);
1279 const std::string message =
"Cannot save file \"" + filename +
"\": OpenCV backend is not available";
1283 else if (backend == IO_DEFAULT_BACKEND) {
1284 #if defined(VISP_HAVE_TINYEXR)
1285 writeEXRTiny(I, filename);
1289 const std::string message =
"Cannot save file \"" + filename +
"\": TinyEXR backend is not available";
1411 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND) {
1412 backend = IO_STB_IMAGE_BACKEND;
1414 else if (backend == IO_OPENCV_BACKEND) {
1415 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1416 backend = IO_STB_IMAGE_BACKEND;
1419 else if (backend == IO_DEFAULT_BACKEND) {
1420 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
1421 backend = IO_OPENCV_BACKEND;
1422 #elif defined(VISP_HAVE_STBIMAGE)
1423 backend = IO_STB_IMAGE_BACKEND;
1427 const std::string message =
"Cannot in-memory png read: OpenCV or std_image backend are not available";
1432 if (backend == IO_OPENCV_BACKEND) {
1433 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) \
1434 && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1435 readPNGfromMemOpenCV(buffer, I);
1441 const std::string message =
"Cannot in-memory png read: OpenCV backend is not available";
1446 #if defined(VISP_HAVE_STBIMAGE)
1447 readPNGfromMemStb(buffer, I);
1453 const std::string message =
"Cannot in-memory png read: std_image backend is not available";
1468 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND) {
1469 backend = IO_STB_IMAGE_BACKEND;
1471 else if (backend == IO_OPENCV_BACKEND) {
1472 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1473 backend = IO_STB_IMAGE_BACKEND;
1476 else if (backend == IO_DEFAULT_BACKEND) {
1477 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
1478 backend = IO_OPENCV_BACKEND;
1479 #elif defined(VISP_HAVE_STBIMAGE)
1480 backend = IO_STB_IMAGE_BACKEND;
1484 const std::string message =
"Cannot in-memory png read: OpenCV or std_image backend are not available";
1489 if (backend == IO_OPENCV_BACKEND) {
1490 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) \
1491 && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1492 readPNGfromMemOpenCV(buffer, I);
1498 const std::string message =
"Cannot in-memory png read: OpenCV backend is not available";
1503 #if defined(VISP_HAVE_STBIMAGE)
1504 readPNGfromMemStb(buffer, I);
1510 const std::string message =
"Cannot in-memory png read: std_image backend is not available";
1526 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND) {
1527 backend = IO_STB_IMAGE_BACKEND;
1529 else if (backend == IO_OPENCV_BACKEND) {
1530 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1531 backend = IO_STB_IMAGE_BACKEND;
1534 else if (backend == IO_DEFAULT_BACKEND) {
1535 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
1536 backend = IO_OPENCV_BACKEND;
1537 #elif defined(VISP_HAVE_STBIMAGE)
1538 backend = IO_STB_IMAGE_BACKEND;
1542 const std::string message =
"Cannot in-memory png write: OpenCV or std_image backend are not available";
1547 if (backend == IO_OPENCV_BACKEND) {
1548 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) \
1549 && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1550 writePNGtoMemOpenCV(I, buffer);
1554 const std::string message =
"Cannot in-memory png write: OpenCV backend is not available";
1558 else if (backend == IO_STB_IMAGE_BACKEND) {
1559 #if defined(VISP_HAVE_STBIMAGE)
1560 writePNGtoMemStb(I, buffer);
1564 const std::string message =
"Cannot in-memory png write: std_image backend is not available";
1569 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1570 const std::string message =
"The " + std::to_string(backend) +
" backend is not available.";
1589 if (backend == IO_SYSTEM_LIB_BACKEND || backend == IO_SIMDLIB_BACKEND) {
1590 backend = IO_STB_IMAGE_BACKEND;
1592 else if (backend == IO_OPENCV_BACKEND) {
1593 #if !(defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS))
1594 backend = IO_STB_IMAGE_BACKEND;
1597 else if (backend == IO_DEFAULT_BACKEND) {
1598 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS)
1599 backend = IO_OPENCV_BACKEND;
1600 #elif defined(VISP_HAVE_STBIMAGE)
1601 backend = IO_STB_IMAGE_BACKEND;
1605 const std::string message =
"Cannot in-memory png write: OpenCV or std_image backend are not available";
1610 if (backend == IO_OPENCV_BACKEND) {
1611 #if ((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_IMGCODECS)) || ((VISP_HAVE_OPENCV_VERSION < 0x030000) \
1612 && defined(HAVE_OPENCV_HIGHGUI) && defined(HAVE_OPENCV_IMGPROC))
1613 writePNGtoMemOpenCV(I, buffer, saveAlpha);
1617 const std::string message =
"Cannot in-memory png write: OpenCV backend is not available";
1621 else if (backend == IO_STB_IMAGE_BACKEND) {
1622 #if defined(VISP_HAVE_STBIMAGE)
1623 writePNGtoMemStb(I, buffer, saveAlpha);
1627 const std::string message =
"Cannot in-memory png write: std_image backend is not available";
1632 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1633 const std::string message =
"The " + std::to_string(backend) +
" backend is not available.";
Error that can be emitted by the vpImage class and its derivatives.
static void writePFM(const vpImage< float > &I, const std::string &filename)
static void readPGM(vpImage< unsigned char > &I, const std::string &filename)
static void writeJPEG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90)
static void readJPEG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void readPFM(vpImage< float > &I, const std::string &filename)
static void writePNG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void readPFM_HDR(vpImage< float > &I, const std::string &filename)
static void readPPM(vpImage< unsigned char > &I, const std::string &filename)
static void writePFM_HDR(const vpImage< float > &I, const std::string &filename)
static void readPNGfromMem(const std::vector< unsigned char > &buffer, vpImage< unsigned char > &I, int backend=IO_DEFAULT_BACKEND)
static void readEXR(vpImage< float > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void writePGM(const vpImage< unsigned char > &I, const std::string &filename)
static void writeEXR(const vpImage< float > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void writePNGtoMem(const vpImage< unsigned char > &I, std::vector< unsigned char > &buffer, int backend=IO_DEFAULT_BACKEND)
static void readPNG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void writePPM(const vpImage< unsigned char > &I, const std::string &filename)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)