Skip to content
Snippets Groups Projects
Contexts.cpp 49.9 KiB
Newer Older
/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
 * granted under this license.
 *
 * Copyright (c) 2010-2019, ITU/ISO/IEC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file     Contexts.cpp
 *  \brief    Classes providing probability descriptions and contexts (also contains context initialization values)
 */

#include "Contexts.h"

#include <algorithm>
#include <cstring>
#include <limits>

#if !JVET_M0453_CABAC_ENGINE
const uint8_t ProbModelTables::m_NextState[128][2] =
{
  {   2,  1 },{   0,  3 },{   4,  0 },{   1,  5 },{   6,  2 },{   3,  7 },{   8,  4 },{   5,  9 },
  {  10,  4 },{   5, 11 },{  12,  8 },{   9, 13 },{  14,  8 },{   9, 15 },{  16, 10 },{  11, 17 },
  {  18, 12 },{  13, 19 },{  20, 14 },{  15, 21 },{  22, 16 },{  17, 23 },{  24, 18 },{  19, 25 },
  {  26, 18 },{  19, 27 },{  28, 22 },{  23, 29 },{  30, 22 },{  23, 31 },{  32, 24 },{  25, 33 },
  {  34, 26 },{  27, 35 },{  36, 26 },{  27, 37 },{  38, 30 },{  31, 39 },{  40, 30 },{  31, 41 },
  {  42, 32 },{  33, 43 },{  44, 32 },{  33, 45 },{  46, 36 },{  37, 47 },{  48, 36 },{  37, 49 },
  {  50, 38 },{  39, 51 },{  52, 38 },{  39, 53 },{  54, 42 },{  43, 55 },{  56, 42 },{  43, 57 },
  {  58, 44 },{  45, 59 },{  60, 44 },{  45, 61 },{  62, 46 },{  47, 63 },{  64, 48 },{  49, 65 },
  {  66, 48 },{  49, 67 },{  68, 50 },{  51, 69 },{  70, 52 },{  53, 71 },{  72, 52 },{  53, 73 },
  {  74, 54 },{  55, 75 },{  76, 54 },{  55, 77 },{  78, 56 },{  57, 79 },{  80, 58 },{  59, 81 },
  {  82, 58 },{  59, 83 },{  84, 60 },{  61, 85 },{  86, 60 },{  61, 87 },{  88, 60 },{  61, 89 },
  {  90, 62 },{  63, 91 },{  92, 64 },{  65, 93 },{  94, 64 },{  65, 95 },{  96, 66 },{  67, 97 },
  {  98, 66 },{  67, 99 },{ 100, 66 },{  67,101 },{ 102, 68 },{  69,103 },{ 104, 68 },{  69,105 },
  { 106, 70 },{  71,107 },{ 108, 70 },{  71,109 },{ 110, 70 },{  71,111 },{ 112, 72 },{  73,113 },
  { 114, 72 },{  73,115 },{ 116, 72 },{  73,117 },{ 118, 74 },{  75,119 },{ 120, 74 },{  75,121 },
  { 122, 74 },{  75,123 },{ 124, 76 },{  77,125 },{ 124, 76 },{  77,125 },{ 126,126 },{ 127,127 }
};

const uint32_t ProbModelTables::m_EstFracBits[128] =
{
  0x07b23, 0x085f9, 0x074a0, 0x08cbc, 0x06ee4, 0x09354, 0x067f4, 0x09c1b, 0x060b0, 0x0a62a, 0x05a9c, 0x0af5b, 0x0548d, 0x0b955, 0x04f56, 0x0c2a9,
  0x04a87, 0x0cbf7, 0x045d6, 0x0d5c3, 0x04144, 0x0e01b, 0x03d88, 0x0e937, 0x039e0, 0x0f2cd, 0x03663, 0x0fc9e, 0x03347, 0x10600, 0x03050, 0x10f95,
  0x02d4d, 0x11a02, 0x02ad3, 0x12333, 0x0286e, 0x12cad, 0x02604, 0x136df, 0x02425, 0x13f48, 0x021f4, 0x149c4, 0x0203e, 0x1527b, 0x01e4d, 0x15d00,
  0x01c99, 0x166de, 0x01b18, 0x17017, 0x019a5, 0x17988, 0x01841, 0x18327, 0x016df, 0x18d50, 0x015d9, 0x19547, 0x0147c, 0x1a083, 0x0138e, 0x1a8a3,
  0x01251, 0x1b418, 0x01166, 0x1bd27, 0x01068, 0x1c77b, 0x00f7f, 0x1d18e, 0x00eda, 0x1d91a, 0x00e19, 0x1e254, 0x00d4f, 0x1ec9a, 0x00c90, 0x1f6e0,
  0x00c01, 0x1fef8, 0x00b5f, 0x208b1, 0x00ab6, 0x21362, 0x00a15, 0x21e46, 0x00988, 0x2285d, 0x00934, 0x22ea8, 0x008a8, 0x239b2, 0x0081d, 0x24577,
  0x007c9, 0x24ce6, 0x00763, 0x25663, 0x00710, 0x25e8f, 0x006a0, 0x26a26, 0x00672, 0x26f23, 0x005e8, 0x27ef8, 0x005ba, 0x284b5, 0x0055e, 0x29057,
  0x0050c, 0x29bab, 0x004c1, 0x2a674, 0x004a7, 0x2aa5e, 0x0046f, 0x2b32f, 0x0041f, 0x2c0ad, 0x003e7, 0x2ca8d, 0x003ba, 0x2d323, 0x0010c, 0x3bfbb
};

const BinFracBits ProbModelTables::m_BinFracBits_128[128] =
{
  {{0x07b23, 0x085f9}}, {{0x085f9, 0x07b23}},   {{0x074a0, 0x08cbc}}, {{0x08cbc, 0x074a0}},   {{0x06ee4, 0x09354}}, {{0x09354, 0x06ee4}},   {{0x067f4, 0x09c1b}}, {{0x09c1b, 0x067f4}},
  {{0x060b0, 0x0a62a}}, {{0x0a62a, 0x060b0}},   {{0x05a9c, 0x0af5b}}, {{0x0af5b, 0x05a9c}},   {{0x0548d, 0x0b955}}, {{0x0b955, 0x0548d}},   {{0x04f56, 0x0c2a9}}, {{0x0c2a9, 0x04f56}},
  {{0x04a87, 0x0cbf7}}, {{0x0cbf7, 0x04a87}},   {{0x045d6, 0x0d5c3}}, {{0x0d5c3, 0x045d6}},   {{0x04144, 0x0e01b}}, {{0x0e01b, 0x04144}},   {{0x03d88, 0x0e937}}, {{0x0e937, 0x03d88}},
  {{0x039e0, 0x0f2cd}}, {{0x0f2cd, 0x039e0}},   {{0x03663, 0x0fc9e}}, {{0x0fc9e, 0x03663}},   {{0x03347, 0x10600}}, {{0x10600, 0x03347}},   {{0x03050, 0x10f95}}, {{0x10f95, 0x03050}},
  {{0x02d4d, 0x11a02}}, {{0x11a02, 0x02d4d}},   {{0x02ad3, 0x12333}}, {{0x12333, 0x02ad3}},   {{0x0286e, 0x12cad}}, {{0x12cad, 0x0286e}},   {{0x02604, 0x136df}}, {{0x136df, 0x02604}},
  {{0x02425, 0x13f48}}, {{0x13f48, 0x02425}},   {{0x021f4, 0x149c4}}, {{0x149c4, 0x021f4}},   {{0x0203e, 0x1527b}}, {{0x1527b, 0x0203e}},   {{0x01e4d, 0x15d00}}, {{0x15d00, 0x01e4d}},
  {{0x01c99, 0x166de}}, {{0x166de, 0x01c99}},   {{0x01b18, 0x17017}}, {{0x17017, 0x01b18}},   {{0x019a5, 0x17988}}, {{0x17988, 0x019a5}},   {{0x01841, 0x18327}}, {{0x18327, 0x01841}},
  {{0x016df, 0x18d50}}, {{0x18d50, 0x016df}},   {{0x015d9, 0x19547}}, {{0x19547, 0x015d9}},   {{0x0147c, 0x1a083}}, {{0x1a083, 0x0147c}},   {{0x0138e, 0x1a8a3}}, {{0x1a8a3, 0x0138e}},
  {{0x01251, 0x1b418}}, {{0x1b418, 0x01251}},   {{0x01166, 0x1bd27}}, {{0x1bd27, 0x01166}},   {{0x01068, 0x1c77b}}, {{0x1c77b, 0x01068}},   {{0x00f7f, 0x1d18e}}, {{0x1d18e, 0x00f7f}},
  {{0x00eda, 0x1d91a}}, {{0x1d91a, 0x00eda}},   {{0x00e19, 0x1e254}}, {{0x1e254, 0x00e19}},   {{0x00d4f, 0x1ec9a}}, {{0x1ec9a, 0x00d4f}},   {{0x00c90, 0x1f6e0}}, {{0x1f6e0, 0x00c90}},
  {{0x00c01, 0x1fef8}}, {{0x1fef8, 0x00c01}},   {{0x00b5f, 0x208b1}}, {{0x208b1, 0x00b5f}},   {{0x00ab6, 0x21362}}, {{0x21362, 0x00ab6}},   {{0x00a15, 0x21e46}}, {{0x21e46, 0x00a15}},
  {{0x00988, 0x2285d}}, {{0x2285d, 0x00988}},   {{0x00934, 0x22ea8}}, {{0x22ea8, 0x00934}},   {{0x008a8, 0x239b2}}, {{0x239b2, 0x008a8}},   {{0x0081d, 0x24577}}, {{0x24577, 0x0081d}},
  {{0x007c9, 0x24ce6}}, {{0x24ce6, 0x007c9}},   {{0x00763, 0x25663}}, {{0x25663, 0x00763}},   {{0x00710, 0x25e8f}}, {{0x25e8f, 0x00710}},   {{0x006a0, 0x26a26}}, {{0x26a26, 0x006a0}},
  {{0x00672, 0x26f23}}, {{0x26f23, 0x00672}},   {{0x005e8, 0x27ef8}}, {{0x27ef8, 0x005e8}},   {{0x005ba, 0x284b5}}, {{0x284b5, 0x005ba}},   {{0x0055e, 0x29057}}, {{0x29057, 0x0055e}},
  {{0x0050c, 0x29bab}}, {{0x29bab, 0x0050c}},   {{0x004c1, 0x2a674}}, {{0x2a674, 0x004c1}},   {{0x004a7, 0x2aa5e}}, {{0x2aa5e, 0x004a7}},   {{0x0046f, 0x2b32f}}, {{0x2b32f, 0x0046f}},
  {{0x0041f, 0x2c0ad}}, {{0x2c0ad, 0x0041f}},   {{0x003e7, 0x2ca8d}}, {{0x2ca8d, 0x003e7}},   {{0x003ba, 0x2d323}}, {{0x2d323, 0x003ba}},   {{0x0010c, 0x3bfbb}}, {{0x3bfbb, 0x0010c}}
};

const uint32_t ProbModelTables::m_EstFracProb[128] =
{
  0x041b5, 0x03df6, 0x04410, 0x03bbc, 0x04636, 0x039a3, 0x048e6, 0x036f6, 0x04bd3, 0x0340c, 0x04e5d, 0x03185, 0x050fa, 0x02eeb, 0x0534b, 0x02c9b,
  0x0557e, 0x02a6a, 0x057b1, 0x02839, 0x059e4, 0x02608, 0x05bba, 0x02433, 0x05d8f, 0x0225e, 0x05f58, 0x02097, 0x060f7, 0x01efa, 0x06288, 0x01d69,
  0x06427, 0x01bcb, 0x06581, 0x01a72, 0x066d4, 0x0191f, 0x0682f, 0x017c6, 0x0693e, 0x016b7, 0x06a80, 0x01576, 0x06b7e, 0x01478, 0x06ca1, 0x01356,
  0x06da2, 0x01255, 0x06e88, 0x01170, 0x06f67, 0x01092, 0x0703e, 0x00fba, 0x07116, 0x00ee3, 0x071b7, 0x00e42, 0x0728f, 0x00d6a, 0x07323, 0x00cd6,
  0x073e9, 0x00c11, 0x0747d, 0x00b7d, 0x0751e, 0x00add, 0x075b2, 0x00a49, 0x0761b, 0x009e0, 0x07697, 0x00964, 0x07719, 0x008e2, 0x07794, 0x00867,
  0x077f1, 0x0080b, 0x0785b, 0x007a1, 0x078c9, 0x00733, 0x07932, 0x006ca, 0x0798f, 0x0066d, 0x079c6, 0x00636, 0x07a23, 0x005da, 0x07a7f, 0x0057d,
  0x07ab7, 0x00546, 0x07afb, 0x00502, 0x07b32, 0x004cb, 0x07b7d, 0x00480, 0x07b9c, 0x00461, 0x07bf8, 0x00405, 0x07c17, 0x003e6, 0x07c55, 0x003a9,
  0x07c8c, 0x00371, 0x07cbf, 0x0033f, 0x07cd0, 0x0032e, 0x07cf6, 0x00308, 0x07d2c, 0x002d1, 0x07d52, 0x002ab, 0x07d71, 0x0028c, 0x07f46, 0x000b5
};

const uint8_t ProbModelTables::m_LPSTable_64_4[64][4] =
{
  { 128, 176, 208, 240 },
  { 128, 167, 197, 227 },
  { 128, 158, 187, 216 },
  { 123, 150, 178, 205 },
  { 116, 142, 169, 195 },
  { 111, 135, 160, 185 },
  { 105, 128, 152, 175 },
  { 100, 122, 144, 166 },
  {  95, 116, 137, 158 },
  {  90, 110, 130, 150 },
  {  85, 104, 123, 142 },
  {  81,  99, 117, 135 },
  {  77,  94, 111, 128 },
  {  73,  89, 105, 122 },
  {  69,  85, 100, 116 },
  {  66,  80,  95, 110 },
  {  62,  76,  90, 104 },
  {  59,  72,  86,  99 },
  {  56,  69,  81,  94 },
  {  53,  65,  77,  89 },
  {  51,  62,  73,  85 },
  {  48,  59,  69,  80 },
  {  46,  56,  66,  76 },
  {  43,  53,  63,  72 },
  {  41,  50,  59,  69 },
  {  39,  48,  56,  65 },
  {  37,  45,  54,  62 },
  {  35,  43,  51,  59 },
  {  33,  41,  48,  56 },
  {  32,  39,  46,  53 },
  {  30,  37,  43,  50 },
  {  29,  35,  41,  48 },
  {  27,  33,  39,  45 },
  {  26,  31,  37,  43 },
  {  24,  30,  35,  41 },
  {  23,  28,  33,  39 },
  {  22,  27,  32,  37 },
  {  21,  26,  30,  35 },
  {  20,  24,  29,  33 },
  {  19,  23,  27,  31 },
  {  18,  22,  26,  30 },
  {  17,  21,  25,  28 },
  {  16,  20,  23,  27 },
  {  15,  19,  22,  25 },
  {  14,  18,  21,  24 },
  {  14,  17,  20,  23 },
  {  13,  16,  19,  22 },
  {  12,  15,  18,  21 },
  {  12,  14,  17,  20 },
  {  11,  14,  16,  19 },
  {  11,  13,  15,  18 },
  {  10,  12,  15,  17 },
  {  10,  12,  14,  16 },
  {   9,  11,  13,  15 },
  {   9,  11,  12,  14 },
  {   8,  10,  12,  14 },
  {   8,   9,  11,  13 },
  {   7,   9,  11,  12 },
  {   7,   9,  10,  12 },
  {   7,   8,  10,  11 },
  {   6,   8,   9,  11 },
  {   6,   7,   9,  10 },
  {   6,   7,   8,   9 },
  {   2,   2,   2,   2 }
};

const uint8_t ProbModelTables::m_RenormTable_32[32] =
{
  6,  5,  4,  4,
  3,  3,  3,  3,
  2,  2,  2,  2,
  2,  2,  2,  2,
  1,  1,  1,  1,
  1,  1,  1,  1,
  1,  1,  1,  1,
  1,  1,  1,  1
};

#if JVET_M0453_CABAC_ENGINE
const BinFracBits ProbModelTables::m_binFracBits[256] = {
  { { 0x0005c, 0x48000 } }, { { 0x00116, 0x3b520 } }, { { 0x001d0, 0x356cb } }, { { 0x0028b, 0x318a9 } },
  { { 0x00346, 0x2ea40 } }, { { 0x00403, 0x2c531 } }, { { 0x004c0, 0x2a658 } }, { { 0x0057e, 0x28beb } },
  { { 0x0063c, 0x274ce } }, { { 0x006fc, 0x26044 } }, { { 0x007bc, 0x24dc9 } }, { { 0x0087d, 0x23cfc } },
  { { 0x0093f, 0x22d96 } }, { { 0x00a01, 0x21f60 } }, { { 0x00ac4, 0x2122e } }, { { 0x00b89, 0x205dd } },
  { { 0x00c4e, 0x1fa51 } }, { { 0x00d13, 0x1ef74 } }, { { 0x00dda, 0x1e531 } }, { { 0x00ea2, 0x1db78 } },
  { { 0x00f6a, 0x1d23c } }, { { 0x01033, 0x1c970 } }, { { 0x010fd, 0x1c10b } }, { { 0x011c8, 0x1b903 } },
  { { 0x01294, 0x1b151 } }, { { 0x01360, 0x1a9ee } }, { { 0x0142e, 0x1a2d4 } }, { { 0x014fc, 0x19bfc } },
  { { 0x015cc, 0x19564 } }, { { 0x0169c, 0x18f06 } }, { { 0x0176d, 0x188de } }, { { 0x0183f, 0x182e8 } },
  { { 0x01912, 0x17d23 } }, { { 0x019e6, 0x1778a } }, { { 0x01abb, 0x1721c } }, { { 0x01b91, 0x16cd5 } },
Loading
Loading full blame...