lodepng: remove interface dependency

It also avoid installing lodepng.a in the vtk-m shared build.
This commit is contained in:
Vicente Adolfo Bolea Sanchez 2022-08-22 21:54:49 -04:00
parent 6a6bc011a6
commit c92abc4093
13 changed files with 80 additions and 76 deletions

@ -114,6 +114,8 @@ function(do_verify root_dir prefix)
set(file_exceptions
thirdparty/diy/vtkmdiy/cmake/mpi_types.h
thirdparty/lodepng/vtkmlodepng/lodepng.h
thirdparty/loguru/vtkmloguru/loguru.hpp
# Ignore deprecated virtual classes (which are not installed if VTKm_NO_DEPRECATED_VIRTUAL
# is on). These exceptions can be removed when these files are completely removed.

@ -27,6 +27,5 @@ Libs: -L${libdir} \
-lvtkm_worklet-@VTKm_VERSION@ \
-lvtkm_source-@VTKm_VERSION@ \
-lvtkm_io-@VTKm_VERSION@ \
-lvtkm_lodepng-@VTKm_VERSION@ \
-lvtkm_cont-@VTKm_VERSION@ \
-lvtkmdiympi_nompi

@ -34,6 +34,5 @@ VTKm_LIB_FLAGS = -L $(VTKm_DIR)/lib \
-lvtkm_worklet-$(VTKM_VERSION) \
-lvtkm_source-$(VTKM_VERSION) \
-lvtkm_io-$(VTKM_VERSION) \
-lvtkm_lodepng-$(VTKM_VERSION) \
-lvtkm_cont-$(VTKM_VERSION) \
-lvtkmdiympi_nompi

@ -48,6 +48,7 @@ set(sources
ImageWriterBase.cxx
ImageWriterPNG.cxx
ImageWriterPNM.cxx
PixelTypes.cxx
VTKDataSetReader.cxx
VTKDataSetReaderBase.cxx
VTKDataSetWriter.cxx
@ -82,6 +83,7 @@ vtkm_library(
TEMPLATE_SOURCES ${template_sources}
)
# CMAKE 3.12 does not know about PRIVATE TARGET_OBJECTS
target_link_libraries(vtkm_io PUBLIC vtkm_cont PRIVATE vtkm_lodepng)
if (VTKm_ENABLE_HDF5_IO)
target_include_directories(vtkm_io PRIVATE $<BUILD_INTERFACE:${HDF5_INCLUDE_DIR}>)

@ -12,6 +12,10 @@
#include <vtkm/io/PixelTypes.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <vtkm/thirdparty/lodepng/vtkmlodepng/lodepng.h>
VTKM_THIRDPARTY_POST_INCLUDE
namespace
{
@ -23,12 +27,13 @@ vtkm::io::ImageReaderBase::ColorArrayType ReadFromPNG(const std::string& fileNam
{
unsigned char* imageData;
unsigned uwidth, uheight;
vtkm::png::lodepng_decode_file(&imageData,
&uwidth,
&uheight,
fileName.c_str(),
PixelType::PNG_COLOR_TYPE,
PixelType::BIT_DEPTH);
vtkm::png::lodepng_decode_file(
&imageData,
&uwidth,
&uheight,
fileName.c_str(),
static_cast<vtkm::png::LodePNGColorType>(PixelType::GetColorType()),
PixelType::GetBitDepth());
width = static_cast<vtkm::Id>(uwidth);
height = static_cast<vtkm::Id>(uheight);

@ -56,12 +56,13 @@ void ImageWriterPNG::WriteToFile(vtkm::Id width, vtkm::Id height, const ColorArr
}
}
vtkm::png::lodepng_encode_file(this->FileName.c_str(),
imageData.data(),
static_cast<unsigned>(width),
static_cast<unsigned>(height),
PixelType::PNG_COLOR_TYPE,
PixelType::BIT_DEPTH);
vtkm::png::lodepng_encode_file(
this->FileName.c_str(),
imageData.data(),
static_cast<unsigned>(width),
static_cast<unsigned>(height),
static_cast<vtkm::png::LodePNGColorType>(PixelType::GetColorType()),
PixelType::GetBitDepth());
}
}
} // namespace vtkm::io

19
vtkm/io/PixelTypes.cxx Normal file

@ -0,0 +1,19 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/PixelTypes.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <vtkm/thirdparty/lodepng/vtkmlodepng/lodepng.h>
VTKM_THIRDPARTY_POST_INCLUDE
int vtkm::io::internal::GreyColorType = static_cast<int>(vtkm::png::LodePNGColorType::LCT_GREY);
int vtkm::io::internal::RGBColorType = static_cast<int>(vtkm::png::LodePNGColorType::LCT_RGB);

@ -13,15 +13,20 @@
#include <vtkm/Types.h>
#include <vtkm/VecTraits.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <vtkm/thirdparty/lodepng/vtkmlodepng/lodepng.h>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm
{
namespace io
{
namespace internal
{
extern int GreyColorType;
extern int RGBColorType;
}
// ----------------------------------------------------------------------
// Define custom SFINAE structures to calculate the VTKM types associated
// with provided BitDepths
@ -75,6 +80,10 @@ public:
static constexpr vtkm::IdComponent MAX_COLOR_VALUE = (1 << BitDepth) - 1;
static constexpr vtkm::IdComponent NUM_CHANNELS = Superclass::NUM_COMPONENTS;
static constexpr vtkm::IdComponent BYTES_PER_PIXEL = NUM_CHANNELS * NUM_BYTES;
static constexpr vtkm::IdComponent GetBitDepth()
{
return BasePixel<BitDepth, Channels>::BIT_DEPTH;
}
using Superclass::Superclass;
BasePixel() = default;
@ -131,8 +140,6 @@ public:
// RGB values are stored in a vtkm::Vec<ComponentType, 3>
using Superclass = BasePixel<BitDepth, 3>;
using ComponentType = typename Superclass::ComponentType;
static constexpr vtkm::png::LodePNGColorType PNG_COLOR_TYPE =
vtkm::png::LodePNGColorType::LCT_RGB;
using Superclass::Superclass;
RGBPixel() = default;
@ -145,6 +152,9 @@ public:
virtual ~RGBPixel() = default;
// Get the implementation specific color type (Gray|RGB) value
static int GetColorType();
ComponentType Diff(const Superclass& pixel) const override;
vtkm::Vec4f_32 ToVec4f() const override;
@ -169,8 +179,6 @@ public:
// in order to simplify the pixel helper functions
using Superclass = BasePixel<BitDepth, 1>;
using ComponentType = typename Superclass::ComponentType;
static constexpr vtkm::png::LodePNGColorType PNG_COLOR_TYPE =
vtkm::png::LodePNGColorType::LCT_GREY;
using Superclass::Superclass;
GreyPixel() = default;
@ -182,6 +190,9 @@ public:
virtual ~GreyPixel() = default;
// Get the implementation specific color type (Gray|RGB) value
static int GetColorType();
ComponentType Diff(const Superclass& pixel) const override;
vtkm::Vec4f_32 ToVec4f() const override;

@ -78,6 +78,17 @@ vtkm::Vec4f_32 GreyPixel<B>::ToVec4f() const
1);
}
template <const vtkm::Id B>
int RGBPixel<B>::GetColorType()
{
return internal::RGBColorType;
}
template <const vtkm::Id B>
int GreyPixel<B>::GetColorType()
{
return internal::GreyColorType;
}
} // namespace io
} // namespace vtkm

@ -16,7 +16,7 @@ set(unit_tests
UnitTestVTKDataSetWriter.cxx
)
set(unit_test_libraries vtkm_lodepng vtkm_io)
set(unit_test_libraries vtkm_io)
if(VTKm_ENABLE_RENDERING)
list(APPEND unit_tests

@ -106,6 +106,7 @@ void TestGreyPixelConstructors()
"Incorrect Conversion");
VTKM_TEST_ASSERT(vtkm::Vec<vtkm::UInt16, 1>(10) == pixel_7, "Bad Vec4f_32 construction");
VTKM_TEST_ASSERT(GreyPixel<16>::GetBitDepth() == 16, "Bad BitDepth");
VTKM_TEST_ASSERT(GreyPixel<16>::BIT_DEPTH == 16, "Bad BitDepth");
VTKM_TEST_ASSERT(GreyPixel<16>::NUM_BYTES == 2, "Bad NumBytes");
VTKM_TEST_ASSERT(GreyPixel<16>::MAX_COLOR_VALUE == 65535, "Bad NumBytes");
@ -146,6 +147,7 @@ void TestRGBPixelConstructors()
"Incorrect Conversion");
VTKM_TEST_ASSERT(vtkm::Vec<vtkm::UInt16, 3>(10, 10, 10) == pixel_8, "Bad Vec4f_32 construction");
VTKM_TEST_ASSERT(RGBPixel<16>::GetBitDepth() == 16, "Bad BitDepth");
VTKM_TEST_ASSERT(RGBPixel<16>::BIT_DEPTH == 16, "Bad BitDepth");
VTKM_TEST_ASSERT(RGBPixel<16>::NUM_BYTES == 2, "Bad NumBytes");
VTKM_TEST_ASSERT(RGBPixel<16>::MAX_COLOR_VALUE == 65535, "Bad NumBytes");

@ -7,53 +7,12 @@
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##============================================================================
set(headers
vtkmlodepng/lodepng.h
)
set(sources
vtkmlodepng/lodepng.cpp
)
# Mark this lib as STATIC for usage in Windows without requiring dll_export
# if a SHARED lib is ever required you will need to generate the export
# headers and add them to the lodepng functions that should be shared
add_library(vtkm_lodepng STATIC ${headers} ${sources})
add_library(vtkm_lodepng OBJECT vtkmlodepng/lodepng.cpp)
if(DEFINED VTKm_CUSTOM_LIBRARY_SUFFIX)
set(_lib_suffix "${VTKm_CUSTOM_LIBRARY_SUFFIX}")
else()
set(_lib_suffix "-${VTKm_VERSION_MAJOR}.${VTKm_VERSION_MINOR}")
endif()
set_target_properties(vtkm_lodepng
PROPERTIES
OUTPUT_NAME "vtkm_lodepng${_lib_suffix}"
LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}
ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH}
POSITION_INDEPENDENT_CODE ON
)
if (NOT VTKm_SKIP_LIBRARY_VERSIONS)
set_target_properties(vtkm_lodepng
PROPERTIES
VERSION 1
SOVERSION 1
)
endif ()
target_include_directories(vtkm_lodepng INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${VTKm_INSTALL_INCLUDE_DIR}/vtkm/thirdparty/lodepng>
)
# To be consumed by other potentially PIC libraries
set_target_properties(vtkm_lodepng PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(NOT VTKm_INSTALL_ONLY_LIBRARIES)
install(FILES ${headers}
DESTINATION "${VTKm_INSTALL_INCLUDE_DIR}/vtkm/thirdparty/lodepng/vtkmlodepng/"
)
endif()
install(TARGETS vtkm_lodepng
EXPORT ${VTKm_EXPORT_NAME}
LIBRARY DESTINATION ${VTKm_INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${VTKm_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${VTKm_INSTALL_BIN_DIR}
COMPONENT libraries
)
# This will not install anything but it is needed for CMake <= 3.21 since it
# does not fully support $<TARGET_OBJECTS> in target_link_library.
install(TARGETS vtkm_lodepng EXPORT ${VTKm_EXPORT_NAME})

@ -22,9 +22,3 @@ target_link_libraries(vtkm_loguru INTERFACE ${CMAKE_DL_LIBS} Threads::Threads)
install(TARGETS vtkm_loguru
EXPORT ${VTKm_EXPORT_NAME})
## Install headers
if(NOT VTKm_INSTALL_ONLY_LIBRARIES)
install(DIRECTORY vtkmloguru
DESTINATION ${VTKm_INSTALL_INCLUDE_DIR}/${kit_dir}/)
endif()