• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/dirac_arith.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Marco Gerards <marco@gnu.org>
00003  * Copyright (C) 2009 David Conrad
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #include "dirac_arith.h"
00029 
00030 
00031 const uint16_t ff_dirac_prob[256] = {
00032     0,    2,    5,    8,    11,   15,   20,   24,
00033     29,   35,   41,   47,   53,   60,   67,   74,
00034     82,   89,   97,   106,  114,  123,  132,  141,
00035     150,  160,  170,  180,  190,  201,  211,  222,
00036     233,  244,  256,  267,  279,  291,  303,  315,
00037     327,  340,  353,  366,  379,  392,  405,  419,
00038     433,  447,  461,  475,  489,  504,  518,  533,
00039     548,  563,  578,  593,  609,  624,  640,  656,
00040     672,  688,  705,  721,  738,  754,  771,  788,
00041     805,  822,  840,  857,  875,  892,  910,  928,
00042     946,  964,  983,  1001, 1020, 1038, 1057, 1076,
00043     1095, 1114, 1133, 1153, 1172, 1192, 1211, 1231,
00044     1251, 1271, 1291, 1311, 1332, 1352, 1373, 1393,
00045     1414, 1435, 1456, 1477, 1498, 1520, 1541, 1562,
00046     1584, 1606, 1628, 1649, 1671, 1694, 1716, 1738,
00047     1760, 1783, 1806, 1828, 1851, 1874, 1897, 1920,
00048     1935, 1942, 1949, 1955, 1961, 1968, 1974, 1980,
00049     1985, 1991, 1996, 2001, 2006, 2011, 2016, 2021,
00050     2025, 2029, 2033, 2037, 2040, 2044, 2047, 2050,
00051     2053, 2056, 2058, 2061, 2063, 2065, 2066, 2068,
00052     2069, 2070, 2071, 2072, 2072, 2072, 2072, 2072,
00053     2072, 2071, 2070, 2069, 2068, 2066, 2065, 2063,
00054     2060, 2058, 2055, 2052, 2049, 2045, 2042, 2038,
00055     2033, 2029, 2024, 2019, 2013, 2008, 2002, 1996,
00056     1989, 1982, 1975, 1968, 1960, 1952, 1943, 1934,
00057     1925, 1916, 1906, 1896, 1885, 1874, 1863, 1851,
00058     1839, 1827, 1814, 1800, 1786, 1772, 1757, 1742,
00059     1727, 1710, 1694, 1676, 1659, 1640, 1622, 1602,
00060     1582, 1561, 1540, 1518, 1495, 1471, 1447, 1422,
00061     1396, 1369, 1341, 1312, 1282, 1251, 1219, 1186,
00062     1151, 1114, 1077, 1037, 995,  952,  906,  857,
00063     805,  750,  690,  625,  553,  471,  376,  255
00064 };
00065 
00066 const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT] = {
00067     [CTX_ZPZN_F1]   = CTX_ZP_F2,
00068     [CTX_ZPNN_F1]   = CTX_ZP_F2,
00069     [CTX_ZP_F2]     = CTX_ZP_F3,
00070     [CTX_ZP_F3]     = CTX_ZP_F4,
00071     [CTX_ZP_F4]     = CTX_ZP_F5,
00072     [CTX_ZP_F5]     = CTX_ZP_F6,
00073     [CTX_ZP_F6]     = CTX_ZP_F6,
00074     [CTX_NPZN_F1]   = CTX_NP_F2,
00075     [CTX_NPNN_F1]   = CTX_NP_F2,
00076     [CTX_NP_F2]     = CTX_NP_F3,
00077     [CTX_NP_F3]     = CTX_NP_F4,
00078     [CTX_NP_F4]     = CTX_NP_F5,
00079     [CTX_NP_F5]     = CTX_NP_F6,
00080     [CTX_NP_F6]     = CTX_NP_F6,
00081     [CTX_DELTA_Q_F] = CTX_DELTA_Q_F,
00082 };
00083 
00084 int16_t ff_dirac_prob_branchless[256][2];
00085 
00086 void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length)
00087 {
00088     int i;
00089     align_get_bits(gb);
00090 
00091     length = FFMIN(length, get_bits_left(gb)/8);
00092 
00093     c->bytestream     = gb->buffer + get_bits_count(gb)/8;
00094     c->bytestream_end = c->bytestream + length;
00095     skip_bits_long(gb, length*8);
00096 
00097     c->low = 0;
00098     for (i = 0; i < 4; i++) {
00099         c->low <<= 8;
00100         if (c->bytestream < c->bytestream_end)
00101             c->low |= *c->bytestream++;
00102         else
00103             c->low |= 0xff;
00104     }
00105 
00106     c->counter = -16;
00107     c->range   = 0xffff;
00108 
00109     for (i = 0; i < 256; i++) {
00110         ff_dirac_prob_branchless[i][0] =  ff_dirac_prob[255-i];
00111         ff_dirac_prob_branchless[i][1] = -ff_dirac_prob[i];
00112     }
00113 
00114     for (i = 0; i < DIRAC_CTX_COUNT; i++)
00115         c->contexts[i] = 0x8000;
00116 }
Generated on Fri Feb 1 2013 14:34:32 for FFmpeg by doxygen 1.7.1