Commit 84584002 authored by Alexander Enaldiev's avatar Alexander Enaldiev Committed by Alexander Alekhin

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
parent 573e7901
...@@ -280,6 +280,9 @@ OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" ON ...@@ -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_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_ITT "Include Intel ITT support" ON IF (NOT APPLE_FRAMEWORK) )
OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON ) 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 # OpenCV build components
# =================================================== # ===================================================
...@@ -1216,6 +1219,18 @@ if(WITH_GDCM OR HAVE_GDCM) ...@@ -1216,6 +1219,18 @@ if(WITH_GDCM OR HAVE_GDCM)
status(" GDCM:" HAVE_GDCM THEN "YES (ver ${GDCM_VERSION})" ELSE "NO") status(" GDCM:" HAVE_GDCM THEN "YES (ver ${GDCM_VERSION})" ELSE "NO")
endif() 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 ========================== # ========================== VIDEO IO ==========================
status("") status("")
status(" Video I/O:") status(" Video I/O:")
......
...@@ -252,3 +252,19 @@ if (WITH_GDCM) ...@@ -252,3 +252,19 @@ if (WITH_GDCM)
set(GDCM_LIBRARIES gdcmMSFF) # GDCM does not set this variable for some reason set(GDCM_LIBRARIES gdcmMSFF) # GDCM does not set this variable for some reason
endif() endif()
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()
...@@ -60,6 +60,18 @@ if(HAVE_GDAL) ...@@ -60,6 +60,18 @@ if(HAVE_GDAL)
list(APPEND GRFMT_LIBS ${GDAL_LIBRARY}) list(APPEND GRFMT_LIBS ${GDAL_LIBRARY})
endif() 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_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.hpp)
file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp) file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp)
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include "grfmt_hdr.hpp" #include "grfmt_hdr.hpp"
#include "rgbe.hpp" #include "rgbe.hpp"
#ifdef HAVE_IMGCODEC_HDR
namespace cv namespace cv
{ {
...@@ -166,3 +168,5 @@ bool HdrEncoder::isFormatSupported( int depth ) const { ...@@ -166,3 +168,5 @@ bool HdrEncoder::isFormatSupported( int depth ) const {
} }
} }
#endif // HAVE_IMGCODEC_HDR
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include "grfmt_base.hpp" #include "grfmt_base.hpp"
#ifdef HAVE_IMGCODEC_HDR
namespace cv namespace cv
{ {
...@@ -85,4 +87,6 @@ protected: ...@@ -85,4 +87,6 @@ protected:
} }
#endif // HAVE_IMGCODEC_HDR
#endif/*_GRFMT_HDR_H_*/ #endif/*_GRFMT_HDR_H_*/
...@@ -46,10 +46,13 @@ ...@@ -46,10 +46,13 @@
// //
//M*/ //M*/
#include "precomp.hpp"
#ifdef HAVE_IMGCODEC_PXM
#include <cerrno> #include <cerrno>
#include "precomp.hpp"
#include "utils.hpp" #include "utils.hpp"
#include "grfmt_pam.hpp" #include "grfmt_pam.hpp"
...@@ -720,3 +723,5 @@ bool PAMEncoder::write( const Mat& img, const std::vector<int>& params ) ...@@ -720,3 +723,5 @@ bool PAMEncoder::write( const Mat& img, const std::vector<int>& params )
} }
} }
#endif
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#ifndef _OPENCV_PAM_HPP_ #ifndef _OPENCV_PAM_HPP_
#define _OPENCV_PAM_HPP_ #define _OPENCV_PAM_HPP_
#ifdef HAVE_IMGCODEC_PXM
#include "grfmt_base.hpp" #include "grfmt_base.hpp"
#include "bitstrm.hpp" #include "bitstrm.hpp"
...@@ -96,4 +98,6 @@ public: ...@@ -96,4 +98,6 @@ public:
} }
#endif
#endif /* _OPENCV_PAM_HPP_ */ #endif /* _OPENCV_PAM_HPP_ */
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include "grfmt_pxm.hpp" #include "grfmt_pxm.hpp"
#include <iostream> #include <iostream>
#ifdef HAVE_IMGCODEC_PXM
namespace cv namespace cv
{ {
...@@ -619,3 +621,5 @@ bool PxMEncoder::write(const Mat& img, const std::vector<int>& params) ...@@ -619,3 +621,5 @@ bool PxMEncoder::write(const Mat& img, const std::vector<int>& params)
} }
} }
#endif // HAVE_IMGCODEC_PXM
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include "grfmt_base.hpp" #include "grfmt_base.hpp"
#include "bitstrm.hpp" #include "bitstrm.hpp"
#ifdef HAVE_IMGCODEC_PXM
namespace cv namespace cv
{ {
...@@ -101,4 +103,6 @@ public: ...@@ -101,4 +103,6 @@ public:
} }
#endif // HAVE_IMGCODEC_PXM
#endif/*_GRFMT_PxM_H_*/ #endif/*_GRFMT_PxM_H_*/
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "grfmt_sunras.hpp" #include "grfmt_sunras.hpp"
#ifdef HAVE_IMGCODEC_SUNRASTER
namespace cv namespace cv
{ {
...@@ -427,3 +429,5 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector<int>& ) ...@@ -427,3 +429,5 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector<int>& )
} }
} }
#endif // HAVE_IMGCODEC_SUNRASTER
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include "grfmt_base.hpp" #include "grfmt_base.hpp"
#ifdef HAVE_IMGCODEC_SUNRASTER
namespace cv namespace cv
{ {
...@@ -102,4 +104,6 @@ public: ...@@ -102,4 +104,6 @@ public:
} }
#endif // HAVE_IMGCODEC_SUNRASTER
#endif/*_GRFMT_SUNRAS_H_*/ #endif/*_GRFMT_SUNRAS_H_*/
...@@ -131,8 +131,10 @@ struct ImageCodecInitializer ...@@ -131,8 +131,10 @@ struct ImageCodecInitializer
decoders.push_back( makePtr<BmpDecoder>() ); decoders.push_back( makePtr<BmpDecoder>() );
encoders.push_back( makePtr<BmpEncoder>() ); encoders.push_back( makePtr<BmpEncoder>() );
#ifdef HAVE_IMGCODEC_HDR
decoders.push_back( makePtr<HdrDecoder>() ); decoders.push_back( makePtr<HdrDecoder>() );
encoders.push_back( makePtr<HdrEncoder>() ); encoders.push_back( makePtr<HdrEncoder>() );
#endif
#ifdef HAVE_JPEG #ifdef HAVE_JPEG
decoders.push_back( makePtr<JpegDecoder>() ); decoders.push_back( makePtr<JpegDecoder>() );
encoders.push_back( makePtr<JpegEncoder>() ); encoders.push_back( makePtr<JpegEncoder>() );
...@@ -141,13 +143,19 @@ struct ImageCodecInitializer ...@@ -141,13 +143,19 @@ struct ImageCodecInitializer
decoders.push_back( makePtr<WebPDecoder>() ); decoders.push_back( makePtr<WebPDecoder>() );
encoders.push_back( makePtr<WebPEncoder>() ); encoders.push_back( makePtr<WebPEncoder>() );
#endif #endif
#ifdef HAVE_IMGCODEC_SUNRASTER
decoders.push_back( makePtr<SunRasterDecoder>() ); decoders.push_back( makePtr<SunRasterDecoder>() );
encoders.push_back( makePtr<SunRasterEncoder>() ); encoders.push_back( makePtr<SunRasterEncoder>() );
#endif
#ifdef HAVE_IMGCODEC_PXM
decoders.push_back( makePtr<PxMDecoder>() ); decoders.push_back( makePtr<PxMDecoder>() );
encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_AUTO) ); encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_AUTO) );
encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PBM) ); encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PBM) );
encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PGM) ); encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PGM) );
encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PPM) ); encoders.push_back( makePtr<PxMEncoder>(PXM_TYPE_PPM) );
decoders.push_back( makePtr<PAMDecoder>() );
encoders.push_back( makePtr<PAMEncoder>() );
#endif
#ifdef HAVE_TIFF #ifdef HAVE_TIFF
decoders.push_back( makePtr<TiffDecoder>() ); decoders.push_back( makePtr<TiffDecoder>() );
encoders.push_back( makePtr<TiffEncoder>() ); encoders.push_back( makePtr<TiffEncoder>() );
...@@ -172,8 +180,6 @@ struct ImageCodecInitializer ...@@ -172,8 +180,6 @@ struct ImageCodecInitializer
/// Attach the GDAL Decoder /// Attach the GDAL Decoder
decoders.push_back( makePtr<GdalDecoder>() ); decoders.push_back( makePtr<GdalDecoder>() );
#endif/*HAVE_GDAL*/ #endif/*HAVE_GDAL*/
decoders.push_back( makePtr<PAMDecoder>() );
encoders.push_back( makePtr<PAMEncoder>() );
} }
std::vector<ImageDecoder> decoders; std::vector<ImageDecoder> decoders;
......
...@@ -89,7 +89,9 @@ const string all_images[] = ...@@ -89,7 +89,9 @@ const string all_images[] =
"readwrite/ordinary.bmp", "readwrite/ordinary.bmp",
"readwrite/rle8.bmp", "readwrite/rle8.bmp",
"readwrite/test_1_c1.jpg", "readwrite/test_1_c1.jpg",
#ifdef HAVE_IMGCODEC_HDR
"readwrite/rle.hdr" "readwrite/rle.hdr"
#endif
}; };
const int basic_modes[] = const int basic_modes[] =
...@@ -207,11 +209,13 @@ const string all_exts[] = ...@@ -207,11 +209,13 @@ const string all_exts[] =
".jpg", ".jpg",
#endif #endif
".bmp", ".bmp",
#ifdef HAVE_IMGCODEC_PXM
".pam", ".pam",
".ppm", ".ppm",
".pgm", ".pgm",
".pbm", ".pbm",
".pnm" ".pnm"
#endif
}; };
vector<Size> all_sizes() vector<Size> all_sizes()
...@@ -227,6 +231,7 @@ INSTANTIATE_TEST_CASE_P(All, Imgcodecs_ExtSize, ...@@ -227,6 +231,7 @@ INSTANTIATE_TEST_CASE_P(All, Imgcodecs_ExtSize,
testing::ValuesIn(all_exts), testing::ValuesIn(all_exts),
testing::ValuesIn(all_sizes()))); testing::ValuesIn(all_sizes())));
#ifdef HAVE_IMGCODEC_PXM
typedef testing::TestWithParam<bool> Imgcodecs_pbm; typedef testing::TestWithParam<bool> Imgcodecs_pbm;
TEST_P(Imgcodecs_pbm, write_read) TEST_P(Imgcodecs_pbm, write_read)
{ {
...@@ -259,6 +264,7 @@ 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()); INSTANTIATE_TEST_CASE_P(All, Imgcodecs_pbm, testing::Bool());
#endif
//================================================================================================== //==================================================================================================
...@@ -274,6 +280,7 @@ TEST(Imgcodecs_Bmp, read_rle8) ...@@ -274,6 +280,7 @@ TEST(Imgcodecs_Bmp, read_rle8)
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), rle, ord); EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), rle, ord);
} }
#ifdef HAVE_IMGCODEC_HDR
TEST(Imgcodecs_Hdr, regression) TEST(Imgcodecs_Hdr, regression)
{ {
string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/"; string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/";
...@@ -299,7 +306,9 @@ TEST(Imgcodecs_Hdr, regression) ...@@ -299,7 +306,9 @@ TEST(Imgcodecs_Hdr, regression)
} }
remove(tmp_file_name.c_str()); remove(tmp_file_name.c_str());
} }
#endif
#ifdef HAVE_IMGCODEC_PXM
TEST(Imgcodecs_Pam, read_write) TEST(Imgcodecs_Pam, read_write)
{ {
string folder = string(cvtest::TS::ptr()->get_data_path()) + "readwrite/"; string folder = string(cvtest::TS::ptr()->get_data_path()) + "readwrite/";
...@@ -326,5 +335,6 @@ TEST(Imgcodecs_Pam, read_write) ...@@ -326,5 +335,6 @@ TEST(Imgcodecs_Pam, read_write)
remove(writefile.c_str()); remove(writefile.c_str());
remove(writefile_no_param.c_str()); remove(writefile_no_param.c_str());
} }
#endif
}} // namespace }} // namespace
...@@ -112,8 +112,12 @@ const string exts[] = { ...@@ -112,8 +112,12 @@ const string exts[] = {
"exr", "exr",
#endif #endif
"bmp", "bmp",
#ifdef HAVE_IMGCODEC_PXM
"ppm", "ppm",
"ras" #endif
#ifdef HAVE_IMGCODEC_SUNRASTER
"ras",
#endif
}; };
INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts)); INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment