SDL_Main isn't needed on sane platforms anyway. Remove it
[jpcrr.git] / streamtools / resizer-xdrop9.cpp
blob321c0f859e0443d32168ee112fae5af719518868
1 #include "resize.hpp"
2 #include <stdint.h>
3 #include <cmath>
4 #include <stdexcept>
6 namespace
8 inline uint32_t nnscale(uint32_t value, uint32_t trange, uint32_t srange)
10 //x / trange is as good approximation for value / srange as possible.
11 //=> x is as good approximation for value * trange / srange as possible.
12 return (uint32_t)(((uint64_t)value * trange + srange / 2) / srange);
15 void do_resize(uint8_t* target, uint32_t twidth, uint32_t theight,
16 const uint8_t* source, uint32_t swidth, uint32_t sheight)
18 uint32_t* __restrict__ src = (uint32_t*)source;
19 uint32_t* __restrict__ dest = (uint32_t*)target;
20 uint32_t pwidth = swidth * 8 / 9 + swidth % 9;
22 for(uint32_t y = 0; y < theight; y++)
23 for(uint32_t x = 0; x < twidth; x++) {
24 uint32_t _x = nnscale(x, pwidth, twidth);
25 uint32_t _y = nnscale(y, sheight, theight);
26 _x = _x / 8 * 9 + _x % 8;
27 dest[y * twidth + x] = src[_y * swidth + _x];
31 simple_resizer factory("xdrop9", do_resize);