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"