44 #include <visp3/core/vpIoTools.h> 45 #include <visp3/io/vpImageIo.h> 47 #include "private/vpImageIoBackend.h" 50 vpImageIo::vpImageFormatType vpImageIo::getFormat(
const std::string &filename)
52 std::string ext = vpImageIo::getExtension(filename);
54 if (ext.compare(
".PGM") == 0)
56 else if (ext.compare(
".pgm") == 0)
58 else if (ext.compare(
".PPM") == 0)
60 else if (ext.compare(
".ppm") == 0)
62 else if (ext.compare(
".JPG") == 0)
64 else if (ext.compare(
".jpg") == 0)
66 else if (ext.compare(
".JPEG") == 0)
68 else if (ext.compare(
".jpeg") == 0)
70 else if (ext.compare(
".PNG") == 0)
72 else if (ext.compare(
".png") == 0)
75 else if (ext.compare(
".TIFF") == 0)
77 else if (ext.compare(
".tiff") == 0)
79 else if (ext.compare(
".TIF") == 0)
81 else if (ext.compare(
".tif") == 0)
83 else if (ext.compare(
".BMP") == 0)
85 else if (ext.compare(
".bmp") == 0)
87 else if (ext.compare(
".DIB") == 0)
89 else if (ext.compare(
".dib") == 0)
91 else if (ext.compare(
".PBM") == 0)
93 else if (ext.compare(
".pbm") == 0)
95 else if (ext.compare(
".SR") == 0)
97 else if (ext.compare(
".sr") == 0)
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;
108 return FORMAT_UNKNOWN;
112 std::string vpImageIo::getExtension(
const std::string &filename)
115 size_t dot = filename.find_last_of(
".");
116 std::string ext = filename.substr(dot, filename.size() - 1);
153 std::string message =
"Cannot read file: \"" + std::string(filename) +
"\" doesn't exist";
160 bool try_opencv_reader =
false;
162 switch (getFormat(final_filename)) {
170 readJPEG(I, final_filename, backend);
173 readPNG(I, final_filename, backend);
180 case FORMAT_JPEG2000:
182 try_opencv_reader =
true;
186 if (try_opencv_reader) {
187 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 188 readOpenCV(I, filename);
190 std::string message =
"Cannot read file \"" + filename +
"\": No backend able to support this image format";
229 std::string message =
"Cannot read file: \"" + std::string(filename) +
"\" doesn't exist";
235 bool try_opencv_reader =
false;
237 switch (getFormat(final_filename)) {
245 readJPEG(I, final_filename, backend);
248 readPNG(I, final_filename, backend);
255 case FORMAT_JPEG2000:
257 try_opencv_reader =
true;
261 if (try_opencv_reader) {
262 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 263 readOpenCV(I, filename);
265 std::string message =
"Cannot read file \"" + filename +
"\": No backend able to support this image format";
295 bool try_opencv_writer =
false;
297 switch (getFormat(filename)) {
315 case FORMAT_JPEG2000:
317 try_opencv_writer =
true;
321 if (try_opencv_writer) {
322 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 323 writeOpenCV(I, filename, 90);
325 std::string message =
"Cannot write file \"" + filename +
"\": No backend able to support this image format";
355 bool try_opencv_writer =
false;
357 switch (getFormat(filename)) {
375 case FORMAT_JPEG2000:
377 try_opencv_writer =
true;
381 if (try_opencv_writer) {
382 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 383 writeOpenCV(I, filename, 90);
385 std::string message =
"Cannot write file \"" + filename +
"\": No backend able to support this image format";
404 #if !defined(VISP_HAVE_JPEG) 405 std::string message =
"Libjpeg backend is not available to read file \"" + filename +
"\": switch to stb_image 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";
416 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 418 #elif defined(VISP_HAVE_JPEG) 426 #if defined(VISP_HAVE_JPEG) 427 readJPEGLibjpeg(I, filename);
430 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 431 readOpenCV(I, filename);
434 readStb(I, filename);
436 readSimdlib(I, filename);
453 #if !defined(VISP_HAVE_JPEG) 454 std::string message =
"Libjpeg backend is not available to read file \"" + filename +
"\": switch to stb_image 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";
465 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 467 #elif defined(VISP_HAVE_JPEG) 475 #if defined(VISP_HAVE_JPEG) 476 readJPEGLibjpeg(I, filename);
479 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 480 readOpenCV(I, filename);
483 readStb(I, filename);
485 readSimdlib(I, filename);
502 #if !defined(VISP_HAVE_PNG) 503 std::string message =
"Libpng backend is not available to read file \"" + filename +
"\": switch to stb_image 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";
514 #if defined(VISP_HAVE_PNG) 516 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 524 #if defined(VISP_HAVE_PNG) 525 readPNGLibpng(I, filename);
528 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 529 readOpenCV(I, filename);
532 readStb(I, filename);
534 readSimdlib(I, filename);
551 #if !defined(VISP_HAVE_PNG) 552 std::string message =
"Libpng backend is not available to read file \"" + filename +
"\": switch to stb_image 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";
563 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 571 #if defined(VISP_HAVE_PNG) 572 readPNGLibpng(I, filename);
575 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 576 readOpenCV(I, filename);
579 readStb(I, filename);
581 readSimdlib(I, filename);
599 #if !defined(VISP_HAVE_JPEG) 600 std::string message =
"Libjpeg backend is not available to save file \"" + filename +
"\": switch to simd 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";
611 #if defined(VISP_HAVE_JPEG) 613 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 621 #if defined(VISP_HAVE_JPEG) 622 writeJPEGLibjpeg(I, filename, quality);
625 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 626 writeOpenCV(I, filename, quality);
629 writeJPEGSimdlib(I, filename, quality);
631 writeJPEGStb(I, filename, quality);
649 #if !defined(VISP_HAVE_JPEG) 650 std::string message =
"Libjpeg backend is not available to save file \"" + filename +
"\": switch to simd 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";
661 #if defined(VISP_HAVE_JPEG) 663 #elif defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 671 #if defined(VISP_HAVE_JPEG) 672 writeJPEGLibjpeg(I, filename, quality);
675 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 676 writeOpenCV(I, filename, quality);
679 writeJPEGSimdlib(I, filename, quality);
681 writeJPEGStb(I, filename, quality);
698 #if !defined(VISP_HAVE_PNG) 699 std::string message =
"Libpng backend is not available to save file \"" + filename +
"\": switch to simd 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";
710 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 718 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 719 writeOpenCV(I, filename, 90);
722 writePNGSimdlib(I, filename);
724 writePNGStb(I, filename);
726 #if defined(VISP_HAVE_PNG) 727 writePNGLibpng(I, filename);
745 #if !defined(VISP_HAVE_PNG) 746 std::string message =
"Libpng backend is not available to save file \"" + filename +
"\": switch to simd 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";
757 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 765 #if defined(VISP_HAVE_OPENCV) && VISP_HAVE_OPENCV_VERSION >= 0x020100 766 writeOpenCV(I, filename, 90);
769 writePNGSimdlib(I, filename);
771 writePNGStb(I, filename);
773 #if defined(VISP_HAVE_PNG) 774 writePNGLibpng(I, filename);
786 vp_writePFM(I, filename);
796 vp_writePGM(I, filename);
806 vp_writePGM(I, filename);
816 vp_writePGM(I, filename);
826 vp_readPFM(I, filename);
836 vp_readPGM(I, filename);
846 vp_readPGM(I, filename);
856 vp_readPPM(I, filename);
866 vp_readPPM(I, filename);
876 vp_writePPM(I, filename);
886 vp_writePPM(I, filename);
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void readJPEG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Use embedded simd library.
static void writeJPEG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90)
Use system libraries like libpng or libjpeg.
static void readPNG(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Use embedded stb_image library.
static void writePNG(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
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)
static void writePPM(const vpImage< unsigned char > &I, const std::string &filename)
static void readPPM(vpImage< unsigned char > &I, const std::string &filename)
static void writePFM(const vpImage< float > &I, const std::string &filename)
static void readPFM(vpImage< float > &I, const std::string &filename)
static void readPGM(vpImage< unsigned char > &I, const std::string &filename)
static void writePGM(const vpImage< unsigned char > &I, const std::string &filename)