forked from usineur/hode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scaler_nearest.cpp
46 lines (43 loc) · 906 Bytes
/
scaler_nearest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "scaler.h"
static void scale_nearest(int factor, uint32_t *dst, int dstPitch, const uint32_t *src, int srcPitch, int w, int h) {
switch (factor) {
case 2:
while (h--) {
uint32_t *p = dst;
for (int i = 0; i < w; ++i, p += 2) {
uint32_t c = *(src + i);
*(p) = c;
*(p + 1) = c;
*(p + dstPitch) = c;
*(p + dstPitch + 1) = c;
}
dst += dstPitch * 2;
src += srcPitch;
}
break;
case 3:
while (h--) {
uint32_t *p = dst;
for (int i = 0; i < w; ++i, p += 3) {
uint32_t c = *(src + i);
*(p) = c;
*(p + 1) = c;
*(p + 2) = c;
*(p + dstPitch) = c;
*(p + dstPitch + 1) = c;
*(p + dstPitch + 2) = c;
*(p + 2 * dstPitch) = c;
*(p + 2 * dstPitch + 1) = c;
*(p + 2 * dstPitch + 2) = c;
}
dst += dstPitch * 3;
src += srcPitch;
}
break;
}
}
const Scaler scaler_nearest = {
"nearest",
2, 3,
scale_nearest
};