Skip to content

Commit

Permalink
Add possibility to choose image I/O backend for JPEG and PNG image re…
Browse files Browse the repository at this point in the history
…ading/writing.
  • Loading branch information
s-trinh committed Jan 24, 2022
1 parent 413f542 commit 440892b
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 153 deletions.
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,7 @@ VP_OPTION(WITH_CLIPPER "" "" "Build clipper as built-in library"
VP_OPTION(WITH_LAPACK "" "" "Build lapack as built-in library" "" ON IF NOT USE_LAPACK)
VP_OPTION(WITH_QBDEVICE "" "" "Build qbdevice-api as built-in library" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND (NOT WINRT) AND (NOT IOS))
VP_OPTION(WITH_TAKKTILE2 "" "" "Build Right Hand takktile2 driver as built-in library" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND (NOT WIN32) AND (NOT WINRT) AND (NOT IOS) AND (NOT ANDROID))

# Use stb_image as built-in library only when OpenCV, libjpeg and libpng not available
if(NOT USE_OPENCV AND (NOT USE_PNG OR NOT USE_JPEG))
set(WITH_STBIMAGE ON)
else()
set(WITH_STBIMAGE OFF)
endif()
# TODO:
set(WITH_STBIMAGE ON)

VP_OPTION(WITH_CATCH2 "" "" "Use catch2" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98))
VP_OPTION(WITH_CATCH2 "" "" "Use catch2" "" ON IF (VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98))

# ----------------------------------------------------------------------------
# Check for specific functions. Should be after cxx standard detection in VISPDetectCXXStandard.cmake and potential modification depending on pcl, realsense2, libfranka
Expand Down
11 changes: 5 additions & 6 deletions cmake/VISP3rdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ add_subdirectory("${VISP_SOURCE_DIR}/3rdparty/simdlib")
set(SIMDLIB_INCLUDE_DIRS "${VISP_SOURCE_DIR}/3rdparty/simdlib")
set(SIMDLIB_LIBRARIES ${SIMD_LIBRARY})

if(WITH_STBIMAGE)
set(STBIMAGE_LIBRARY visp_stbimage)
add_subdirectory("${VISP_SOURCE_DIR}/3rdparty/stb_image")
set(STBIMAGE_INCLUDE_DIRS "${VISP_SOURCE_DIR}/3rdparty/stb_image")
set(STBIMAGE_VERSION ${STBIMAGE_MAJOR_VERSION}.${STBIMAGE_MINOR_VERSION}.${STBIMAGE_PATCH_VERSION})
endif()
# stb is always enabled
set(STBIMAGE_LIBRARY visp_stbimage)
add_subdirectory("${VISP_SOURCE_DIR}/3rdparty/stb_image")
set(STBIMAGE_INCLUDE_DIRS "${VISP_SOURCE_DIR}/3rdparty/stb_image")
set(STBIMAGE_VERSION ${STBIMAGE_MAJOR_VERSION}.${STBIMAGE_MINOR_VERSION}.${STBIMAGE_PATCH_VERSION})

if(WITH_CATCH2)
set(CATCH2_LIBRARY visp_catch2)
Expand Down
7 changes: 2 additions & 5 deletions modules/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ if(USE_PNG)
add_definitions(${PNG_DEFINITIONS})
endif()

# TODO:
#if(WITH_STBIMAGE)
# stb_image is private
include_directories(${STBIMAGE_INCLUDE_DIRS})
#endif()
# stb_image is private
include_directories(${STBIMAGE_INCLUDE_DIRS})

if(WITH_CATCH2)
# catch2 is private
Expand Down
27 changes: 13 additions & 14 deletions modules/io/include/visp3/io/vpImageIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,20 @@ class VISP_EXPORT vpImageIo
static std::string getExtension(const std::string &filename);

public:
//TODO:
// Image IO backend for only jpeg and png formats
enum vpImageIoBackendType {
IO_DEFAULT_BACKEND,
IO_LIB_BACKEND,
IO_SYSTEM_LIB_BACKEND,
IO_OPENCV_BACKEND,
IO_SIMDLIB_BACKEND,
IO_STB_IMAGE_BACKEND
};

static void read(vpImage<unsigned char> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void read(vpImage<vpRGBa> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void read(vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
static void read(vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);

static void write(const vpImage<unsigned char> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void write(const vpImage<vpRGBa> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void write(const vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
static void write(const vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);

static void readPFM(vpImage<float> &I, const std::string &filename);

Expand All @@ -148,11 +147,11 @@ class VISP_EXPORT vpImageIo
static void readPPM(vpImage<unsigned char> &I, const std::string &filename);
static void readPPM(vpImage<vpRGBa> &I, const std::string &filename);

static void readJPEG(vpImage<unsigned char> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void readJPEG(vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);

static void readPNG(vpImage<unsigned char> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void readPNG(vpImage<vpRGBa> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void readPNG(vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
static void readPNG(vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);

static void writePFM(const vpImage<float> &I, const std::string &filename);

Expand All @@ -163,10 +162,10 @@ class VISP_EXPORT vpImageIo
static void writePPM(const vpImage<unsigned char> &I, const std::string &filename);
static void writePPM(const vpImage<vpRGBa> &I, const std::string &filename);

static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int quality=90, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int quality=90, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int quality=90, int backend=IO_DEFAULT_BACKEND);
static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int quality=90, int backend=IO_DEFAULT_BACKEND);

static void writePNG(const vpImage<unsigned char> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename, const vpImageIoBackendType& backend=IO_DEFAULT_BACKEND);
static void writePNG(const vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND);
};
#endif
17 changes: 0 additions & 17 deletions modules/io/src/image/private/vpImageIoLibjpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* Libjpeg backend for JPEG image I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -48,14 +41,6 @@
#include "vpImageIoBackend.h"
#include <visp3/core/vpImageConvert.h>

//TODO: is it needed?
//#if defined(_WIN32)
//// Include WinSock2.h before windows.h to ensure that winsock.h is not
//// included by windows.h since winsock.h and winsock2.h are incompatible
//#include <WinSock2.h>
//#include <windows.h>
//#endif

#if defined(VISP_HAVE_JPEG)
#include <jerror.h>
#include <jpeglib.h>
Expand Down Expand Up @@ -106,7 +91,6 @@ void writeJPEGLibjpeg(const vpImage<unsigned char> &I, const std::string &filena
cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE;
jpeg_set_defaults(&cinfo);
//TODO:
jpeg_set_quality(&cinfo, quality, TRUE);

jpeg_start_compress(&cinfo, TRUE);
Expand Down Expand Up @@ -166,7 +150,6 @@ void writeJPEGLibjpeg(const vpImage<vpRGBa> &I, const std::string &filename, int
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
//TODO:
jpeg_set_quality(&cinfo, quality, TRUE);

jpeg_start_compress(&cinfo, TRUE);
Expand Down
15 changes: 0 additions & 15 deletions modules/io/src/image/private/vpImageIoLibpng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* Libpng backend for PNG image I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -48,14 +41,6 @@
#include "vpImageIoBackend.h"
#include <visp3/core/vpImageConvert.h>

//TODO: is it needed?
//#if defined(_WIN32)
//// Include WinSock2.h before windows.h to ensure that winsock.h is not
//// included by windows.h since winsock.h and winsock2.h are incompatible
//#include <WinSock2.h>
//#include <windows.h>
//#endif

#if defined(VISP_HAVE_PNG)
#include <png.h>
#endif
Expand Down
8 changes: 0 additions & 8 deletions modules/io/src/image/private/vpImageIoOpenCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* OpenCV backend for image I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -47,7 +40,6 @@

#include "vpImageIoBackend.h"

//TODO:
#ifdef VISP_HAVE_OPENCV
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000) // Require opencv >= 3.0.0
# include <opencv2/imgcodecs.hpp>
Expand Down
15 changes: 0 additions & 15 deletions modules/io/src/image/private/vpImageIoPortable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* Backend for portable image format I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -49,14 +42,6 @@
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpImageConvert.h>

//TODO: is it needed?
//#if defined(_WIN32)
//// Include WinSock2.h before windows.h to ensure that winsock.h is not
//// included by windows.h since winsock.h and winsock2.h are incompatible
//#include <WinSock2.h>
//#include <windows.h>
//#endif


void vp_decodeHeaderPNM(const std::string &filename, std::ifstream &fd, const std::string &magic, unsigned int &w,
unsigned int &h, unsigned int &maxval);
Expand Down
8 changes: 0 additions & 8 deletions modules/io/src/image/private/vpImageIoSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* Simd backend for JPEG and PNG image I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -49,7 +42,6 @@
#include <Simd/SimdLib.h>


//TODO:
void readSimdlib(vpImage<unsigned char> &I, const std::string &filename)
{
size_t stride = 0, width = 0, height = 0;
Expand Down
9 changes: 0 additions & 9 deletions modules/io/src/image/private/vpImageIoStb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
<<<<<<< HEAD
* Read/write images.
*
* Authors:
* Eric Marchand
=======
* stb backend for JPEG and PNG image I/O operations.
>>>>>>> 557f1beda01f36ca886ec039d0a1a80a7446ca59
*
*****************************************************************************/

Expand All @@ -47,7 +40,6 @@

#include "vpImageIoBackend.h"

//TODO:
#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
# define VISP_HAVE_SSE2 1
#endif
Expand All @@ -63,7 +55,6 @@
#include <stb_image_write.h>


//TODO:
void readStb(vpImage<unsigned char> &I, const std::string &filename)
{
int width = 0, height = 0, channels = 0;
Expand Down
Loading

0 comments on commit 440892b

Please sign in to comment.