From 5522ebbb5d0ed861aee02e1064fb83e48e8456eb Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 10 Jul 2023 21:53:13 +0800 Subject: [PATCH 1/8] Add a dedicated CI for exclude deprecated --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cf0f586f9..e095fd966f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,7 @@ jobs: build_type: [standard] include: - raytracing_label: raytracing + - exclude_deprecated_label: no-exclude-deprecated - bundle_label: no-bundle - egl_label: no-egl - vtk_version: v9.0.0 @@ -73,6 +74,10 @@ jobs: os: ubuntu vtk_version: commit egl_label: egl + - build_type: exclude_deprecated + os: ubuntu + vtk_version: commit + exclude_deprecated_label: exclude-deprecated runs-on: ${{matrix.os}}-latest container: ${{ matrix.os == 'ubuntu' && 'ghcr.io/f3d-app/f3d-ci' || null }} @@ -163,6 +168,7 @@ jobs: -DCMAKE_PREFIX_PATH:PATH=$(pwd)/../dependencies/install/ -DF3D_BINDINGS_JAVA=ON -DF3D_BINDINGS_PYTHON=ON + -DF3D_EXCLUDE_DEPRECATED=${{ matrix.exclude_deprecated_label == 'exclude-deprecated' && 'ON' || 'OFF' }} -DF3D_LINUX_GENERATE_MAN=ON -DF3D_LINUX_INSTALL_DEFAULT_CONFIGURATION_FILE_IN_PREFIX=ON -DF3D_MACOS_BUNDLE=${{ matrix.bundle_label == 'bundle' && 'ON' || 'OFF' }} @@ -388,7 +394,6 @@ jobs: -DF3D_PLUGIN_BUILD_DRACO=ON -DF3D_PLUGIN_BUILD_OCCT=ON -DF3D_STRICT_BUILD=ON - -DF3D_EXCLUDE_DEPRECATED=ON -DF3D_TESTING_ENABLE_LONG_TIMEOUT_TESTS=ON - name: Build From 7a28f1d39c2718f6b6cbb87aaa82a6c275edf4c0 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 10 Jul 2023 22:12:09 +0800 Subject: [PATCH 2/8] Fix cache logic for supplementery builds --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e095fd966f..f1549dc847 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,15 +69,23 @@ jobs: os: macos vtk_version: commit raytracing_label: no-raytracing + exclude_deprecated_label: no-exclude-deprecated bundle_label: bundle + egl_label: no-egl - build_type: headless os: ubuntu vtk_version: commit + raytracing_label: raytracing + exclude_deprecated_label: no-exclude-deprecated + bundle_label: no-bundle egl_label: egl - build_type: exclude_deprecated os: ubuntu vtk_version: commit + raytracing_label: raytracing exclude_deprecated_label: exclude-deprecated + bundle_label: no-bundle + egl_label: no-egl runs-on: ${{matrix.os}}-latest container: ${{ matrix.os == 'ubuntu' && 'ghcr.io/f3d-app/f3d-ci' || null }} From ca5f525fe5e3e0f623e892babbc443b485016e36 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 10 Jul 2023 23:37:02 +0800 Subject: [PATCH 3/8] Fix a deprecated usage --- python/testing/TestPythonImageData.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/testing/TestPythonImageData.py b/python/testing/TestPythonImageData.py index a660440f47..6dff5b8a2e 100644 --- a/python/testing/TestPythonImageData.py +++ b/python/testing/TestPythonImageData.py @@ -42,7 +42,7 @@ '''set data back''' -img.setData(data) +img.setContent(data) assert img.getContent() == data '''check channel type and save image''' @@ -57,7 +57,7 @@ '''attempt to set partial data back''' try: - img.setData(data[:-1]) + img.setContent(data[:-1]) assert False, 'expected exception' except ValueError: assert True From 0c0b1915bc63e93be46ee3d6aea91a946f1a0cbc Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 10 Jul 2023 23:39:44 +0800 Subject: [PATCH 4/8] Add deprecated image python API tests back --- python/testing/CMakeLists.txt | 5 ++ .../testing/TestPythonImageDataDeprecated.py | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 python/testing/TestPythonImageDataDeprecated.py diff --git a/python/testing/CMakeLists.txt b/python/testing/CMakeLists.txt index c2d019a225..73624a718a 100644 --- a/python/testing/CMakeLists.txt +++ b/python/testing/CMakeLists.txt @@ -5,6 +5,11 @@ list(APPEND pyf3dTests_list TestPythonUtils.py ) +if(NOT F3D_EXCLUDE_DEPRECATED) + list(APPEND pyf3dTests_list + TestPythonImageDataDeprecated.py) +endif() + if(NOT F3D_MACOS_BUNDLE) list(APPEND pyf3dTests_list TestPythonPlugins.py diff --git a/python/testing/TestPythonImageDataDeprecated.py b/python/testing/TestPythonImageDataDeprecated.py new file mode 100644 index 0000000000..49926df52c --- /dev/null +++ b/python/testing/TestPythonImageDataDeprecated.py @@ -0,0 +1,55 @@ +import sys +if sys.platform.startswith('win32'): + import os + os.add_dll_directory(sys.argv[1]) + +import f3d + +engine = f3d.engine(f3d.window.NATIVE_OFFSCREEN) +window = engine.getWindow() +window.setSize(300, 200) + + +'''with background -> RGB image''' + +img = window.renderToImage() +width = img.getWidth() +height = img.getHeight() +depth = img.getChannelCount() +data = img.getData() + +assert width == window.getWidth() +assert height == window.getHeight() +assert depth == 3 +assert isinstance(data, (bytes, bytearray)) +assert len(data) == depth * width * height + + +'''without background -> RGBA image''' + +img = window.renderToImage(True) +width = img.getWidth() +height = img.getHeight() +depth = img.getChannelCount() +data = img.getData() + +assert width == window.getWidth() +assert height == window.getHeight() +assert depth == 4 +assert isinstance(data, (bytes, bytearray)) +assert len(data) == depth * width * height + + +'''set data back''' + +img.setData(data) +assert img.getData() == data + + +'''attempt to set partial data back''' + +try: + img.setData(data[:-1]) + assert False, 'expected exception' +except ValueError: + assert True From 6f5c9cf87c709b4aa9d930a4ff43c7ad83751907 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 10 Jul 2023 23:44:29 +0800 Subject: [PATCH 5/8] Adding CHANGELOG for #858 --- doc/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index e313ebc658..f8dd445714 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -7,7 +7,12 @@ For F3D users: - Fixed an issue with the binary release when opening draco files - Fixed an issue with matcap textures +For libf3d users: + - Reworked image API to support many file formats to read (EXR, HDR) and write (PNG, JPG, TIF, BMP) + - Deprecated previous image API + For developers: + - Added a deprecation framework For F3D packagers: - Fixed compatibility with FreeBSD From 6c17394e0ac744e0e3f3a1f9aa9c94f77d79743c Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Tue, 11 Jul 2023 00:07:49 +0800 Subject: [PATCH 6/8] Fix an issue in the image deprecated python bindings --- python/F3DPythonBindings.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/F3DPythonBindings.cxx b/python/F3DPythonBindings.cxx index 21aa909c4d..2f6578acc5 100644 --- a/python/F3DPythonBindings.cxx +++ b/python/F3DPythonBindings.cxx @@ -288,7 +288,7 @@ PYBIND11_MODULE(f3d, module) [=](const f3d::image& img) { PyErr_WarnEx(PyExc_DeprecationWarning, "getData is deprecated, use getContent instead.", 1); - getImageBytes(img); + return getImageBytes(img); }); #pragma GCC diagnostic pop #endif From fdad4a06553b1284acbf6b3d3b1ba0c9c2311d59 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Tue, 11 Jul 2023 00:52:21 +0800 Subject: [PATCH 7/8] Adding a SDK Deprecated test --- library/testing/CMakeLists.txt | 4 + library/testing/TestSDKImageDeprecated.cxx | 109 +++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 library/testing/TestSDKImageDeprecated.cxx diff --git a/library/testing/CMakeLists.txt b/library/testing/CMakeLists.txt index 3f9f191f12..641eaba23a 100644 --- a/library/testing/CMakeLists.txt +++ b/library/testing/CMakeLists.txt @@ -22,6 +22,10 @@ if(VTK_VERSION VERSION_GREATER 9.0.1) TestSDKDynamicLightIntensity.cxx TestSDKDynamicProperties.cxx ) + if(NOT F3D_EXCLUDE_DEPRECATED) + list(APPEND libf3dSDKTests_list + TestSDKImageDeprecated.cxx) + endif() endif() # Animation needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7246 diff --git a/library/testing/TestSDKImageDeprecated.cxx b/library/testing/TestSDKImageDeprecated.cxx new file mode 100644 index 0000000000..81d1a0c588 --- /dev/null +++ b/library/testing/TestSDKImageDeprecated.cxx @@ -0,0 +1,109 @@ +#include + +#include +#include +#include +#include + +int TestSDKImageDeprecated(int argc, char* argv[]) +{ + constexpr unsigned int width = 64; + constexpr unsigned int height = 64; + constexpr unsigned int channels = 3; + + std::vector pixels(width * height * channels); + + // fill with deterministic random values + // do not use std::uniform_int_distribution, it's not giving the same result on different + // platforms + std::mt19937 rand_generator; + std::generate(std::begin(pixels), std::end(pixels), [&]() { return rand_generator() % 256; }); + + f3d::image generated; + generated.setResolution(width, height).setChannelCount(channels).setData(pixels.data()); + generated.save(std::string(argv[2]) + "TestSDKImageDeprecated.png"); + + // test exceptions + try + { + generated.save("/dummy/folder/img.png"); + + std::cerr << "An exception has not been thrown when saving to an incorrect path" << std::endl; + return EXIT_FAILURE; + } + catch (const f3d::image::write_exception&) + { + } + + try + { + f3d::image img("/dummy/folder/img.png"); + + std::cerr << "An exception has not been thrown when reading an incorrect path" << std::endl; + return EXIT_FAILURE; + } + catch (const f3d::image::read_exception&) + { + } + + f3d::image baseline(std::string(argv[1]) + "/baselines/TestSDKImage.png"); + + if (generated.getWidth() != width || generated.getHeight() != height) + { + std::cerr << "Image has wrong dimensions" << std::endl; + return EXIT_FAILURE; + } + + if (generated.getChannelCount() != channels) + { + std::cerr << "Image has wrong number of channels" << std::endl; + return EXIT_FAILURE; + } + + if (generated.getData() == nullptr) + { + std::cerr << "Image has no data" << std::endl; + return EXIT_FAILURE; + } + + if (generated != baseline) + { + std::cerr << "Generated image is different from the baseline" << std::endl; + return EXIT_FAILURE; + } + + // test operators + f3d::image imgCopy = generated; // copy constructor + + if (imgCopy != generated) + { + std::cerr << "Copy constructor failed" << std::endl; + return EXIT_FAILURE; + } + + imgCopy = baseline; // copy assignment + + if (imgCopy != baseline) + { + std::cerr << "Copy assignment failed" << std::endl; + return EXIT_FAILURE; + } + + f3d::image imgMove = std::move(imgCopy); // move constructor + + if (imgMove != baseline) + { + std::cerr << "Move constructor failed" << std::endl; + return EXIT_FAILURE; + } + + imgCopy = std::move(imgMove); // move assignment + + if (imgCopy != baseline) + { + std::cerr << "Move assignment failed" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} From 357bf28d7abbf0b23316f5ea1f90125347d5e8fb Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Tue, 11 Jul 2023 17:30:08 +0800 Subject: [PATCH 8/8] fix cppcheck --- .cppcheck.supp | 1 + 1 file changed, 1 insertion(+) diff --git a/.cppcheck.supp b/.cppcheck.supp index a84f61b5ad..c7f12d5d2f 100644 --- a/.cppcheck.supp +++ b/.cppcheck.supp @@ -11,6 +11,7 @@ unusedFunction // specific checks knownConditionTrueFalse:library/testing/TestSDKImage.cxx +knownConditionTrueFalse:library/testing/TestSDKImageDeprecated.cxx noExplicitConstructor:library/public/types.h preprocessorErrorDirective:library/src/engine.cxx preprocessorErrorDirective:plugins/draco/module/vtkF3DDracoReader.cxx