/
BilinearScalerInternal_X2Y24.cpp
146 lines (110 loc) · 3.29 KB
/
BilinearScalerInternal_X2Y24.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright (C) 2005 The Pentagram Team
Copyright (C) 2010 The Exult Team
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; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pent_include.h"
#include "BilinearScalerInternal.h"
#include "manip.h"
namespace Pentagram {
template<class uintX, class Manip, class uintS>
bool BilinearScalerInternal_X2Y24(SDL_Surface *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh,
uint8 *pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src) {
ignore_unused_variable_warning(dh);
// Source buffer pointers
int tpitch = tex->pitch / sizeof(uintS);
uintS *texel = static_cast<uintS *>(tex->pixels) + (sy * tpitch + sx);
uintS *tline_end = texel + (sw - 1);
uintS *tex_end = texel + (sh - 5) * tpitch;
int tex_diff = (tpitch * 5) - sw;
uint8 a[4], b[4], c[4], d[4], e[4], f[4], g[4], h[4], i[4], j[4], k[4], l[4];
uint8 cols[2][12][4];
bool clip_x = true;
if (sw + sx < tpitch && clamp_src == false) {
clip_x = false;
tline_end = texel + (sw + 1);
tex_diff--;
}
bool clip_y = true;
if (sh + sy < tex->h && clamp_src == false) {
clip_y = false;
tex_end = texel + (sh) * tpitch;
}
// Src Loop Y
do {
Read6(a, b, c, d, e, l);
texel++;
X2xY24xDoColsA();
// Src Loop X
do {
Read6(f, g, h, i, j, k);
texel++;
X2xY24xDoColsB();
X2xY24xInnerLoop(0, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
Read6(a, b, c, d, e, l);
texel++;
X2xY24xDoColsA();
X2xY24xInnerLoop(1, 0);
pixel -= pitch * 12 - sizeof(uintX) * 2;
} while (texel != tline_end);
// Final X (clipping)
if (clip_x) {
Read6(f, g, h, i, j, k);
texel++;
X2xY24xDoColsB();
X2xY24xInnerLoop(0, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
X2xY24xInnerLoop(1, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
}
pixel += pitch * 12 - sizeof(uintX) * (dw);
texel += tex_diff;
tline_end += tpitch * 5;
} while (texel != tex_end);
//
// Final Rows - Clipping
//
// Src Loop Y
if (clip_y) {
Read6_Clipped(a, b, c, d, e, l);
texel++;
X2xY24xDoColsA();
// Src Loop X
do {
Read6_Clipped(f, g, h, i, j, k);
texel++;
X2xY24xDoColsB();
X2xY24xInnerLoop(0, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
Read6_Clipped(a, b, c, d, e, l);
texel++;
X2xY24xDoColsA();
X2xY24xInnerLoop(1, 0);
pixel -= pitch * 12 - sizeof(uintX) * 2;
} while (texel != tline_end);
// Final X (clipping)
if (clip_x) {
Read6_Clipped(f, g, h, i, j, k);
texel++;
X2xY24xDoColsB();
X2xY24xInnerLoop(0, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
X2xY24xInnerLoop(1, 1);
pixel -= pitch * 12 - sizeof(uintX) * 2;
};
}
return true;
}
InstantiateBilinearScalerFunc(BilinearScalerInternal_X2Y24);
}