Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: image I/O backend for JPEG and PNG types #1004

Merged
merged 12 commits into from
Jan 26, 2022
Merged
10 changes: 1 addition & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +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()

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
19 changes: 11 additions & 8 deletions modules/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ if(USE_PNG)
add_definitions(${PNG_DEFINITIONS})
endif()

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

if(WITH_CATCH2)
# catch2 is private
include_directories(${CATCH2_INCLUDE_DIRS})
endif()

# simdlib is always enabled since it contains fallback code to plain C++ code
# Simd lib is private
include_directories(${SIMDLIB_INCLUDE_DIRS})

# OpenCV
if(USE_OPENCV)
# On win32 since OpenCV 2.4.7 and on OSX with OpenCV 2.4.10 we cannot use OpenCV_LIBS to set ViSP 3rd party libraries.
Expand Down Expand Up @@ -169,11 +176,6 @@ if(USE_OPENCV)
endif()
endif(USE_OPENCV)

if(WITH_CATCH2)
# catch2 is private
include_directories(${CATCH2_INCLUDE_DIRS})
endif()

if(ANDROID)
vp_add_module(io visp_core)
else()
Expand All @@ -187,3 +189,4 @@ vp_add_tests()

vp_set_source_file_compile_flag(src/tools/vpParseArgv.cpp -Wno-strict-overflow)
vp_set_source_file_compile_flag(src/image/vpImageIo.cpp -Wno-missing-field-initializers) # since stb_image_write.h update from v1.13 to v1.16
vp_set_source_file_compile_flag(src/image/private/vpImageIoStb.cpp -Wno-missing-field-initializers)
33 changes: 21 additions & 12 deletions modules/io/include/visp3/io/vpImageIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,20 @@ class VISP_EXPORT vpImageIo
static std::string getExtension(const std::string &filename);

public:
static void read(vpImage<unsigned char> &I, const std::string &filename);
static void read(vpImage<vpRGBa> &I, const std::string &filename);
// Image IO backend for only jpeg and png formats
enum vpImageIoBackendType {
IO_DEFAULT_BACKEND,
IO_SYSTEM_LIB_BACKEND,
IO_OPENCV_BACKEND,
IO_SIMDLIB_BACKEND,
IO_STB_IMAGE_BACKEND
};

static void write(const vpImage<unsigned char> &I, const std::string &filename);
static void write(const vpImage<vpRGBa> &I, const std::string &filename);
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, 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 @@ -138,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);
static void readJPEG(vpImage<vpRGBa> &I, const std::string &filename);
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);
static void readPNG(vpImage<vpRGBa> &I, const std::string &filename);
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);
fspindle marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -153,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);
static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename);
static void writeJPEG(const vpImage<unsigned char> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90);
static void writeJPEG(const vpImage<vpRGBa> &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND, int quality=90);

static void writePNG(const vpImage<unsigned char> &I, const std::string &filename);
static void writePNG(const vpImage<vpRGBa> &I, const std::string &filename);
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
103 changes: 103 additions & 0 deletions modules/io/src/image/private/vpImageIoBackend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2022 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See http://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at [email protected]
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Backend functions implementation for image I/O operations.
*
*****************************************************************************/

/*!
\file vpImageIoBackend.h
\brief Backend functions implementation for image I/O operations.
*/

#ifndef vpIMAGEIOBACKEND_H
#define vpIMAGEIOBACKEND_H

#include <visp3/core/vpImage.h>


// Portable FloatMap format (PFM)
// Portable Graymap format (PGM)
// Portable Pixmap format (PPM)
void vp_writePFM(const vpImage<float> &I, const std::string &filename);
void vp_writePGM(const vpImage<unsigned char> &I, const std::string &filename);
void vp_writePGM(const vpImage<short> &I, const std::string &filename);
void vp_writePGM(const vpImage<vpRGBa> &I, const std::string &filename);
void vp_readPFM(vpImage<float> &I, const std::string &filename);
void vp_readPGM(vpImage<unsigned char> &I, const std::string &filename);
void vp_readPGM(vpImage<vpRGBa> &I, const std::string &filename);
void vp_readPPM(vpImage<unsigned char> &I, const std::string &filename);
void vp_readPPM(vpImage<vpRGBa> &I, const std::string &filename);
void vp_writePPM(const vpImage<unsigned char> &I, const std::string &filename);
void vp_writePPM(const vpImage<vpRGBa> &I, const std::string &filename);

// libjpeg
void readJPEGLibjpeg(vpImage<unsigned char> &I, const std::string &filename);
void readJPEGLibjpeg(vpImage<vpRGBa> &I, const std::string &filename);

void writeJPEGLibjpeg(const vpImage<unsigned char> &I, const std::string &filename, int quality);
void writeJPEGLibjpeg(const vpImage<vpRGBa> &I, const std::string &filename, int quality);

// libpng
void readPNGLibpng(vpImage<unsigned char> &I, const std::string &filename);
void readPNGLibpng(vpImage<vpRGBa> &I, const std::string &filename);

void writePNGLibpng(const vpImage<unsigned char> &I, const std::string &filename);
void writePNGLibpng(const vpImage<vpRGBa> &I, const std::string &filename);

// OpenCV
void readOpenCV(vpImage<unsigned char> &I, const std::string &filename);
void readOpenCV(vpImage<vpRGBa> &I, const std::string &filename);

void writeOpenCV(const vpImage<unsigned char> &I, const std::string &filename, int quality);
void writeOpenCV(const vpImage<vpRGBa> &I, const std::string &filename, int quality);

// Simd lib
void readSimdlib(vpImage<unsigned char> &I, const std::string &filename);
void readSimdlib(vpImage<vpRGBa> &I, const std::string &filename);

void writeJPEGSimdlib(const vpImage<unsigned char> &I, const std::string &filename, int quality);
void writeJPEGSimdlib(const vpImage<vpRGBa> &I, const std::string &filename, int quality);

void writePNGSimdlib(const vpImage<unsigned char> &I, const std::string &filename);
void writePNGSimdlib(const vpImage<vpRGBa> &I, const std::string &filename);

// stb lib
void readStb(vpImage<unsigned char> &I, const std::string &filename);
void readStb(vpImage<vpRGBa> &I, const std::string &filename);

void writeJPEGStb(const vpImage<unsigned char> &I, const std::string &filename, int quality);
void writeJPEGStb(const vpImage<vpRGBa> &I, const std::string &filename, int quality);

void writePNGStb(const vpImage<unsigned char> &I, const std::string &filename);
void writePNGStb(const vpImage<vpRGBa> &I, const std::string &filename);

#endif
Loading