Detect toolchain based on gcc -dumpmachine
[profile/ivi/libvpx.git] / vp8 / encoder / quantize.c
1 /*
2  *  Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license 
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may 
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11
12 #include <math.h>
13 #include "vpx_mem/vpx_mem.h"
14
15 #include "quantize.h"
16 #include "entropy.h"
17 #include "predictdc.h"
18
19 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
20 {
21     int i, rc, eob;
22     int zbin;
23     int x, y, z, sz;
24     short *coeff_ptr  = &b->coeff[0];
25     short *zbin_ptr   = &b->zbin[0][0];
26     short *round_ptr  = &b->round[0][0];
27     short *quant_ptr  = &b->quant[0][0];
28     short *qcoeff_ptr = d->qcoeff;
29     short *dqcoeff_ptr = d->dqcoeff;
30     short *dequant_ptr = &d->dequant[0][0];
31
32     vpx_memset(qcoeff_ptr, 0, 32);
33     vpx_memset(dqcoeff_ptr, 0, 32);
34
35     eob = -1;
36
37     for (i = 0; i < 16; i++)
38     {
39         rc   = vp8_default_zig_zag1d[i];
40         z    = coeff_ptr[rc];
41         zbin = zbin_ptr[rc] ;
42
43         sz = (z >> 31);                                 // sign of z
44         x  = (z ^ sz) - sz;                             // x = abs(z)
45
46         if (x >= zbin)
47         {
48             y  = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
49             x  = (y ^ sz) - sz;                         // get the sign back
50             qcoeff_ptr[rc] = x;                          // write to destination
51             dqcoeff_ptr[rc] = x * dequant_ptr[rc];        // dequantized value
52
53             if (y)
54             {
55                 eob = i;                                // last nonzero coeffs
56             }
57         }
58     }
59
60     d->eob = eob + 1;
61
62 }
63
64 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
65 {
66     int i, rc, eob;
67     int zbin;
68     int x, y, z, sz;
69     short *zbin_boost_ptr = &b->zrun_zbin_boost[0];
70     short *coeff_ptr  = &b->coeff[0];
71     short *zbin_ptr   = &b->zbin[0][0];
72     short *round_ptr  = &b->round[0][0];
73     short *quant_ptr  = &b->quant[0][0];
74     short *qcoeff_ptr = d->qcoeff;
75     short *dqcoeff_ptr = d->dqcoeff;
76     short *dequant_ptr = &d->dequant[0][0];
77     short zbin_oq_value = b->zbin_extra;
78
79     vpx_memset(qcoeff_ptr, 0, 32);
80     vpx_memset(dqcoeff_ptr, 0, 32);
81
82     eob = -1;
83
84     for (i = 0; i < 16; i++)
85     {
86         rc   = vp8_default_zig_zag1d[i];
87         z    = coeff_ptr[rc];
88
89         //if ( i == 0 )
90         //    zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
91         //else
92         zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
93
94         zbin_boost_ptr ++;
95         sz = (z >> 31);                                 // sign of z
96         x  = (z ^ sz) - sz;                             // x = abs(z)
97
98         if (x >= zbin)
99         {
100             y  = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
101             x  = (y ^ sz) - sz;                         // get the sign back
102             qcoeff_ptr[rc]  = x;                         // write to destination
103             dqcoeff_ptr[rc] = x * dequant_ptr[rc];        // dequantized value
104
105             if (y)
106             {
107                 eob = i;                                // last nonzero coeffs
108                 zbin_boost_ptr = &b->zrun_zbin_boost[0];    // reset zero runlength
109             }
110         }
111     }
112
113     d->eob = eob + 1;
114 }
115 void vp8_quantize_mby(MACROBLOCK *x)
116 {
117     int i;
118
119     if (x->e_mbd.mbmi.mode != B_PRED && x->e_mbd.mbmi.mode != SPLITMV)
120     {
121         for (i = 0; i < 16; i++)
122         {
123             x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
124             x->e_mbd.mbmi.mb_skip_coeff &= (x->e_mbd.block[i].eob < 2);
125         }
126
127         x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
128         x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[24].eob);
129
130     }
131     else
132     {
133         for (i = 0; i < 16; i++)
134         {
135             x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
136             x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
137         }
138     }
139 }
140
141 void vp8_quantize_mb(MACROBLOCK *x)
142 {
143     int i;
144
145     x->e_mbd.mbmi.mb_skip_coeff = 1;
146
147     if (x->e_mbd.mbmi.mode != B_PRED && x->e_mbd.mbmi.mode != SPLITMV)
148     {
149         for (i = 0; i < 16; i++)
150         {
151             x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
152             x->e_mbd.mbmi.mb_skip_coeff &= (x->e_mbd.block[i].eob < 2);
153         }
154
155         for (i = 16; i < 25; i++)
156         {
157             x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
158             x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
159         }
160     }
161     else
162     {
163         for (i = 0; i < 24; i++)
164         {
165             x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
166             x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
167         }
168     }
169
170 }
171
172
173 void vp8_quantize_mbuv(MACROBLOCK *x)
174 {
175     int i;
176
177     for (i = 16; i < 24; i++)
178     {
179         x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
180         x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
181     }
182 }