Merge pull request #11417 from Turim:imgcodecs_cmake_decoders_customize_formats
authorAlexander Enaldiev <alexander.enaldiev@gmail.com>
Tue, 22 May 2018 15:10:15 +0000 (18:10 +0300)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 22 May 2018 15:10:15 +0000 (15:10 +0000)
* 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

14 files changed:
CMakeLists.txt
cmake/OpenCVFindLibsGrfmt.cmake
modules/imgcodecs/CMakeLists.txt
modules/imgcodecs/src/grfmt_hdr.cpp
modules/imgcodecs/src/grfmt_hdr.hpp
modules/imgcodecs/src/grfmt_pam.cpp
modules/imgcodecs/src/grfmt_pam.hpp
modules/imgcodecs/src/grfmt_pxm.cpp
modules/imgcodecs/src/grfmt_pxm.hpp
modules/imgcodecs/src/grfmt_sunras.cpp
modules/imgcodecs/src/grfmt_sunras.hpp
modules/imgcodecs/src/loadsave.cpp
modules/imgcodecs/test/test_grfmt.cpp
modules/imgcodecs/test/test_read_write.cpp

index 1c4bb2b..5190c50 100644 (file)
@@ -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:")
index c3eb82c..9f18e2b 100644 (file)
@@ -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()
index 720f586..434278c 100644 (file)
@@ -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)
 
index 9801106..a274b22 100644 (file)
@@ -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
index 04947ea..fa29fbe 100644 (file)
@@ -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_*/
index 705e851..e300d33 100644 (file)
 //
 //M*/
 
+#include "precomp.hpp"
+
+
+#ifdef HAVE_IMGCODEC_PXM
 
 #include <cerrno>
 
-#include "precomp.hpp"
 #include "utils.hpp"
 #include "grfmt_pam.hpp"
 
@@ -720,3 +723,5 @@ bool PAMEncoder::write( const Mat& img, const std::vector<int>& params )
 }
 
 }
+
+#endif
index 3b740e3..f9b2614 100644 (file)
@@ -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_ */
index 49ffc9e..b7186ce 100644 (file)
@@ -45,6 +45,8 @@
 #include "grfmt_pxm.hpp"
 #include <iostream>
 
+#ifdef HAVE_IMGCODEC_PXM
+
 namespace cv
 {
 
@@ -619,3 +621,5 @@ bool PxMEncoder::write(const Mat& img, const std::vector<int>& params)
 }
 
 }
+
+#endif // HAVE_IMGCODEC_PXM
index b4d5ad0..6404e96 100644 (file)
@@ -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_*/
index 85a9ab9..6398db5 100644 (file)
@@ -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<int>& )
 }
 
 }
+
+#endif // HAVE_IMGCODEC_SUNRASTER
index ecd5c74..fc6284a 100644 (file)
@@ -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_*/
index e6782dc..7804ebe 100644 (file)
@@ -131,8 +131,10 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<BmpDecoder>() );
         encoders.push_back( makePtr<BmpEncoder>() );
 
+    #ifdef HAVE_IMGCODEC_HDR
         decoders.push_back( makePtr<HdrDecoder>() );
         encoders.push_back( makePtr<HdrEncoder>() );
+    #endif
     #ifdef HAVE_JPEG
         decoders.push_back( makePtr<JpegDecoder>() );
         encoders.push_back( makePtr<JpegEncoder>() );
@@ -141,13 +143,19 @@ struct ImageCodecInitializer
         decoders.push_back( makePtr<WebPDecoder>() );
         encoders.push_back( makePtr<WebPEncoder>() );
     #endif
+    #ifdef HAVE_IMGCODEC_SUNRASTER
         decoders.push_back( makePtr<SunRasterDecoder>() );
         encoders.push_back( makePtr<SunRasterEncoder>() );
+    #endif
+    #ifdef HAVE_IMGCODEC_PXM
         decoders.push_back( makePtr<PxMDecoder>() );
         encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_AUTO) );
         encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PBM) );
         encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PGM) );
         encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PPM) );
+        decoders.push_back( makePtr<PAMDecoder>() );
+        encoders.push_back( makePtr<PAMEncoder>() );
+    #endif
     #ifdef HAVE_TIFF
         decoders.push_back( makePtr<TiffDecoder>() );
         encoders.push_back( makePtr<TiffEncoder>() );
@@ -172,8 +180,6 @@ struct ImageCodecInitializer
         /// Attach the GDAL Decoder
         decoders.push_back( makePtr<GdalDecoder>() );
     #endif/*HAVE_GDAL*/
-        decoders.push_back( makePtr<PAMDecoder>() );
-        encoders.push_back( makePtr<PAMEncoder>() );
     }
 
     std::vector<ImageDecoder> decoders;
index 88f8501..8fcbc1c 100644 (file)
@@ -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<Size> 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<bool> 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
index e816a3c..8176b52 100644 (file)
@@ -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));