media/libvpx/vp8/common/quant_common.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp8/common/quant_common.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +
    1.15 +#include "quant_common.h"
    1.16 +
    1.17 +static const int dc_qlookup[QINDEX_RANGE] =
    1.18 +{
    1.19 +    4,    5,    6,    7,    8,    9,   10,   10,   11,   12,   13,   14,   15,   16,   17,   17,
    1.20 +    18,   19,   20,   20,   21,   21,   22,   22,   23,   23,   24,   25,   25,   26,   27,   28,
    1.21 +    29,   30,   31,   32,   33,   34,   35,   36,   37,   37,   38,   39,   40,   41,   42,   43,
    1.22 +    44,   45,   46,   46,   47,   48,   49,   50,   51,   52,   53,   54,   55,   56,   57,   58,
    1.23 +    59,   60,   61,   62,   63,   64,   65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
    1.24 +    75,   76,   76,   77,   78,   79,   80,   81,   82,   83,   84,   85,   86,   87,   88,   89,
    1.25 +    91,   93,   95,   96,   98,  100,  101,  102,  104,  106,  108,  110,  112,  114,  116,  118,
    1.26 +    122,  124,  126,  128,  130,  132,  134,  136,  138,  140,  143,  145,  148,  151,  154,  157,
    1.27 +};
    1.28 +
    1.29 +static const int ac_qlookup[QINDEX_RANGE] =
    1.30 +{
    1.31 +    4,    5,    6,    7,    8,    9,   10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
    1.32 +    20,   21,   22,   23,   24,   25,   26,   27,   28,   29,   30,   31,   32,   33,   34,   35,
    1.33 +    36,   37,   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,   48,   49,   50,   51,
    1.34 +    52,   53,   54,   55,   56,   57,   58,   60,   62,   64,   66,   68,   70,   72,   74,   76,
    1.35 +    78,   80,   82,   84,   86,   88,   90,   92,   94,   96,   98,  100,  102,  104,  106,  108,
    1.36 +    110,  112,  114,  116,  119,  122,  125,  128,  131,  134,  137,  140,  143,  146,  149,  152,
    1.37 +    155,  158,  161,  164,  167,  170,  173,  177,  181,  185,  189,  193,  197,  201,  205,  209,
    1.38 +    213,  217,  221,  225,  229,  234,  239,  245,  249,  254,  259,  264,  269,  274,  279,  284,
    1.39 +};
    1.40 +
    1.41 +
    1.42 +int vp8_dc_quant(int QIndex, int Delta)
    1.43 +{
    1.44 +    int retval;
    1.45 +
    1.46 +    QIndex = QIndex + Delta;
    1.47 +
    1.48 +    if (QIndex > 127)
    1.49 +        QIndex = 127;
    1.50 +    else if (QIndex < 0)
    1.51 +        QIndex = 0;
    1.52 +
    1.53 +    retval = dc_qlookup[ QIndex ];
    1.54 +    return retval;
    1.55 +}
    1.56 +
    1.57 +int vp8_dc2quant(int QIndex, int Delta)
    1.58 +{
    1.59 +    int retval;
    1.60 +
    1.61 +    QIndex = QIndex + Delta;
    1.62 +
    1.63 +    if (QIndex > 127)
    1.64 +        QIndex = 127;
    1.65 +    else if (QIndex < 0)
    1.66 +        QIndex = 0;
    1.67 +
    1.68 +    retval = dc_qlookup[ QIndex ] * 2;
    1.69 +    return retval;
    1.70 +
    1.71 +}
    1.72 +int vp8_dc_uv_quant(int QIndex, int Delta)
    1.73 +{
    1.74 +    int retval;
    1.75 +
    1.76 +    QIndex = QIndex + Delta;
    1.77 +
    1.78 +    if (QIndex > 127)
    1.79 +        QIndex = 127;
    1.80 +    else if (QIndex < 0)
    1.81 +        QIndex = 0;
    1.82 +
    1.83 +    retval = dc_qlookup[ QIndex ];
    1.84 +
    1.85 +    if (retval > 132)
    1.86 +        retval = 132;
    1.87 +
    1.88 +    return retval;
    1.89 +}
    1.90 +
    1.91 +int vp8_ac_yquant(int QIndex)
    1.92 +{
    1.93 +    int retval;
    1.94 +
    1.95 +    if (QIndex > 127)
    1.96 +        QIndex = 127;
    1.97 +    else if (QIndex < 0)
    1.98 +        QIndex = 0;
    1.99 +
   1.100 +    retval = ac_qlookup[ QIndex ];
   1.101 +    return retval;
   1.102 +}
   1.103 +
   1.104 +int vp8_ac2quant(int QIndex, int Delta)
   1.105 +{
   1.106 +    int retval;
   1.107 +
   1.108 +    QIndex = QIndex + Delta;
   1.109 +
   1.110 +    if (QIndex > 127)
   1.111 +        QIndex = 127;
   1.112 +    else if (QIndex < 0)
   1.113 +        QIndex = 0;
   1.114 +
   1.115 +    /* For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
   1.116 +     * The smallest precision for that is '(x*6349) >> 12' but 16 is a good
   1.117 +     * word size. */
   1.118 +    retval = (ac_qlookup[ QIndex ] * 101581) >> 16;
   1.119 +
   1.120 +    if (retval < 8)
   1.121 +        retval = 8;
   1.122 +
   1.123 +    return retval;
   1.124 +}
   1.125 +int vp8_ac_uv_quant(int QIndex, int Delta)
   1.126 +{
   1.127 +    int retval;
   1.128 +
   1.129 +    QIndex = QIndex + Delta;
   1.130 +
   1.131 +    if (QIndex > 127)
   1.132 +        QIndex = 127;
   1.133 +    else if (QIndex < 0)
   1.134 +        QIndex = 0;
   1.135 +
   1.136 +    retval = ac_qlookup[ QIndex ];
   1.137 +    return retval;
   1.138 +}

mercurial