1
/* Copyright (C) 2005 Ole André Vadla Ravnås <oleavr@gmail.com>
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either
6
* version 2.1 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
#include "mimic-private.h"
20
extern guchar _col_zag[64];
22
void _fdct_quant_block(MimCtx *ctx, gint *block, const guchar *src,
23
gint stride, gboolean is_chrom, gint num_coeffs)
25
gint sum1, sum2, sum3, sum4;
26
gint diff1, diff2, diff3, diff4;
27
gint ex1, ex2, ex3, ex4, ex5;
33
* Forward DCT, first pass (horizontal).
38
for (i = 0; i < 8; i++) {
44
diff1 = p1[0] - p1[7];
45
diff2 = p1[1] - p1[6];
46
diff3 = p1[2] - p1[5];
47
diff4 = p1[3] - p1[4];
49
ex1 = ((diff1 + diff4) * 851) - (diff1 * 282);
50
ex2 = ((diff2 + diff3) * 1004) - (diff2 * 804);
51
ex3 = ((diff2 + diff3) * 1004) - (diff3 * 1204);
52
ex4 = ((diff1 + diff4) * 851) - (diff4 * 1420);
54
iptr[0] = sum1 + sum2 + sum3 + sum4;
55
iptr[2] = (((sum1 - sum4) * 1337) + ((sum2 - sum3) * 554)) >> 10;
56
iptr[4] = sum1 - sum2 - sum3 + sum4;
58
iptr[1] = (ex1 + ex2 + ex3 + ex4) >> 10;
59
iptr[3] = ((ex4 - ex2) * 181) >> 17;
60
iptr[5] = ((ex1 - ex3) * 181) >> 17;
70
* Forward DCT, first pass (vertical).
72
* This is only known to be correct for i == 0, though it seems to be ...
74
for (i = 0; i < 6; i++) {
75
sum1 = iptr[ 0 + i] + iptr[56 + i];
76
sum2 = iptr[ 8 + i] + iptr[48 + i];
77
sum3 = iptr[16 + i] + iptr[40 + i];
78
sum4 = iptr[24 + i] + iptr[32 + i];
80
diff1 = iptr[ 0 + i] - iptr[56 + i];
81
diff2 = iptr[ 8 + i] - iptr[48 + i];
82
diff3 = iptr[16 + i] - iptr[40 + i];
83
diff4 = iptr[24 + i] - iptr[32 + i];
85
ex1 = ((diff1 + diff4) * 851) - (diff1 * 282);
86
ex2 = ((diff2 + diff3) * 1004) - (diff2 * 804);
87
ex3 = ((diff2 + diff3) * 1004) - (diff3 * 1204);
88
ex4 = ((diff1 + diff4) * 851) - (diff4 * 1420);
90
ex5 = (sum1 + sum2 - sum3 - sum4) * 554;
92
for (j = 0; j < 7 - i; j++) {
96
iptr[ 0 + i] = (16 + sum1 + sum2 + sum3 + sum4) >> 5;
100
iptr[ 8 + i] = (16384 + ex1 + ex2 + ex3 + ex4) >> 15;
104
iptr[16 + i] = (16384 + ((sum1 - sum4) * 783) + ex5) >> 15;
108
iptr[24 + i] = (8192 + (((ex4 - ex2) >> 8) * 181)) >> 14;
112
iptr[32 + i] = (16 + sum1 - sum2 - sum3 + sum4) >> 5;
116
iptr[40 + i] = (8192 + (((ex1 - ex3) >> 8) * 181)) >> 14;
120
iptr[48 + i] = (16384 - ((sum2 - sum3) * 1891) + ex5) >> 15;
134
if (num_coeffs > 3) {
136
gdouble s = (10000 - ctx->quality) * 10.0 * (gfloat) 9.9999997e-5;
140
else if (is_chrom != 0 && s < 1.0)
147
for (i = 3; i < num_coeffs; i++) {
151
coeff = block[_col_zag[i]] * s;
152
r = coeff - (gint) coeff;
155
block[_col_zag[i]] = (gint) (coeff + 1.0);
157
block[_col_zag[i]] = (gint) (coeff - 1.0);
159
block[_col_zag[i]] = (gint) coeff;
161
if (block[_col_zag[i]] > 120)
162
block[_col_zag[i]] = 120;
163
else if (block[_col_zag[i]] < -120)
164
block[_col_zag[i]] = -120;
170
else if (block[8] < -120)
175
else if (block[1] < -120)
178
for (i = num_coeffs; i < 64; i++)
179
block[_col_zag[i]] = 0;