From 84584002f2a579f9c63bde73e44e7a695271bd39 Mon Sep 17 00:00:00 2001 From: Alexander Enaldiev Date: Tue, 22 May 2018 18:10:15 +0300 Subject: [PATCH] Merge pull request #11417 from Turim:imgcodecs_cmake_decoders_customize_formats * imgcodecs cmake: the option to customize supported formats list (WITH_IMGCODEC_HDR, WITH_IMGCODEC_SUNRASTER, WITH_IMGCODEC_PXM) * imgcodecs: fixes - fixed CMake scripts (=OFF doesn't really work) - restore dropped GDCM block - added _IMGCODEC_ prefix - fixed tests - include PAM format under WITH_IMGCODEC_PXM option --- CMakeLists.txt | 15 +++++++++++++++ cmake/OpenCVFindLibsGrfmt.cmake | 16 ++++++++++++++++ modules/imgcodecs/CMakeLists.txt | 12 ++++++++++++ modules/imgcodecs/src/grfmt_hdr.cpp | 4 ++++ modules/imgcodecs/src/grfmt_hdr.hpp | 4 ++++ modules/imgcodecs/src/grfmt_pam.cpp | 7 ++++++- modules/imgcodecs/src/grfmt_pam.hpp | 4 ++++ modules/imgcodecs/src/grfmt_pxm.cpp | 4 ++++ modules/imgcodecs/src/grfmt_pxm.hpp | 4 ++++ modules/imgcodecs/src/grfmt_sunras.cpp | 4 ++++ modules/imgcodecs/src/grfmt_sunras.hpp | 4 ++++ modules/imgcodecs/src/loadsave.cpp | 10 ++++++++-- modules/imgcodecs/test/test_grfmt.cpp | 10 ++++++++++ modules/imgcodecs/test/test_read_write.cpp | 6 +++++- 14 files changed, 100 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c4bb2b1ce..5190c5081f 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 c3eb82c537..9f18e2bf62 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 720f586053..434278c2a5 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 9801106506..a274b2233c 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 04947eae58..fa29fbe0d2 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 705e8511d2..e300d33ff4 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 3b740e3692..f9b2614b28 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 49ffc9ef59..b7186ce223 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 b4d5ad08fa..6404e96ef1 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 85a9ab9d34..6398db567f 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 ecd5c743fc..fc6284ad40 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 e6782dcbec..7804ebee26 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 88f8501d89..8fcbc1c35a 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 e816a3cc39..8176b52ccf 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)); -- GitLab