From 82d6550d577bdeac61e0e41c951f409f8e161c8a Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Fri, 3 May 2024 13:33:39 +0200 Subject: [PATCH] add utility functions --- include/threepp/utils/ImageUtils.hpp | 26 ++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + 2 files changed, 27 insertions(+) create mode 100644 include/threepp/utils/ImageUtils.hpp diff --git a/include/threepp/utils/ImageUtils.hpp b/include/threepp/utils/ImageUtils.hpp new file mode 100644 index 000000000..da04e5b91 --- /dev/null +++ b/include/threepp/utils/ImageUtils.hpp @@ -0,0 +1,26 @@ + +#ifndef THREEPP_IMAGEUTILS_HPP +#define THREEPP_IMAGEUTILS_HPP + +#include +#include + +namespace threepp { + + inline void convertBGRtoRGB(std::vector& pixels) { + for (size_t i = 0; i < pixels.size(); i += 3) { + std::swap(pixels[i], pixels[i + 2]); + } + } + + inline void flipImage(std::vector& pixels, int channels, int w, int h) { + for (int line = 0; line != h / 2; ++line) { + std::swap_ranges(pixels.begin() + channels * w * line, + pixels.begin() + channels * w * (line + 1), + pixels.begin() + channels * w * (h - line - 1)); + } + } + +}// namespace threepp + +#endif //THREEPP_IMAGEUTILS_HPP diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a462a1203..fa70a1a8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -170,6 +170,7 @@ set(publicHeaders "threepp/textures/Texture.hpp" "threepp/utils/BufferGeometryUtils.hpp" + "threepp/utils/ImageUtils.hpp" "threepp/utils/StringUtils.hpp" "threepp/lights/lights.hpp"