blob: 3c0694a295aaaec171c84cdb8e36745563cd79d4 [file] [log] [blame]
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +00001/*
2 * filters.h
3 *
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +00004 * Description: TTAv1 filter functions
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +00005 * Developed by: Alexander Djourik <sasha@iszf.irk.ru>
6 * Pavel Zhilin <pzh@iszf.irk.ru>
7 *
8 * Copyright (c) 1999-2004 Alexander Djourik. All rights reserved.
9 *
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * aint with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 * Please see the file COPYING in this directory for full copyright
28 * information.
29 */
30
31#ifndef FILTERS_H
32#define FILTERS_H
33
34///////// Filter Settings //////////
35static long flt_set[3] = {10, 9, 10};
36
37static void
38memshl (register long *pA, register long *pB) {
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000039 *pA++ = *pB++;
40 *pA++ = *pB++;
41 *pA++ = *pB++;
42 *pA++ = *pB++;
43 *pA++ = *pB++;
44 *pA++ = *pB++;
45 *pA++ = *pB++;
46 *pA = *pB;
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000047}
48
49static void
50hybrid_filter (fltst *fs, long *in) {
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000051 register long *pA = fs->dl;
52 register long *pB = fs->qm;
53 register long *pM = fs->dx;
54 register long sum = fs->round;
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000055
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000056 if (!fs->error) {
57 sum += *pA++ * *pB, pB++;
58 sum += *pA++ * *pB, pB++;
59 sum += *pA++ * *pB, pB++;
60 sum += *pA++ * *pB, pB++;
61 sum += *pA++ * *pB, pB++;
62 sum += *pA++ * *pB, pB++;
63 sum += *pA++ * *pB, pB++;
64 sum += *pA++ * *pB, pB++; pM += 8;
65 } else if (fs->error < 0) {
66 sum += *pA++ * (*pB -= *pM++), pB++;
67 sum += *pA++ * (*pB -= *pM++), pB++;
68 sum += *pA++ * (*pB -= *pM++), pB++;
69 sum += *pA++ * (*pB -= *pM++), pB++;
70 sum += *pA++ * (*pB -= *pM++), pB++;
71 sum += *pA++ * (*pB -= *pM++), pB++;
72 sum += *pA++ * (*pB -= *pM++), pB++;
73 sum += *pA++ * (*pB -= *pM++), pB++;
74 } else {
75 sum += *pA++ * (*pB += *pM++), pB++;
76 sum += *pA++ * (*pB += *pM++), pB++;
77 sum += *pA++ * (*pB += *pM++), pB++;
78 sum += *pA++ * (*pB += *pM++), pB++;
79 sum += *pA++ * (*pB += *pM++), pB++;
80 sum += *pA++ * (*pB += *pM++), pB++;
81 sum += *pA++ * (*pB += *pM++), pB++;
82 sum += *pA++ * (*pB += *pM++), pB++;
83 }
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000084
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000085 *(pM-0) = ((*(pA-1) >> 30) | 1) << 2;
86 *(pM-1) = ((*(pA-2) >> 30) | 1) << 1;
87 *(pM-2) = ((*(pA-3) >> 30) | 1) << 1;
88 *(pM-3) = ((*(pA-4) >> 30) | 1);
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000089
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000090 fs->error = *in;
91 *in += (sum >> fs->shift);
92 *pA = *in;
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000093
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000094 *(pA-1) = *(pA-0) - *(pA-1);
95 *(pA-2) = *(pA-1) - *(pA-2);
96 *(pA-3) = *(pA-2) - *(pA-3);
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +000097
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +000098 memshl (fs->dl, fs->dl + 1);
99 memshl (fs->dx, fs->dx + 1);
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +0000100}
101
102static void
103filter_init (fltst *fs, long shift) {
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +0000104 memset (fs, 0, sizeof(fltst));
105 fs->shift = shift;
106 fs->round = 1 << (shift - 1);
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +0000107}
108
Thomas Vander Stichelebdb814f2005-12-06 19:55:58 +0000109#endif /* FILTERS_H */
Arwed v. Merkatzaeb09d32004-11-26 23:10:28 +0000110