polaroid-pp

Schlieren and contour plot tool
git clone https://git.0xfab.ch/polaroid-pp.git
Log | Files | Refs | Submodules | README | LICENSE

commit 01500eacd240b26e22452fa7e8c423c4ac8b6e68
parent de939a24263ac901cbf46c8c780f424fb2b3310c
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date:   Mon,  3 Oct 2016 20:11:20 +0200

added byte swap streamer

Diffstat:
Msrc/Polaroid.cpp | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/Polaroid.cpp b/src/Polaroid.cpp @@ -5,6 +5,7 @@ // Copyright 2016 ETH Zurich. All Rights Reserved. #include <cassert> #include <cmath> +#include <cstring> #include <algorithm> #include <string> #include <sstream> @@ -22,6 +23,21 @@ using namespace std; #define ID3(ix, iy, iz, NX, NY) ((ix) + (NX) * ((iy) + (NY) * (iz))) +template <typename T> +inline void _streamSwap(const size_t n, unsigned char * const stream) +{ + constexpr size_t _e = sizeof(T); + unsigned char _buf[_e]; + for (size_t i = 0; i < n*_e; i += _e) + { + const unsigned char * const upstream = stream + i + (_e - 1); +#pragma unroll(_e) + for (int j = 0; j < _e; ++j) + _buf[j] = *(upstream - j); + std::memcpy(stream+i, &_buf[0], _e); + } +} + void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) { #ifdef _USE_HDF_ @@ -30,6 +46,7 @@ void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) const char direction = parser("-sd").asString("x")[0]; // slice normal direction const int channel = parser("-channel").asInt(0); // data channel const bool magnitude = parser("-magnitude").asBool(false); // vector magnitude (only if NCH == 3) + const bool swap = parser("-swap").asBool(false); // swap bytes? /* open data */ hid_t file_id, dataset_id, dataspace_id, file_dataspace_id; @@ -156,6 +173,7 @@ void Polaroid::load_hdf5_slice(const char* filename, ArgumentParser& parser) #ifdef _USE_HDF_ const int channel = parser("-channel").asInt(0); // data channel const bool magnitude = parser("-magnitude").asBool(false); // vector magnitude (only if NCH == 3) + const bool swap = parser("-swap").asBool(false); // swap bytes? /* open data */ hid_t file_id, dataset_id, dataspace_id, file_dataspace_id;