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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
// VirtualDub - Video processing and capture application
// Graphics support library
// Copyright (C) 1998-2009 Avery Lee
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdafx.h>
#include <vd2/system/memory.h>
#include <vd2/system/cpuaccel.h>
#include <vd2/Kasumi/pixmaputils.h>
#include "resample_stages_reference.h"
#include <vd2/Kasumi/resample_kernels.h>
#include "blt_spanutils.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
int VDResamplerRowStageSeparablePoint8::GetWindowSize() const {
return 1;
}
void VDResamplerRowStageSeparablePoint8::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint8 *dst = (uint8 *)dst0;
const uint8 *src = (const uint8 *)src0;
do {
*dst++ = src[u>>16];
u += dudx;
} while(--w);
}
int VDResamplerRowStageSeparablePoint16::GetWindowSize() const {
return 1;
}
void VDResamplerRowStageSeparablePoint16::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint16 *dst = (uint16 *)dst0;
const uint16 *src = (const uint16 *)src0;
do {
*dst++ = src[u>>16];
u += dudx;
} while(--w);
}
int VDResamplerRowStageSeparablePoint32::GetWindowSize() const {
return 1;
}
void VDResamplerRowStageSeparablePoint32::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src = (const uint32 *)src0;
do {
*dst++ = src[u>>16];
u += dudx;
} while(--w);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
int VDResamplerRowStageSeparableLinear8::GetWindowSize() const {return 2;}
void VDResamplerRowStageSeparableLinear8::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint8 *dst = (uint8 *)dst0;
const uint8 *src = (const uint8 *)src0;
do {
const sint32 iu = u>>16;
const uint32 p0 = src[iu];
const uint32 p1 = src[iu+1];
const uint32 f = (u >> 8) & 0xff;
*dst++ = (uint8)(p0 + (((sint32)(p1 - p0)*f + 0x80)>>8));
u += dudx;
} while(--w);
}
void VDResamplerRowStageSeparableLinear8_phaseZeroStepHalf::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint8 *dst = (uint8 *)dst0;
const uint8 *src = (const uint8 *)src0;
VDASSERT(!u && dudx == 0x8000);
nsVDPixmapSpanUtils::horiz_expand2x_coaligned(dst, src, w);
}
int VDResamplerRowStageSeparableLinear32::GetWindowSize() const {return 2;}
void VDResamplerRowStageSeparableLinear32::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src = (const uint32 *)src0;
do {
const sint32 iu = u>>16;
const uint32 p0 = src[iu];
const uint32 p1 = src[iu+1];
const uint32 f = (u >> 8) & 0xff;
const uint32 p0_rb = p0 & 0xff00ff;
const uint32 p1_rb = p1 & 0xff00ff;
const uint32 p0_g = p0 & 0xff00;
const uint32 p1_g = p1 & 0xff00;
*dst++ = ((p0_rb + (((p1_rb - p0_rb)*f + 0x800080)>>8)) & 0xff00ff)
+ ((p0_g + (((p1_g - p0_g )*f + 0x008000)>>8)) & 0x00ff00);
u += dudx;
} while(--w);
}
int VDResamplerColStageSeparableLinear8::GetWindowSize() const {return 2;}
void VDResamplerColStageSeparableLinear8::Process(void *dst0, const void *const *srcarray, uint32 w, sint32 phase) {
uint8 *dst = (uint8 *)dst0;
const uint8 *src0 = (const uint8 *)srcarray[0];
const uint8 *src1 = (const uint8 *)srcarray[1];
const uint32 f = (phase >> 8) & 0xff;
do {
const uint32 p0 = *src0++;
const uint32 p1 = *src1++;
*dst++ = (uint8)(p0 + (((p1 - p0)*f + 0x80)>>8));
} while(--w);
}
int VDResamplerColStageSeparableLinear32::GetWindowSize() const {return 2;}
void VDResamplerColStageSeparableLinear32::Process(void *dst0, const void *const *srcarray, uint32 w, sint32 phase) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src0 = (const uint32 *)srcarray[0];
const uint32 *src1 = (const uint32 *)srcarray[1];
const uint32 f = (phase >> 8) & 0xff;
do {
const uint32 p0 = *src0++;
const uint32 p1 = *src1++;
const uint32 p0_rb = p0 & 0xff00ff;
const uint32 p1_rb = p1 & 0xff00ff;
const uint32 p0_g = p0 & 0xff00;
const uint32 p1_g = p1 & 0xff00;
*dst++ = ((p0_rb + (((p1_rb - p0_rb)*f + 0x800080)>>8)) & 0xff00ff)
+ ((p0_g + (((p1_g - p0_g )*f + 0x008000)>>8)) & 0x00ff00);
} while(--w);
}
VDResamplerRowStageSeparableTable8::VDResamplerRowStageSeparableTable8(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTable(mFilterBank.data(), filter);
}
int VDResamplerRowStageSeparableTable8::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerRowStageSeparableTable8::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint8 *dst = (uint8 *)dst0;
const uint8 *src = (const uint8 *)src0;
const unsigned ksize = (int)mFilterBank.size() >> 8;
const sint32 *filterBase = mFilterBank.data();
do {
const uint8 *src2 = src + (u>>16);
const sint32 *filter = filterBase + ksize*((u>>8)&0xff);
u += dudx;
int b = 0x2000;
for(unsigned i = ksize; i; --i) {
uint8 p = *src2++;
sint32 coeff = *filter++;
b += (sint32)p*coeff;
}
b >>= 14;
if ((uint32)b >= 0x00000100)
b = ~b >> 31;
*dst++ = (uint8)b;
} while(--w);
}
VDResamplerRowStageSeparableTable32::VDResamplerRowStageSeparableTable32(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTable(mFilterBank.data(), filter);
}
int VDResamplerRowStageSeparableTable32::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerRowStageSeparableTable32::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src = (const uint32 *)src0;
const unsigned ksize = (int)mFilterBank.size() >> 8;
const sint32 *filterBase = mFilterBank.data();
do {
const uint32 *src2 = src + (u>>16);
const sint32 *filter = filterBase + ksize*((u>>8)&0xff);
u += dudx;
int r = 0x2000, g = 0x2000, b = 0x2000;
for(unsigned i = ksize; i; --i) {
uint32 p = *src2++;
sint32 coeff = *filter++;
r += ((p>>16)&0xff)*coeff;
g += ((p>> 8)&0xff)*coeff;
b += ((p )&0xff)*coeff;
}
r <<= 2;
g >>= 6;
b >>= 14;
if ((uint32)r >= 0x01000000)
r = ~r >> 31;
if ((uint32)g >= 0x00010000)
g = ~g >> 31;
if ((uint32)b >= 0x00000100)
b = ~b >> 31;
*dst++ = (r & 0xff0000) + (g & 0xff00) + (b & 0xff);
} while(--w);
}
VDResamplerRowStageSeparableTable32Fx4::VDResamplerRowStageSeparableTable32Fx4(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTableF(mFilterBank.data(), filter);
}
int VDResamplerRowStageSeparableTable32Fx4::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerRowStageSeparableTable32Fx4::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
float *dst = (float *)dst0;
const float *src = (const float *)src0;
const unsigned ksize = (int)mFilterBank.size() >> 8;
const float *filterBase = mFilterBank.data();
do {
const float *src2 = src + (u>>16)*4;
const float *filter = filterBase + ksize*((u>>8)&0xff);
u += dudx;
float r = 0, g = 0, b = 0, a = 0;
for(unsigned i = ksize; i; --i) {
float coeff = *filter++;
r += coeff * src2[0];
g += coeff * src2[1];
b += coeff * src2[2];
a += coeff * src2[3];
src2 += 4;
}
dst[0] = r;
dst[1] = g;
dst[2] = b;
dst[3] = a;
dst += 4;
} while(--w);
}
VDResamplerRowStageSeparableTable32F::VDResamplerRowStageSeparableTable32F(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTableF(mFilterBank.data(), filter);
}
int VDResamplerRowStageSeparableTable32F::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerRowStageSeparableTable32F::Process(void *dst0, const void *src0, uint32 w, uint32 u, uint32 dudx) {
float *dst = (float *)dst0;
const float *src = (const float *)src0;
const unsigned ksize = (int)mFilterBank.size() >> 8;
const float *filterBase = mFilterBank.data();
VDCPUCleanupExtensions();
do {
const float *src2 = src + (u>>16);
const float *filter = filterBase + ksize*((u>>8)&0xff);
u += dudx;
float r = 0;
for(unsigned i = ksize; i; --i) {
float coeff = *filter++;
r += coeff * src2[0];
++src2;
}
dst[0] = r;
++dst;
} while(--w);
}
VDResamplerColStageSeparableTable8::VDResamplerColStageSeparableTable8(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTable(mFilterBank.data(), filter);
}
int VDResamplerColStageSeparableTable8::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerColStageSeparableTable8::Process(void *dst0, const void *const *src0, uint32 w, sint32 phase) {
uint8 *dst = (uint8 *)dst0;
const uint8 *const *src = (const uint8 *const *)src0;
const unsigned ksize = (unsigned)mFilterBank.size() >> 8;
const sint32 *filter = &mFilterBank[((phase>>8)&0xff) * ksize];
for(uint32 i=0; i<w; ++i) {
int b = 0x2000;
const sint32 *filter2 = filter;
const uint8 *const *src2 = src;
for(unsigned j = ksize; j; --j) {
sint32 p = (*src2++)[i];
sint32 coeff = *filter2++;
b += p*coeff;
}
b >>= 14;
if ((uint32)b >= 0x00000100)
b = ~b >> 31;
*dst++ = (uint8)b;
}
}
VDResamplerColStageSeparableTable32::VDResamplerColStageSeparableTable32(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTable(mFilterBank.data(), filter);
}
int VDResamplerColStageSeparableTable32::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerColStageSeparableTable32::Process(void *dst0, const void *const *src0, uint32 w, sint32 phase) {
uint32 *dst = (uint32 *)dst0;
const uint32 *const *src = (const uint32 *const *)src0;
const unsigned ksize = (unsigned)mFilterBank.size() >> 8;
const sint32 *filter = &mFilterBank[((phase>>8)&0xff) * ksize];
for(uint32 i=0; i<w; ++i) {
int r = 0x2000, g = 0x2000, b = 0x2000;
const sint32 *filter2 = filter;
const uint32 *const *src2 = src;
for(unsigned j = ksize; j; --j) {
uint32 p = (*src2++)[i];
sint32 coeff = *filter2++;
r += ((p>>16)&0xff)*coeff;
g += ((p>> 8)&0xff)*coeff;
b += ((p )&0xff)*coeff;
}
r <<= 2;
g >>= 6;
b >>= 14;
if ((uint32)r >= 0x01000000)
r = ~r >> 31;
if ((uint32)g >= 0x00010000)
g = ~g >> 31;
if ((uint32)b >= 0x00000100)
b = ~b >> 31;
*dst++ = (r & 0xff0000) + (g & 0xff00) + (b & 0xff);
}
}
VDResamplerColStageSeparableTable32F::VDResamplerColStageSeparableTable32F(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTableF(mFilterBank.data(), filter);
}
int VDResamplerColStageSeparableTable32F::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerColStageSeparableTable32F::Process(void *dst0, const void *const *src0, uint32 w, sint32 phase) {
float *dst = (float *)dst0;
const float *const *src = (const float *const *)src0;
const unsigned ksize = (unsigned)mFilterBank.size() >> 8;
const float *filter = &mFilterBank[((phase>>8)&0xff) * ksize];
for(uint32 i=0; i<w; ++i) {
float r = 0;
const float *filter2 = filter;
const float *const *src2 = src;
for(unsigned j = ksize; j; --j) {
const float *p = (*src2++) + i;
float coeff = *filter2++;
r += p[0]*coeff;
}
dst[0] = r;
++dst;
}
}
VDResamplerColStageSeparableTable32Fx4::VDResamplerColStageSeparableTable32Fx4(const IVDResamplerFilter& filter) {
mFilterBank.resize(filter.GetFilterWidth() * 256);
VDResamplerGenerateTableF(mFilterBank.data(), filter);
}
int VDResamplerColStageSeparableTable32Fx4::GetWindowSize() const {return (int)mFilterBank.size() >> 8;}
void VDResamplerColStageSeparableTable32Fx4::Process(void *dst0, const void *const *src0, uint32 w, sint32 phase) {
float *dst = (float *)dst0;
const float *const *src = (const float *const *)src0;
const unsigned ksize = (unsigned)mFilterBank.size() >> 8;
const float *filter = &mFilterBank[((phase>>8)&0xff) * ksize];
for(uint32 i=0; i<w; ++i) {
float r = 0, g = 0, b = 0, a = 0;
const float *filter2 = filter;
const float *const *src2 = src;
for(unsigned j = ksize; j; --j) {
const float *p = (*src2++) + i*4;
float coeff = *filter2++;
r += p[0]*coeff;
g += p[1]*coeff;
b += p[2]*coeff;
a += p[3]*coeff;
}
dst[0] = r;
dst[1] = g;
dst[2] = b;
dst[3] = a;
dst += 4;
}
}
|