summaryrefslogtreecommitdiff
path: root/vp8/common/predictdc.c
blob: df4c96e4acf2151641af88cf84790faad921424a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 *  Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license and patent
 *  grant that can be found in the LICENSE file in the root of the source
 *  tree. All contributing project authors may be found in the AUTHORS
 *  file in the root of the source tree.
 */


#include <stdlib.h>
#include "blockd.h"


void vp8_predict_dc(short *lastdc, short *thisdc, short quant, short *cons)
{
    int diff;
    int sign;
    int last_dc = *lastdc;
    int this_dc = *thisdc;

    if (*cons  > DCPREDCNTTHRESH)
    {
        this_dc += last_dc;
    }

    diff = abs(last_dc - this_dc);
    sign  = (last_dc >> 31) ^(this_dc >> 31);
    sign |= (!last_dc | !this_dc);

    if (sign)
    {
        *cons = 0;
    }
    else
    {
        if (diff <= DCPREDSIMTHRESH * quant)
            (*cons)++ ;
    }

    *thisdc = this_dc;
    *lastdc = this_dc;
}