1 | |
2 | #pragma once |
3 | |
4 | #include "arithmetics.hpp" |
5 | #include "Vector2.h" |
6 | #include "BitmapRef.hpp" |
7 | |
8 | namespace msdfgen { |
9 | |
10 | template <typename T, int N> |
11 | static void interpolate(T *output, const BitmapConstRef<T, N> &bitmap, Point2 pos) { |
12 | pos -= .5; |
13 | int l = (int) floor(pos.x); |
14 | int b = (int) floor(pos.y); |
15 | int r = l+1; |
16 | int t = b+1; |
17 | double lr = pos.x-l; |
18 | double bt = pos.y-b; |
19 | l = clamp(l, bitmap.width-1), r = clamp(r, bitmap.width-1); |
20 | b = clamp(b, bitmap.height-1), t = clamp(t, bitmap.height-1); |
21 | for (int i = 0; i < N; ++i) |
22 | output[i] = mix(mix(bitmap(l, b)[i], bitmap(r, b)[i], lr), mix(bitmap(l, t)[i], bitmap(r, t)[i], lr), bt); |
23 | } |
24 | |
25 | } |
26 | |