-
Notifications
You must be signed in to change notification settings - Fork 4
/
scale.c
98 lines (85 loc) · 2.68 KB
/
scale.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
normalmap GIMP plugin
Copyright (C) 2002-2012 Shawn Kirst <skirst@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
*/
#include "scale.h"
void scale_pixels(unsigned char *dst, int dw, int dh,
unsigned char *src, int sw, int sh,
int bpp)
{
int x, y, n, ix, iy, wx, wy, v;
int a, b, c, d;
int dstride = dw * bpp;
unsigned char *s;
for(y = 0; y < dh; ++y)
{
if(dh > 1)
{
iy = (((sh - 1) * y) << 7) / (dh - 1);
if(y == dh - 1) --iy;
wy = iy & 0x7f;
iy >>= 7;
}
else
iy = wy = 0;
for(x = 0; x < dw; ++x)
{
if(dw > 1)
{
ix = (((sw - 1) * x) << 7) / (dw - 1);
if(x == dw - 1) --ix;
wx = ix & 0x7f;
ix >>= 7;
}
else
ix = wx = 0;
s = src + ((iy - 1) * sw + (ix - 1)) * bpp;
for(n = 0; n < bpp; ++n)
{
b = icerp(s[(sw + 0) * bpp],
s[(sw + 1) * bpp],
s[(sw + 2) * bpp],
s[(sw + 3) * bpp], wx);
if(iy > 0)
{
a = icerp(s[ 0],
s[ bpp],
s[2 * bpp],
s[3 * bpp], wx);
}
else
a = b;
c = icerp(s[(2 * sw + 0) * bpp],
s[(2 * sw + 1) * bpp],
s[(2 * sw + 2) * bpp],
s[(2 * sw + 3) * bpp], wx);
if(iy < dh - 1)
{
d = icerp(s[(3 * sw + 0) * bpp],
s[(3 * sw + 1) * bpp],
s[(3 * sw + 2) * bpp],
s[(3 * sw + 3) * bpp], wx);
}
else
d = c;
v = icerp(a, b, c, d, wy);
if(v < 0) v = 0;
if(v > 255) v = 255;
dst[(y * dstride) + (x * bpp) + n] = v;
++s;
}
}
}
}