1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /* VLC code
24 *
25 * Original copyright note: * Intel Indeo 4 (IV41, IV42, etc.) video decoder for ffmpeg
26 * written, produced, and directed by Alan Smithee
27 */
28
29 #include "image/codecs/indeo/indeo_dsp.h"
30
31 namespace Image {
32 namespace Indeo {
33
34 /**
35 * butterfly operation for the inverse Haar transform
36 */
37 #define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \
38 t = ((s1) - (s2)) >> 1;\
39 o1 = ((s1) + (s2)) >> 1;\
40 o2 = (t);\
41
42 /**
43 * inverse 8-point Haar transform
44 */
45 #define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
46 d1, d2, d3, d4, d5, d6, d7, d8,\
47 t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
48 t1 = (s1) << 1; t5 = (s5) << 1;\
49 IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
50 IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
51 IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
52 IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\
53 d1 = COMPENSATE(t1);\
54 d2 = COMPENSATE(t2);\
55 d3 = COMPENSATE(t3);\
56 d4 = COMPENSATE(t4);\
57 d5 = COMPENSATE(t5);\
58 d6 = COMPENSATE(t6);\
59 d7 = COMPENSATE(t7);\
60 d8 = COMPENSATE(t8); }
61
62 /**
63 * inverse 4-point Haar transform
64 */
65 #define INV_HAAR4(s1, s3, s5, s7, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
66 IVI_HAAR_BFLY(s1, s3, t0, t1, t4);\
67 IVI_HAAR_BFLY(t0, s5, t2, t3, t4);\
68 d1 = COMPENSATE(t2);\
69 d2 = COMPENSATE(t3);\
70 IVI_HAAR_BFLY(t1, s7, t2, t3, t4);\
71 d3 = COMPENSATE(t2);\
72 d4 = COMPENSATE(t3); }
73
ffIviInverseHaar8x8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)74 void IndeoDSP::ffIviInverseHaar8x8(const int32 *in, int16 *out, uint32 pitch,
75 const uint8 *flags) {
76 int32 tmp[64];
77 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
78
79 // apply the InvHaar8 to all columns
80 #define COMPENSATE(x) (x)
81 const int32 *src = in;
82 int32 *dst = tmp;
83 for (int i = 0; i < 8; i++) {
84 if (flags[i]) {
85 // pre-scaling
86 int shift = !(i & 4);
87 int sp1 = src[ 0] << shift;
88 int sp2 = src[ 8] << shift;
89 int sp3 = src[16] << shift;
90 int sp4 = src[24] << shift;
91 INV_HAAR8( sp1, sp2, sp3, sp4,
92 src[32], src[40], src[48], src[56],
93 dst[ 0], dst[ 8], dst[16], dst[24],
94 dst[32], dst[40], dst[48], dst[56],
95 t0, t1, t2, t3, t4, t5, t6, t7, t8);
96 } else {
97 dst[ 0] = dst[ 8] = dst[16] = dst[24] =
98 dst[32] = dst[40] = dst[48] = dst[56] = 0;
99 }
100
101 src++;
102 dst++;
103 }
104 #undef COMPENSATE
105
106 // apply the InvHaar8 to all rows
107 #define COMPENSATE(x) (x)
108 src = tmp;
109 for (int i = 0; i < 8; i++) {
110 if (!src[0] && !src[1] && !src[2] && !src[3] &&
111 !src[4] && !src[5] && !src[6] && !src[7]) {
112 memset(out, 0, 8 * sizeof(out[0]));
113 } else {
114 INV_HAAR8(src[0], src[1], src[2], src[3],
115 src[4], src[5], src[6], src[7],
116 out[0], out[1], out[2], out[3],
117 out[4], out[5], out[6], out[7],
118 t0, t1, t2, t3, t4, t5, t6, t7, t8);
119 }
120 src += 8;
121 out += pitch;
122 }
123 #undef COMPENSATE
124 }
125
ffIviRowHaar8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)126 void IndeoDSP::ffIviRowHaar8(const int32 *in, int16 *out, uint32 pitch,
127 const uint8 *flags) {
128 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
129
130 // apply the InvHaar8 to all rows
131 #define COMPENSATE(x) (x)
132 for (int i = 0; i < 8; i++) {
133 if ( !in[0] && !in[1] && !in[2] && !in[3]
134 && !in[4] && !in[5] && !in[6] && !in[7]) {
135 memset(out, 0, 8 * sizeof(out[0]));
136 } else {
137 INV_HAAR8(in[0], in[1], in[2], in[3],
138 in[4], in[5], in[6], in[7],
139 out[0], out[1], out[2], out[3],
140 out[4], out[5], out[6], out[7],
141 t0, t1, t2, t3, t4, t5, t6, t7, t8);
142 }
143 in += 8;
144 out += pitch;
145 }
146 #undef COMPENSATE
147 }
148
ffIviColHaar8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)149 void IndeoDSP::ffIviColHaar8(const int32 *in, int16 *out, uint32 pitch,
150 const uint8 *flags) {
151 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
152
153 // apply the InvHaar8 to all columns
154 #define COMPENSATE(x) (x)
155 for (int i = 0; i < 8; i++) {
156 if (flags[i]) {
157 INV_HAAR8(in[ 0], in[ 8], in[16], in[24],
158 in[32], in[40], in[48], in[56],
159 out[0 * pitch], out[1 * pitch],
160 out[2 * pitch], out[3 * pitch],
161 out[4 * pitch], out[5 * pitch],
162 out[6 * pitch], out[7 * pitch],
163 t0, t1, t2, t3, t4, t5, t6, t7, t8);
164 } else {
165 out[0 * pitch] = out[1 * pitch] =
166 out[2 * pitch] = out[3 * pitch] =
167 out[4 * pitch] = out[5 * pitch] =
168 out[6 * pitch] = out[7 * pitch] = 0;
169 }
170
171 in++;
172 out++;
173 }
174 #undef COMPENSATE
175 }
176
ffIviInverseHaar4x4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)177 void IndeoDSP::ffIviInverseHaar4x4(const int32 *in, int16 *out, uint32 pitch,
178 const uint8 *flags) {
179 int32 tmp[16];
180 int t0, t1, t2, t3, t4;
181
182 // apply the InvHaar4 to all columns
183 #define COMPENSATE(x) (x)
184 const int32 *src = in;
185 int32 *dst = tmp;
186 for (int i = 0; i < 4; i++) {
187 if (flags[i]) {
188 // pre-scaling
189 int shift = !(i & 2);
190 int sp1 = src[0] << shift;
191 int sp2 = src[4] << shift;
192 INV_HAAR4( sp1, sp2, src[8], src[12],
193 dst[0], dst[4], dst[8], dst[12],
194 t0, t1, t2, t3, t4);
195 } else {
196 dst[0] = dst[4] = dst[8] = dst[12] = 0;
197 }
198
199 src++;
200 dst++;
201 }
202 #undef COMPENSATE
203
204 // apply the InvHaar8 to all rows
205 #define COMPENSATE(x) (x)
206 src = tmp;
207 for (int i = 0; i < 4; i++) {
208 if (!src[0] && !src[1] && !src[2] && !src[3]) {
209 memset(out, 0, 4 * sizeof(out[0]));
210 } else {
211 INV_HAAR4(src[0], src[1], src[2], src[3],
212 out[0], out[1], out[2], out[3],
213 t0, t1, t2, t3, t4);
214 }
215 src += 4;
216 out += pitch;
217 }
218 #undef COMPENSATE
219 }
220
ffIviRowHaar4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)221 void IndeoDSP::ffIviRowHaar4(const int32 *in, int16 *out, uint32 pitch,
222 const uint8 *flags) {
223 int t0, t1, t2, t3, t4;
224
225 // apply the InvHaar4 to all rows
226 #define COMPENSATE(x) (x)
227 for (int i = 0; i < 4; i++) {
228 if (!in[0] && !in[1] && !in[2] && !in[3]) {
229 memset(out, 0, 4 * sizeof(out[0]));
230 } else {
231 INV_HAAR4(in[0], in[1], in[2], in[3],
232 out[0], out[1], out[2], out[3],
233 t0, t1, t2, t3, t4);
234 }
235 in += 4;
236 out += pitch;
237 }
238 #undef COMPENSATE
239 }
240
ffIviColHaar4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)241 void IndeoDSP::ffIviColHaar4(const int32 *in, int16 *out, uint32 pitch,
242 const uint8 *flags) {
243 int t0, t1, t2, t3, t4;
244
245 // apply the InvHaar8 to all columns
246 #define COMPENSATE(x) (x)
247 for (int i = 0; i < 4; i++) {
248 if (flags[i]) {
249 INV_HAAR4(in[0], in[4], in[8], in[12],
250 out[0 * pitch], out[1 * pitch],
251 out[2 * pitch], out[3 * pitch],
252 t0, t1, t2, t3, t4);
253 } else {
254 out[0 * pitch] = out[1 * pitch] =
255 out[2 * pitch] = out[3 * pitch] = 0;
256 }
257
258 in++;
259 out++;
260 }
261 #undef COMPENSATE
262 }
263
ffIviDcHaar2d(const int32 * in,int16 * out,uint32 pitch,int blkSize)264 void IndeoDSP::ffIviDcHaar2d(const int32 *in, int16 *out, uint32 pitch,
265 int blkSize) {
266 int16 dcCoeff = (*in + 0) >> 3;
267
268 for (int y = 0; y < blkSize; out += pitch, y++) {
269 for (int x = 0; x < blkSize; x++)
270 out[x] = dcCoeff;
271 }
272 }
273
274 //* butterfly operation for the inverse slant transform
275 #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
276 t = (s1) - (s2);\
277 o1 = (s1) + (s2);\
278 o2 = (t);\
279
280 //* This is a reflection a,b = 1/2, 5/4 for the inverse slant transform
281 #define IVI_IREFLECT(s1, s2, o1, o2, t) \
282 t = (((s1) + (s2)*2 + 2) >> 2) + (s1);\
283 o2 = (((s1)*2 - (s2) + 2) >> 2) - (s2);\
284 o1 = (t);\
285
286 //* This is a reflection a,b = 1/2, 7/8 for the inverse slant transform
287 #define IVI_SLANT_PART4(s1, s2, o1, o2, t) \
288 t = (s2) + (((s1)*4 - (s2) + 4) >> 3);\
289 o2 = (s1) + ((-(s1) - (s2)*4 + 4) >> 3);\
290 o1 = (t);\
291
292 //* inverse slant8 transform
293 #define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\
294 d1, d2, d3, d4, d5, d6, d7, d8,\
295 t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
296 IVI_SLANT_PART4(s4, s5, t4, t5, t0);\
297 \
298 IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\
299 IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\
300 \
301 IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT (t4, t3, t4, t3, t0);\
302 IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT (t8, t7, t8, t7, t0);\
303 IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
304 IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\
305 d1 = COMPENSATE(t1);\
306 d2 = COMPENSATE(t2);\
307 d3 = COMPENSATE(t3);\
308 d4 = COMPENSATE(t4);\
309 d5 = COMPENSATE(t5);\
310 d6 = COMPENSATE(t6);\
311 d7 = COMPENSATE(t7);\
312 d8 = COMPENSATE(t8);}
313
314 //* inverse slant4 transform
315 #define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
316 IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT (s4, s3, t4, t3, t0);\
317 \
318 IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
319 d1 = COMPENSATE(t1);\
320 d2 = COMPENSATE(t2);\
321 d3 = COMPENSATE(t3);\
322 d4 = COMPENSATE(t4);}
323
ffIviInverseSlant8x8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)324 void IndeoDSP::ffIviInverseSlant8x8(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags) {
325 int32 tmp[64];
326 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
327
328 #define COMPENSATE(x) (x)
329 const int32 *src = in;
330 int32 *dst = tmp;
331 for (int i = 0; i < 8; i++) {
332 if (flags[i]) {
333 IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
334 dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56],
335 t0, t1, t2, t3, t4, t5, t6, t7, t8);
336 } else {
337 dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
338 }
339
340 src++;
341 dst++;
342 }
343 #undef COMPENSATE
344
345 #define COMPENSATE(x) (((x) + 1)>>1)
346 src = tmp;
347 for (int i = 0; i < 8; i++) {
348 if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
349 memset(out, 0, 8*sizeof(out[0]));
350 } else {
351 IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
352 out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
353 t0, t1, t2, t3, t4, t5, t6, t7, t8);
354 }
355 src += 8;
356 out += pitch;
357 }
358 #undef COMPENSATE
359 }
360
ffIviInverseSlant4x4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)361 void IndeoDSP::ffIviInverseSlant4x4(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags) {
362 int32 tmp[16];
363 int t0, t1, t2, t3, t4;
364
365 #define COMPENSATE(x) (x)
366 const int32 *src = in;
367 int32 *dst = tmp;
368 for (int i = 0; i < 4; i++) {
369 if (flags[i]) {
370 IVI_INV_SLANT4(src[0], src[4], src[8], src[12],
371 dst[0], dst[4], dst[8], dst[12],
372 t0, t1, t2, t3, t4);
373 } else {
374 dst[0] = dst[4] = dst[8] = dst[12] = 0;
375 }
376 src++;
377 dst++;
378 }
379 #undef COMPENSATE
380
381 #define COMPENSATE(x) (((x) + 1)>>1)
382 src = tmp;
383 for (int i = 0; i < 4; i++) {
384 if (!src[0] && !src[1] && !src[2] && !src[3]) {
385 out[0] = out[1] = out[2] = out[3] = 0;
386 } else {
387 IVI_INV_SLANT4(src[0], src[1], src[2], src[3],
388 out[0], out[1], out[2], out[3],
389 t0, t1, t2, t3, t4);
390 }
391 src += 4;
392 out += pitch;
393 }
394 #undef COMPENSATE
395 }
396
ffIviDcSlant2d(const int32 * in,int16 * out,uint32 pitch,int blkSize)397 void IndeoDSP::ffIviDcSlant2d(const int32 *in, int16 *out, uint32 pitch,
398 int blkSize) {
399 int16 dcCoeff = (*in + 1) >> 1;
400
401 for (int y = 0; y < blkSize; out += pitch, y++) {
402 for (int x = 0; x < blkSize; x++)
403 out[x] = dcCoeff;
404 }
405 }
406
ffIviRowSlant8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)407 void IndeoDSP::ffIviRowSlant8(const int32 *in, int16 *out, uint32 pitch,
408 const uint8 *flags) {
409 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
410
411 #define COMPENSATE(x) (((x) + 1)>>1)
412 for (int i = 0; i < 8; i++) {
413 if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
414 memset(out, 0, 8*sizeof(out[0]));
415 } else {
416 IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
417 out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
418 t0, t1, t2, t3, t4, t5, t6, t7, t8);
419 }
420 in += 8;
421 out += pitch;
422 }
423 #undef COMPENSATE
424 }
425
ffIviDcRowSlant(const int32 * in,int16 * out,uint32 pitch,int blkSize)426 void IndeoDSP::ffIviDcRowSlant(const int32 *in, int16 *out, uint32 pitch, int blkSize) {
427 int16 dcCoeff = (*in + 1) >> 1;
428
429 for (int x = 0; x < blkSize; x++)
430 out[x] = dcCoeff;
431
432 out += pitch;
433
434 for (int y = 1; y < blkSize; out += pitch, y++) {
435 for (int x = 0; x < blkSize; x++)
436 out[x] = 0;
437 }
438 }
439
ffIviColSlant8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)440 void IndeoDSP::ffIviColSlant8(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags) {
441 int t0, t1, t2, t3, t4, t5, t6, t7, t8;
442
443 int row2 = pitch << 1;
444 int row4 = pitch << 2;
445 int row8 = pitch << 3;
446
447 #define COMPENSATE(x) (((x) + 1)>>1)
448 for (int i = 0; i < 8; i++) {
449 if (flags[i]) {
450 IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
451 out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
452 out[row4 + pitch], out[row4 + row2], out[row8 - pitch],
453 t0, t1, t2, t3, t4, t5, t6, t7, t8);
454 } else {
455 out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
456 out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0;
457 }
458
459 in++;
460 out++;
461 }
462 #undef COMPENSATE
463 }
464
ffIviDcColSlant(const int32 * in,int16 * out,uint32 pitch,int blkSize)465 void IndeoDSP::ffIviDcColSlant(const int32 *in, int16 *out, uint32 pitch, int blkSize) {
466 int16 dcCoeff = (*in + 1) >> 1;
467
468 for (int y = 0; y < blkSize; out += pitch, y++) {
469 out[0] = dcCoeff;
470 for (int x = 1; x < blkSize; x++)
471 out[x] = 0;
472 }
473 }
474
ffIviRowSlant4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)475 void IndeoDSP::ffIviRowSlant4(const int32 *in, int16 *out,
476 uint32 pitch, const uint8 *flags) {
477 int t0, t1, t2, t3, t4;
478
479 #define COMPENSATE(x) (((x) + 1)>>1)
480 for (int i = 0; i < 4; i++) {
481 if (!in[0] && !in[1] && !in[2] && !in[3]) {
482 memset(out, 0, 4*sizeof(out[0]));
483 } else {
484 IVI_INV_SLANT4( in[0], in[1], in[2], in[3],
485 out[0], out[1], out[2], out[3],
486 t0, t1, t2, t3, t4);
487 }
488 in += 4;
489 out += pitch;
490 }
491 #undef COMPENSATE
492 }
493
ffIviColSlant4(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)494 void IndeoDSP::ffIviColSlant4(const int32 *in, int16 *out, uint32 pitch,
495 const uint8 *flags) {
496 int t0, t1, t2, t3, t4;
497
498 int row2 = pitch << 1;
499
500 #define COMPENSATE(x) (((x) + 1)>>1)
501 for (int i = 0; i < 4; i++) {
502 if (flags[i]) {
503 IVI_INV_SLANT4(in[0], in[4], in[8], in[12],
504 out[0], out[pitch], out[row2], out[row2 + pitch],
505 t0, t1, t2, t3, t4);
506 } else {
507 out[0] = out[pitch] = out[row2] = out[row2 + pitch] = 0;
508 }
509
510 in++;
511 out++;
512 }
513 #undef COMPENSATE
514 }
515
ffIviPutPixels8x8(const int32 * in,int16 * out,uint32 pitch,const uint8 * flags)516 void IndeoDSP::ffIviPutPixels8x8(const int32 *in, int16 *out, uint32 pitch,
517 const uint8 *flags) {
518 for (int y = 0; y < 8; out += pitch, in += 8, y++)
519 for (int x = 0; x < 8; x++)
520 out[x] = in[x];
521 }
522
ffIviPutDcPixel8x8(const int32 * in,int16 * out,uint32 pitch,int blkSize)523 void IndeoDSP::ffIviPutDcPixel8x8(const int32 *in, int16 *out, uint32 pitch,
524 int blkSize) {
525 out[0] = in[0];
526 memset(out + 1, 0, 7 * sizeof(out[0]));
527 out += pitch;
528
529 for (int y = 1; y < 8; out += pitch, y++)
530 memset(out, 0, 8 * sizeof(out[0]));
531 }
532
533 #define IVI_MC_TEMPLATE(size, suffix, OP) \
534 static void iviMc ## size ##x## size ## suffix(int16 *buf, \
535 uint32 dpitch, \
536 const int16 *refBuf, \
537 uint32 pitch, int mcType) \
538 { \
539 const int16 *wptr; \
540 \
541 switch (mcType) { \
542 case 0: /* fullpel (no interpolation) */ \
543 for (int i = 0; i < size; i++, buf += dpitch, refBuf += pitch) { \
544 for (int j = 0; j < size; j++) {\
545 OP(buf[j], refBuf[j]); \
546 } \
547 } \
548 break; \
549 case 1: /* horizontal halfpel interpolation */ \
550 for (int i = 0; i < size; i++, buf += dpitch, refBuf += pitch) \
551 for (int j = 0; j < size; j++) \
552 OP(buf[j], (refBuf[j] + refBuf[j+1]) >> 1); \
553 break; \
554 case 2: /* vertical halfpel interpolation */ \
555 wptr = refBuf + pitch; \
556 for (int i = 0; i < size; i++, buf += dpitch, wptr += pitch, refBuf += pitch) \
557 for (int j = 0; j < size; j++) \
558 OP(buf[j], (refBuf[j] + wptr[j]) >> 1); \
559 break; \
560 case 3: /* vertical and horizontal halfpel interpolation */ \
561 wptr = refBuf + pitch; \
562 for (int i = 0; i < size; i++, buf += dpitch, wptr += pitch, refBuf += pitch) \
563 for (int j = 0; j < size; j++) \
564 OP(buf[j], (refBuf[j] + refBuf[j+1] + wptr[j] + wptr[j+1]) >> 2); \
565 break; \
566 } \
567 } \
568 \
569 void IndeoDSP::ffIviMc ## size ##x## size ## suffix(int16 *buf, const int16 *refBuf, \
570 uint32 pitch, int mcType) \
571 { \
572 iviMc ## size ##x## size ## suffix(buf, pitch, refBuf, pitch, mcType); \
573 }
574
575 #define IVI_MC_AVG_TEMPLATE(size, suffix, OP) \
576 void IndeoDSP::ffIviMcAvg ## size ##x## size ## suffix(int16 *buf, \
577 const int16 *refBuf, \
578 const int16 *refBuf2, \
579 uint32 pitch, \
580 int mcType, int mcType2) \
581 { \
582 int16 tmp[size * size]; \
583 \
584 iviMc ## size ##x## size ## NoDelta(tmp, size, refBuf, pitch, mcType); \
585 iviMc ## size ##x## size ## Delta(tmp, size, refBuf2, pitch, mcType2); \
586 for (int i = 0; i < size; i++, buf += pitch) { \
587 for (int j = 0; j < size; j++) {\
588 OP(buf[j], tmp[i * size + j] >> 1); \
589 } \
590 } \
591 }
592
593 #define OP_PUT(a, b) (a) = (b)
594 #define OP_ADD(a, b) (a) += (b)
595
596 IVI_MC_TEMPLATE(8, NoDelta, OP_PUT)
597 IVI_MC_TEMPLATE(8, Delta, OP_ADD)
598 IVI_MC_TEMPLATE(4, NoDelta, OP_PUT)
599 IVI_MC_TEMPLATE(4, Delta, OP_ADD)
600 IVI_MC_AVG_TEMPLATE(8, NoDelta, OP_PUT)
601 IVI_MC_AVG_TEMPLATE(8, Delta, OP_ADD)
602 IVI_MC_AVG_TEMPLATE(4, NoDelta, OP_PUT)
603 IVI_MC_AVG_TEMPLATE(4, Delta, OP_ADD)
604
605 } // End of namespace Indeo
606 } // End of namespace Image
607