Skip to content

Commit

Permalink
add utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed May 3, 2024
1 parent b1cb0b2 commit 82d6550
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/threepp/utils/ImageUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#ifndef THREEPP_IMAGEUTILS_HPP
#define THREEPP_IMAGEUTILS_HPP

#include <vector>
#include <algorithm>

namespace threepp {

inline void convertBGRtoRGB(std::vector<unsigned char>& pixels) {
for (size_t i = 0; i < pixels.size(); i += 3) {
std::swap(pixels[i], pixels[i + 2]);
}
}

inline void flipImage(std::vector<unsigned char>& 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
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 82d6550

Please sign in to comment.