Streamtools: Refactor rescaling code
[jpcrr.git] / streamtools / rescalers / xdrop9.cpp
blob6899db2c5710cfb6bd8fe7b1f90013fe82fdbfb0
1 #include "rescalers/simple.hpp"
2 #include <stdint.h>
3 #include <cmath>
4 #include <stdexcept>
6 namespace
8 void do_rescale(uint8_t* target, uint32_t twidth, uint32_t theight,
9 const uint8_t* source, uint32_t swidth, uint32_t sheight)
11 uint32_t* __restrict__ src = (uint32_t*)source;
12 uint32_t* __restrict__ dest = (uint32_t*)target;
14 if(theight != sheight || twidth % 8 || swidth % 9 || swidth / 9 * 8 != twidth)
15 throw std::runtime_error("xdrop9: Incorrect scale factor");
17 for(uint32_t y = 0; y < theight; y++)
18 for(uint32_t x = 0; x < twidth; x++) {
19 uint32_t _x = x / 8 * 9 + x % 8;
20 dest[y * twidth + x] = src[y * swidth + _x];
24 simple_rescaler factory("xdrop9", make_bound_method(do_rescale));