ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Video-Capture-V4l/RTjpeg/codec/modules/RTidct_std.c
Revision: 1.1
Committed: Fri May 5 20:21:52 2000 UTC (26 years, 6 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-0_9, rel-0_902, HEAD
Log Message:
Initial check-in

File Contents

# Content
1 #include <sys/types.h>
2
3 #define FIX_0_298631336 ((s32) 2446) /* FIX(0.298631336) */
4 #define FIX_0_390180644 ((s32) 3196) /* FIX(0.390180644) */
5 #define FIX_0_541196100 ((s32) 4433) /* FIX(0.541196100) */
6 #define FIX_0_765366865 ((s32) 6270) /* FIX(0.765366865) */
7 #define FIX_0_899976223 ((s32) 7373) /* FIX(0.899976223) */
8 #define FIX_1_175875602 ((s32) 9633) /* FIX(1.175875602) */
9 #define FIX_1_501321110 ((s32) 12299) /* FIX(1.501321110) */
10 #define FIX_1_847759065 ((s32) 15137) /* FIX(1.847759065) */
11 #define FIX_1_961570560 ((s32) 16069) /* FIX(1.961570560) */
12 #define FIX_2_053119869 ((s32) 16819) /* FIX(2.053119869) */
13 #define FIX_2_562915447 ((s32) 20995) /* FIX(2.562915447) */
14 #define FIX_3_072711026 ((s32) 25172) /* FIX(3.072711026) */
15
16 #define MULTIPLY(var,const) ( (s32) ((var)*(const)) )
17 #define DESCALE(x,n) ((x)>>(n))
18
19 /* clip yuv to 16..235 (should be 16..240 for cr/cb but ... */
20
21 #define RL(x) ((x)>235) ? 235 : (((x)<16) ? 16 : (x))
22
23 void RTjpeg_idct_init(void)
24 {
25 }
26
27 void RTjpeg_idct(u8 *odata, s16 *data, int rskip)
28 {
29 s32 tmp0, tmp1, tmp2, tmp3;
30 s32 tmp10, tmp11, tmp12, tmp13;
31 s32 z1, z2, z3, z4, z5;
32 s16 *inptr;
33 s32 *wsptr;
34 u8 *outptr;
35 int ctr;
36 s32 dcval;
37 s32 workspace[64];
38
39 inptr = data;
40 wsptr = workspace;
41 for (ctr = 8; ctr > 0; ctr--) {
42
43 if ((inptr[8] | inptr[16] | inptr[24] |
44 inptr[32] | inptr[40] | inptr[48] | inptr[56]) == 0) {
45 dcval=inptr[0]<<2;
46 wsptr[0] = dcval;
47 wsptr[8] = dcval;
48 wsptr[16] = dcval;
49 wsptr[24] = dcval;
50 wsptr[32] = dcval;
51 wsptr[40] = dcval;
52 wsptr[48] = dcval;
53 wsptr[56] = dcval;
54 inptr++;
55 wsptr++;
56 continue;
57 }
58
59 z2 = inptr[16];
60 z3 = inptr[48];
61 z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
62 tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
63 tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
64 z2 = inptr[0];
65 z3 = inptr[32];
66
67 tmp0 = (z2 + z3) << 13;
68 tmp1 = (z2 - z3) << 13;
69
70 tmp10 = tmp0 + tmp3;
71 tmp13 = tmp0 - tmp3;
72 tmp11 = tmp1 + tmp2;
73 tmp12 = tmp1 - tmp2;
74
75 tmp0 = inptr[56];
76 tmp1 = inptr[40];
77 tmp2 = inptr[24];
78 tmp3 = inptr[8];
79
80 z1 = tmp0 + tmp3;
81 z2 = tmp1 + tmp2;
82 z3 = tmp0 + tmp2;
83 z4 = tmp1 + tmp3;
84 z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
85
86 tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
87 tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
88 tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
89 tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
90 z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
91 z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
92 z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
93 z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
94
95 z3 += z5;
96 z4 += z5;
97
98 tmp0 += z1 + z3;
99 tmp1 += z2 + z4;
100 tmp2 += z2 + z3;
101 tmp3 += z1 + z4;
102
103 wsptr[0] = (int) DESCALE(tmp10 + tmp3, 11);
104 wsptr[56] = (int) DESCALE(tmp10 - tmp3, 11);
105 wsptr[8] = (int) DESCALE(tmp11 + tmp2, 11);
106 wsptr[48] = (int) DESCALE(tmp11 - tmp2, 11);
107 wsptr[16] = (int) DESCALE(tmp12 + tmp1, 11);
108 wsptr[40] = (int) DESCALE(tmp12 - tmp1, 11);
109 wsptr[24] = (int) DESCALE(tmp13 + tmp0, 11);
110 wsptr[32] = (int) DESCALE(tmp13 - tmp0, 11);
111
112 inptr++; /* advance pointers to next column */
113 wsptr++;
114 }
115
116 wsptr = workspace;
117 for (ctr = 0; ctr < 8; ctr++) {
118 outptr=&(odata[ctr*rskip]);
119 z2 = (s32) wsptr[2];
120 z3 = (s32) wsptr[6];
121
122 z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
123 tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
124 tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
125
126 tmp0 = ((s32) wsptr[0] + (s32) wsptr[4]) << 13;
127 tmp1 = ((s32) wsptr[0] - (s32) wsptr[4]) << 13;
128
129 tmp10 = tmp0 + tmp3;
130 tmp13 = tmp0 - tmp3;
131 tmp11 = tmp1 + tmp2;
132 tmp12 = tmp1 - tmp2;
133
134 tmp0 = (s32) wsptr[7];
135 tmp1 = (s32) wsptr[5];
136 tmp2 = (s32) wsptr[3];
137 tmp3 = (s32) wsptr[1];
138
139 z1 = tmp0 + tmp3;
140 z2 = tmp1 + tmp2;
141 z3 = tmp0 + tmp2;
142 z4 = tmp1 + tmp3;
143 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
144
145 tmp0 = MULTIPLY(tmp0, FIX_0_298631336);
146 tmp1 = MULTIPLY(tmp1, FIX_2_053119869);
147 tmp2 = MULTIPLY(tmp2, FIX_3_072711026);
148 tmp3 = MULTIPLY(tmp3, FIX_1_501321110);
149 z1 = MULTIPLY(z1, - FIX_0_899976223);
150 z2 = MULTIPLY(z2, - FIX_2_562915447);
151 z3 = MULTIPLY(z3, - FIX_1_961570560);
152 z4 = MULTIPLY(z4, - FIX_0_390180644);
153
154 z3 += z5;
155 z4 += z5;
156
157 tmp0 += z1 + z3;
158 tmp1 += z2 + z4;
159 tmp2 += z2 + z3;
160 tmp3 += z1 + z4;
161
162 outptr[0] = (s32) RL(DESCALE(tmp10 + tmp3, 18));
163 outptr[7] = (s32) RL(DESCALE(tmp10 - tmp3, 18));
164 outptr[1] = (s32) RL(DESCALE(tmp11 + tmp2, 18));
165 outptr[6] = (s32) RL(DESCALE(tmp11 - tmp2, 18));
166 outptr[2] = (s32) RL(DESCALE(tmp12 + tmp1, 18));
167 outptr[5] = (s32) RL(DESCALE(tmp12 - tmp1, 18));
168 outptr[3] = (s32) RL(DESCALE(tmp13 + tmp0, 18));
169 outptr[4] = (s32) RL(DESCALE(tmp13 - tmp0, 18));
170
171 wsptr += 8;
172 }
173 }