NHMLFixup v10
[jpcrr.git] / streamtools / rescalers / xdrop9.cpp
blob59ad5914c040e08b3783eaba857e0079f2e2dcae
1 #include "rescalers/simple.hpp"
2 #include <stdint.h>
3 #include <sstream>
4 #include <cmath>
5 #include <stdexcept>
7 namespace
9 void do_rescale(uint8_t* target, uint32_t twidth, uint32_t theight,
10 const uint8_t* source, uint32_t swidth, uint32_t sheight)
12 uint32_t* __restrict__ src = (uint32_t*)source;
13 uint32_t* __restrict__ dest = (uint32_t*)target;
15 if(twidth % 8)
16 throw std::runtime_error("Expected target width to be divisible by 8");
17 if(theight != sheight || swidth / 9 * 8 != twidth) {
18 std::ostringstream str;
19 str << "xdrop9: Expected source to have resolution of " << twidth / 8 * 9 << "x"
20 << theight << ", got " << swidth << "x" << sheight << ".";
21 throw std::runtime_error(str.str());
24 for(uint32_t y = 0; y < theight; y++)
25 for(uint32_t x = 0; x < twidth; x++) {
26 uint32_t _x = x / 8 * 9 + x % 8;
27 dest[y * twidth + x] = src[y * swidth + _x];
31 simple_rescaler factory("xdrop9", make_bound_method(do_rescale));