diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c4bb2b1cea5476a51a4c4186d23082d662b903e..5190c5081f703d23b3100f3fefbc099aa7d894a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -280,6 +280,9 @@ OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" ON OCV_OPTION(WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION) IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_ITT "Include Intel ITT support" ON IF (NOT APPLE_FRAMEWORK) ) OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON ) +OCV_OPTION(WITH_IMGCODEC_HDR "Include HDR support" ON) +OCV_OPTION(WITH_IMGCODEC_SUNRASTER "Include SUNRASTER support" ON) +OCV_OPTION(WITH_IMGCODEC_PXM "Include PNM (PBM,PGM,PPM) and PAM formats support" ON) # OpenCV build components # =================================================== @@ -1216,6 +1219,18 @@ if(WITH_GDCM OR HAVE_GDCM) status(" GDCM:" HAVE_GDCM THEN "YES (ver ${GDCM_VERSION})" ELSE "NO") endif() +if(WITH_IMGCODEC_HDR OR DEFINED HAVE_IMGCODEC_HDR) + status(" HDR:" HAVE_IMGCODEC_HDR THEN "YES" ELSE "NO") +endif() + +if(WITH_IMGCODEC_SUNRASTER OR DEFINED HAVE_IMGCODEC_SUNRASTER) + status(" SUNRASTER:" HAVE_IMGCODEC_SUNRASTER THEN "YES" ELSE "NO") +endif() + +if(WITH_IMGCODEC_PXM OR DEFINED HAVE_IMGCODEC_PXM) + status(" PXM:" HAVE_IMGCODEC_PXM THEN "YES" ELSE "NO") +endif() + # ========================== VIDEO IO ========================== status("") status(" Video I/O:") diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index c3eb82c537a691ddd43914b9ac94bad6b4d0c0b8..9f18e2bf6279b0626e879677156b4e993c335896 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -252,3 +252,19 @@ if (WITH_GDCM) set(GDCM_LIBRARIES gdcmMSFF) # GDCM does not set this variable for some reason endif() endif() + +if(WITH_IMGCODEC_HDR) + set(HAVE_IMGCODEC_HDR ON) +elseif(DEFINED WITH_IMGCODEC_HDR) + set(HAVE_IMGCODEC_HDR OFF) +endif() +if(WITH_IMGCODEC_SUNRASTER) + set(HAVE_IMGCODEC_SUNRASTER ON) +elseif(DEFINED WITH_IMGCODEC_SUNRASTER) + set(HAVE_IMGCODEC_SUNRASTER OFF) +endif() +if(WITH_IMGCODEC_PXM) + set(HAVE_IMGCODEC_PXM ON) +elseif(DEFINED WITH_IMGCODEC_PXM) + set(HAVE_IMGCODEC_PXM OFF) +endif() diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 720f5860536e17a85c4282716ec6452f7e6d8cb4..434278c2a5c6bbba612c3ae871d0cba1ef8e9829 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -60,6 +60,18 @@ if(HAVE_GDAL) list(APPEND GRFMT_LIBS ${GDAL_LIBRARY}) endif() +if(HAVE_IMGCODEC_HDR) + add_definitions(-DHAVE_IMGCODEC_HDR) +endif() + +if(HAVE_IMGCODEC_SUNRASTER) + add_definitions(-DHAVE_IMGCODEC_SUNRASTER) +endif() + +if(HAVE_IMGCODEC_PXM) + add_definitions(-DHAVE_IMGCODEC_PXM) +endif() + file(GLOB grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.hpp) file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp) diff --git a/modules/imgcodecs/src/grfmt_hdr.cpp b/modules/imgcodecs/src/grfmt_hdr.cpp index 9801106506e2f2e255a6d4d6696eb00f45a46bb1..a274b2233c98a3b8d2174e75e5e95566116a1619 100644 --- a/modules/imgcodecs/src/grfmt_hdr.cpp +++ b/modules/imgcodecs/src/grfmt_hdr.cpp @@ -44,6 +44,8 @@ #include "grfmt_hdr.hpp" #include "rgbe.hpp" +#ifdef HAVE_IMGCODEC_HDR + namespace cv { @@ -166,3 +168,5 @@ bool HdrEncoder::isFormatSupported( int depth ) const { } } + +#endif // HAVE_IMGCODEC_HDR diff --git a/modules/imgcodecs/src/grfmt_hdr.hpp b/modules/imgcodecs/src/grfmt_hdr.hpp index 04947eae5810c610dc341daea2c71e3438108d26..fa29fbe0d2d909bcda235a0e6b229f0118481365 100644 --- a/modules/imgcodecs/src/grfmt_hdr.hpp +++ b/modules/imgcodecs/src/grfmt_hdr.hpp @@ -45,6 +45,8 @@ #include "grfmt_base.hpp" +#ifdef HAVE_IMGCODEC_HDR + namespace cv { @@ -85,4 +87,6 @@ protected: } +#endif // HAVE_IMGCODEC_HDR + #endif/*_GRFMT_HDR_H_*/ diff --git a/modules/imgcodecs/src/grfmt_pam.cpp b/modules/imgcodecs/src/grfmt_pam.cpp index 705e8511d20d6f3ec92fce459987d5597dad1314..e300d33ff420c43aa2295bb57457ec6f66fea179 100644 --- a/modules/imgcodecs/src/grfmt_pam.cpp +++ b/modules/imgcodecs/src/grfmt_pam.cpp @@ -46,10 +46,13 @@ // //M*/ +#include "precomp.hpp" + + +#ifdef HAVE_IMGCODEC_PXM #include -#include "precomp.hpp" #include "utils.hpp" #include "grfmt_pam.hpp" @@ -720,3 +723,5 @@ bool PAMEncoder::write( const Mat& img, const std::vector& params ) } } + +#endif diff --git a/modules/imgcodecs/src/grfmt_pam.hpp b/modules/imgcodecs/src/grfmt_pam.hpp index 3b740e36928043cc0f9170fc7354a0bc9681b211..f9b2614b28fe50927c92a0ede7fc99b07796dbc6 100644 --- a/modules/imgcodecs/src/grfmt_pam.hpp +++ b/modules/imgcodecs/src/grfmt_pam.hpp @@ -53,6 +53,8 @@ #ifndef _OPENCV_PAM_HPP_ #define _OPENCV_PAM_HPP_ +#ifdef HAVE_IMGCODEC_PXM + #include "grfmt_base.hpp" #include "bitstrm.hpp" @@ -96,4 +98,6 @@ public: } +#endif + #endif /* _OPENCV_PAM_HPP_ */ diff --git a/modules/imgcodecs/src/grfmt_pxm.cpp b/modules/imgcodecs/src/grfmt_pxm.cpp index 49ffc9ef595f931f0089b28135196d9747123e47..b7186ce2232aaab32a02d3ed171d830a19ac48dd 100644 --- a/modules/imgcodecs/src/grfmt_pxm.cpp +++ b/modules/imgcodecs/src/grfmt_pxm.cpp @@ -45,6 +45,8 @@ #include "grfmt_pxm.hpp" #include +#ifdef HAVE_IMGCODEC_PXM + namespace cv { @@ -619,3 +621,5 @@ bool PxMEncoder::write(const Mat& img, const std::vector& params) } } + +#endif // HAVE_IMGCODEC_PXM diff --git a/modules/imgcodecs/src/grfmt_pxm.hpp b/modules/imgcodecs/src/grfmt_pxm.hpp index b4d5ad08fa4f06d8444a8adf4e7f1a0b50541242..6404e96ef17fca37236c5d5c6b9546b6d61f8425 100644 --- a/modules/imgcodecs/src/grfmt_pxm.hpp +++ b/modules/imgcodecs/src/grfmt_pxm.hpp @@ -46,6 +46,8 @@ #include "grfmt_base.hpp" #include "bitstrm.hpp" +#ifdef HAVE_IMGCODEC_PXM + namespace cv { @@ -101,4 +103,6 @@ public: } +#endif // HAVE_IMGCODEC_PXM + #endif/*_GRFMT_PxM_H_*/ diff --git a/modules/imgcodecs/src/grfmt_sunras.cpp b/modules/imgcodecs/src/grfmt_sunras.cpp index 85a9ab9d34ed6ca5850688f282f0bc09929d8ab9..6398db567f54b52f4ba30e311211c397c93a6f6b 100644 --- a/modules/imgcodecs/src/grfmt_sunras.cpp +++ b/modules/imgcodecs/src/grfmt_sunras.cpp @@ -43,6 +43,8 @@ #include "precomp.hpp" #include "grfmt_sunras.hpp" +#ifdef HAVE_IMGCODEC_SUNRASTER + namespace cv { @@ -427,3 +429,5 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector& ) } } + +#endif // HAVE_IMGCODEC_SUNRASTER diff --git a/modules/imgcodecs/src/grfmt_sunras.hpp b/modules/imgcodecs/src/grfmt_sunras.hpp index ecd5c743fc8c610507887c9146ac262efdf19b6a..fc6284ad409078f10086bb24140de2d9d7020361 100644 --- a/modules/imgcodecs/src/grfmt_sunras.hpp +++ b/modules/imgcodecs/src/grfmt_sunras.hpp @@ -45,6 +45,8 @@ #include "grfmt_base.hpp" +#ifdef HAVE_IMGCODEC_SUNRASTER + namespace cv { @@ -102,4 +104,6 @@ public: } +#endif // HAVE_IMGCODEC_SUNRASTER + #endif/*_GRFMT_SUNRAS_H_*/ diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index e6782dcbec8e16ac254404e9f69ecab0498d71e8..7804ebee2600689c59867fa7df3735e8c335394a 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -131,8 +131,10 @@ struct ImageCodecInitializer decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); + #ifdef HAVE_IMGCODEC_HDR decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); + #endif #ifdef HAVE_JPEG decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); @@ -141,13 +143,19 @@ struct ImageCodecInitializer decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); #endif + #ifdef HAVE_IMGCODEC_SUNRASTER decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); + #endif + #ifdef HAVE_IMGCODEC_PXM decoders.push_back( makePtr() ); encoders.push_back( makePtr(PXM_TYPE_AUTO) ); encoders.push_back( makePtr(PXM_TYPE_PBM) ); encoders.push_back( makePtr(PXM_TYPE_PGM) ); encoders.push_back( makePtr(PXM_TYPE_PPM) ); + decoders.push_back( makePtr() ); + encoders.push_back( makePtr() ); + #endif #ifdef HAVE_TIFF decoders.push_back( makePtr() ); encoders.push_back( makePtr() ); @@ -172,8 +180,6 @@ struct ImageCodecInitializer /// Attach the GDAL Decoder decoders.push_back( makePtr() ); #endif/*HAVE_GDAL*/ - decoders.push_back( makePtr() ); - encoders.push_back( makePtr() ); } std::vector decoders; diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index 88f8501d89a6e5883c8d121f973f043a39e03f18..8fcbc1c35a64609e6b3487728ffe0d712c116038 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -89,7 +89,9 @@ const string all_images[] = "readwrite/ordinary.bmp", "readwrite/rle8.bmp", "readwrite/test_1_c1.jpg", +#ifdef HAVE_IMGCODEC_HDR "readwrite/rle.hdr" +#endif }; const int basic_modes[] = @@ -207,11 +209,13 @@ const string all_exts[] = ".jpg", #endif ".bmp", +#ifdef HAVE_IMGCODEC_PXM ".pam", ".ppm", ".pgm", ".pbm", ".pnm" +#endif }; vector all_sizes() @@ -227,6 +231,7 @@ INSTANTIATE_TEST_CASE_P(All, Imgcodecs_ExtSize, testing::ValuesIn(all_exts), testing::ValuesIn(all_sizes()))); +#ifdef HAVE_IMGCODEC_PXM typedef testing::TestWithParam Imgcodecs_pbm; TEST_P(Imgcodecs_pbm, write_read) { @@ -259,6 +264,7 @@ TEST_P(Imgcodecs_pbm, write_read) } INSTANTIATE_TEST_CASE_P(All, Imgcodecs_pbm, testing::Bool()); +#endif //================================================================================================== @@ -274,6 +280,7 @@ TEST(Imgcodecs_Bmp, read_rle8) EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), rle, ord); } +#ifdef HAVE_IMGCODEC_HDR TEST(Imgcodecs_Hdr, regression) { string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/"; @@ -299,7 +306,9 @@ TEST(Imgcodecs_Hdr, regression) } remove(tmp_file_name.c_str()); } +#endif +#ifdef HAVE_IMGCODEC_PXM TEST(Imgcodecs_Pam, read_write) { string folder = string(cvtest::TS::ptr()->get_data_path()) + "readwrite/"; @@ -326,5 +335,6 @@ TEST(Imgcodecs_Pam, read_write) remove(writefile.c_str()); remove(writefile_no_param.c_str()); } +#endif }} // namespace diff --git a/modules/imgcodecs/test/test_read_write.cpp b/modules/imgcodecs/test/test_read_write.cpp index e816a3cc39b98075487ef394d2d91afeaff93623..8176b52ccf6137e3301cee28a424a43ecba5e90e 100644 --- a/modules/imgcodecs/test/test_read_write.cpp +++ b/modules/imgcodecs/test/test_read_write.cpp @@ -112,8 +112,12 @@ const string exts[] = { "exr", #endif "bmp", +#ifdef HAVE_IMGCODEC_PXM "ppm", - "ras" +#endif +#ifdef HAVE_IMGCODEC_SUNRASTER + "ras", +#endif }; INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts));