diff --git a/vtkm/io/CMakeLists.txt b/vtkm/io/CMakeLists.txt index 2cb4fad43..2e5a15f11 100644 --- a/vtkm/io/CMakeLists.txt +++ b/vtkm/io/CMakeLists.txt @@ -10,10 +10,24 @@ set(headers ErrorIO.h + DecodePNG.h + EncodePNG.h +) + +set(sources + DecodePNG.cxx + EncodePNG.cxx ) vtkm_declare_headers(${headers}) +vtkm_library( NAME vtkm_io + SOURCES ${sources} + HEADERS ${headers} + ) + +target_link_libraries(vtkm_io PUBLIC vtkm_cont PRIVATE vtkm_lodepng) + add_subdirectory(internal) add_subdirectory(reader) add_subdirectory(writer) diff --git a/vtkm/rendering/DecodePNG.cxx b/vtkm/io/DecodePNG.cxx similarity index 93% rename from vtkm/rendering/DecodePNG.cxx rename to vtkm/io/DecodePNG.cxx index ab2a656e4..8d89e15b9 100644 --- a/vtkm/rendering/DecodePNG.cxx +++ b/vtkm/io/DecodePNG.cxx @@ -8,18 +8,19 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ -#include +#include #include #include + VTKM_THIRDPARTY_PRE_INCLUDE #include VTKM_THIRDPARTY_POST_INCLUDE namespace vtkm { -namespace rendering +namespace io { vtkm::UInt32 DecodePNG(std::vector& out_image, @@ -39,4 +40,4 @@ vtkm::UInt32 DecodePNG(std::vector& out_image, return retcode; } } -} // namespace vtkm::rendering +} // namespace vtkm::io diff --git a/vtkm/io/DecodePNG.h b/vtkm/io/DecodePNG.h new file mode 100644 index 000000000..1cc886d23 --- /dev/null +++ b/vtkm/io/DecodePNG.h @@ -0,0 +1,37 @@ +//============================================================================ +// 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. +//============================================================================ +#ifndef vtk_m_io_DecodePNG_h +#define vtk_m_io_DecodePNG_h + +#include +#include + +#include + +namespace vtkm +{ +namespace io +{ + +/// Decodes a PNG file buffer in memory, into a raw pixel buffer +/// Output is RGBA 32-bit (8 bit per channel) color format +/// no matter what color type the original PNG image had. This gives predictable, +/// usable data from any random input PNG. +/// +VTKM_IO_EXPORT +vtkm::UInt32 DecodePNG(std::vector& out_image, + unsigned long& image_width, + unsigned long& image_height, + const unsigned char* in_png, + std::size_t in_size); +} +} // vtkm::io + +#endif //vtk_m_io_DecodePNG_h diff --git a/vtkm/rendering/EncodePNG.cxx b/vtkm/io/EncodePNG.cxx similarity index 96% rename from vtkm/rendering/EncodePNG.cxx rename to vtkm/io/EncodePNG.cxx index 11dbb14ed..046f97afc 100644 --- a/vtkm/rendering/EncodePNG.cxx +++ b/vtkm/io/EncodePNG.cxx @@ -8,7 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ #include // for std::equal -#include +#include #include #include @@ -19,7 +19,7 @@ VTKM_THIRDPARTY_POST_INCLUDE namespace vtkm { -namespace rendering +namespace io { vtkm::UInt32 EncodePNG(std::vector const& image, @@ -68,4 +68,4 @@ vtkm::UInt32 SavePNG(std::string const& filename, return error; } } -} // namespace vtkm::rendering +} // namespace vtkm::io diff --git a/vtkm/io/EncodePNG.h b/vtkm/io/EncodePNG.h new file mode 100644 index 000000000..8b012973b --- /dev/null +++ b/vtkm/io/EncodePNG.h @@ -0,0 +1,38 @@ +//============================================================================ +// 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. +//============================================================================ +#ifndef vtk_m_io_EncodePNG_h +#define vtk_m_io_EncodePNG_h + +#include +#include + +#include + +namespace vtkm +{ +namespace io +{ + +VTKM_IO_EXPORT +vtkm::UInt32 EncodePNG(std::vector const& image, + unsigned long width, + unsigned long height, + unsigned char* out_png, + std::size_t out_size); + +VTKM_IO_EXPORT +vtkm::UInt32 SavePNG(std::string const& filename, + std::vector const& image, + unsigned long width, + unsigned long height); +} +} // vtkm::io + +#endif //vtk_m_io_EncodePNG_h diff --git a/vtkm/rendering/CMakeLists.txt b/vtkm/rendering/CMakeLists.txt index 2c80d8cda..add1b528f 100644 --- a/vtkm/rendering/CMakeLists.txt +++ b/vtkm/rendering/CMakeLists.txt @@ -50,8 +50,8 @@ set(headers ColorLegendAnnotation.h ConnectivityProxy.h Cylinderizer.h - DecodePNG.h - EncodePNG.h + DecodePNG.h # deprecated + EncodePNG.h # deprecated LineRenderer.h MatrixHelpers.h Scene.h @@ -85,8 +85,6 @@ set(sources Camera.cxx Color.cxx - DecodePNG.cxx - EncodePNG.cxx raytracing/Logger.cxx ) @@ -200,8 +198,7 @@ elseif(VTKm_ENABLE_EGL_CONTEXT) endif() #----------------------------------------------------------------------------- -target_link_libraries(vtkm_rendering PUBLIC vtkm_filter - PRIVATE vtkm_lodepng) +target_link_libraries(vtkm_rendering PUBLIC vtkm_filter vtkm_io) if(UNIX AND NOT APPLE) target_link_libraries(vtkm_rendering PRIVATE rt) endif() diff --git a/vtkm/rendering/Canvas.cxx b/vtkm/rendering/Canvas.cxx index 431c9e64d..8b510536f 100644 --- a/vtkm/rendering/Canvas.cxx +++ b/vtkm/rendering/Canvas.cxx @@ -12,9 +12,9 @@ #include #include +#include +#include #include -#include -#include #include #include #include @@ -523,7 +523,7 @@ bool Canvas::LoadFont() const const std::vector& rawPNG = Internals->Font.GetRawImageData(); std::vector rgba; unsigned long textureWidth, textureHeight; - auto error = DecodePNG(rgba, textureWidth, textureHeight, &rawPNG[0], rawPNG.size()); + auto error = io::DecodePNG(rgba, textureWidth, textureHeight, &rawPNG[0], rawPNG.size()); if (error != 0) { return false; @@ -598,7 +598,8 @@ void Canvas::SaveAs(const std::string& fileName) const } } - SavePNG(fileName, img, static_cast(width), static_cast(height)); + vtkm::io::SavePNG( + fileName, img, static_cast(width), static_cast(height)); return; } diff --git a/vtkm/rendering/DecodePNG.h b/vtkm/rendering/DecodePNG.h index 5f97f06a5..5f35b4b6c 100644 --- a/vtkm/rendering/DecodePNG.h +++ b/vtkm/rendering/DecodePNG.h @@ -9,29 +9,26 @@ //============================================================================ #ifndef vtk_m_rendering_DecodePNG_h #define vtk_m_rendering_DecodePNG_h - -#include +#include +#include #include -#include - namespace vtkm { namespace rendering { -/// Decodes a PNG file buffer in memory, into a raw pixel buffer -/// Output is RGBA 32-bit (8 bit per channel) color format -/// no matter what color type the original PNG image had. This gives predictable, -/// usable data from any random input PNG. -/// VTKM_RENDERING_EXPORT vtkm::UInt32 DecodePNG(std::vector& out_image, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, - std::size_t in_size); + std::size_t in_size) VTKM_DEPRECATED("Please use vtkm::io::DecodePNG") +{ + return vtkm::io::DecodePNG(out_image, image_width, image_height, in_png, in_size); +} } } // vtkm::rendering -#endif //vtk_m_rendering_DecodePNG_h + +#endif diff --git a/vtkm/rendering/EncodePNG.h b/vtkm/rendering/EncodePNG.h index bfca11c93..4bcb37735 100644 --- a/vtkm/rendering/EncodePNG.h +++ b/vtkm/rendering/EncodePNG.h @@ -10,11 +10,9 @@ #ifndef vtk_m_rendering_EncodePNG_h #define vtk_m_rendering_EncodePNG_h -#include +#include #include -#include - namespace vtkm { namespace rendering @@ -25,13 +23,19 @@ vtkm::UInt32 EncodePNG(std::vector const& image, unsigned long width, unsigned long height, unsigned char* out_png, - std::size_t out_size); + std::size_t out_size) VTKM_DEPRECATED("Please use vtkm::io::EncodePNG.") +{ + return io::EncodePNG(image, width, height, out_png, out_size); +} -VTKM_RENDERING_EXPORT +VTKM_IO_EXPORT vtkm::UInt32 SavePNG(std::string const& filename, std::vector const& image, unsigned long width, - unsigned long height); + unsigned long height) VTKM_DEPRECATED("Please use SavePNG from vtkm::io") +{ + return io::SavePNG(filename, image, width, height); +} } } // vtkm::rendering