Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * vlc.c : vlc tables |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2003-2025 x264 project |
5 | | * |
6 | | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
7 | | * Fiona Glaser <fiona@x264.com> |
8 | | * Henrik Gramner <henrik@gramner.com> |
9 | | * |
10 | | * This program is free software; you can redistribute it and/or modify |
11 | | * it under the terms of the GNU General Public License as published by |
12 | | * the Free Software Foundation; either version 2 of the License, or |
13 | | * (at your option) any later version. |
14 | | * |
15 | | * This program is distributed in the hope that it will be useful, |
16 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | * GNU General Public License for more details. |
19 | | * |
20 | | * You should have received a copy of the GNU General Public License |
21 | | * along with this program; if not, write to the Free Software |
22 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
23 | | * |
24 | | * This program is also available under a commercial proprietary license. |
25 | | * For more information, contact us at licensing@x264.com. |
26 | | *****************************************************************************/ |
27 | | |
28 | | #include "common.h" |
29 | | |
30 | | vlc_large_t x264_level_token[7][LEVEL_TABLE_SIZE]; |
31 | | uint32_t x264_run_before[1<<16]; |
32 | | |
33 | | void x264_cavlc_init( x264_t *h ) |
34 | 0 | { |
35 | 0 | for( int i_suffix = 0; i_suffix < 7; i_suffix++ ) |
36 | 0 | for( int16_t level = -LEVEL_TABLE_SIZE/2; level < LEVEL_TABLE_SIZE/2; level++ ) |
37 | 0 | { |
38 | 0 | int mask = level >> 15; |
39 | 0 | int abs_level = (level^mask)-mask; |
40 | 0 | int i_level_code = abs_level ? abs_level*2-mask-2 : 0; |
41 | 0 | int i_next = i_suffix; |
42 | 0 | vlc_large_t *vlc = &x264_level_token[i_suffix][level+LEVEL_TABLE_SIZE/2]; |
43 | |
|
44 | 0 | if( ( i_level_code >> i_suffix ) < 14 ) |
45 | 0 | { |
46 | 0 | vlc->i_size = (i_level_code >> i_suffix) + 1 + i_suffix; |
47 | 0 | vlc->i_bits = (1<<i_suffix) + (i_level_code & ((1<<i_suffix)-1)); |
48 | 0 | } |
49 | 0 | else if( i_suffix == 0 && i_level_code < 30 ) |
50 | 0 | { |
51 | 0 | vlc->i_size = 19; |
52 | 0 | vlc->i_bits = (1<<4) + (i_level_code - 14); |
53 | 0 | } |
54 | 0 | else if( i_suffix > 0 && ( i_level_code >> i_suffix ) == 14 ) |
55 | 0 | { |
56 | 0 | vlc->i_size = 15 + i_suffix; |
57 | 0 | vlc->i_bits = (1<<i_suffix) + (i_level_code & ((1<<i_suffix)-1)); |
58 | 0 | } |
59 | 0 | else |
60 | 0 | { |
61 | 0 | i_level_code -= 15 << i_suffix; |
62 | 0 | if( i_suffix == 0 ) |
63 | 0 | i_level_code -= 15; |
64 | 0 | vlc->i_size = 28; |
65 | 0 | vlc->i_bits = (1<<12) + i_level_code; |
66 | 0 | } |
67 | 0 | if( i_next == 0 ) |
68 | 0 | i_next++; |
69 | 0 | if( abs_level > (3 << (i_next-1)) && i_next < 6 ) |
70 | 0 | i_next++; |
71 | 0 | vlc->i_next = i_next; |
72 | 0 | } |
73 | |
|
74 | 0 | x264_run_before[0] = 0; |
75 | 0 | x264_run_before[1] = 0; |
76 | 0 | for( uint32_t i = 2; i < (1<<16); i++ ) |
77 | 0 | { |
78 | 0 | x264_run_level_t runlevel; |
79 | 0 | ALIGNED_ARRAY_16( dctcoef, dct, [16] ); |
80 | 0 | int size = 0; |
81 | 0 | int bits = 0; |
82 | 0 | for( int j = 0; j < 16; j++ ) |
83 | 0 | dct[j] = i&(1<<j); |
84 | 0 | int total = h->quantf.coeff_level_run[DCT_LUMA_4x4]( dct, &runlevel ); |
85 | 0 | int zeros = runlevel.last + 1 - total; |
86 | 0 | uint32_t mask = i << (x264_clz( i ) + 1); |
87 | 0 | for( int j = 0; j < total-1 && zeros > 0; j++ ) |
88 | 0 | { |
89 | 0 | int idx = X264_MIN(zeros, 7) - 1; |
90 | 0 | int run = x264_clz( mask ); |
91 | 0 | int len = x264_run_before_init[idx][run].i_size; |
92 | 0 | size += len; |
93 | 0 | bits <<= len; |
94 | 0 | bits |= x264_run_before_init[idx][run].i_bits; |
95 | 0 | zeros -= run; |
96 | 0 | mask <<= run + 1; |
97 | 0 | } |
98 | 0 | x264_run_before[i] = (bits << 5) + size; |
99 | 0 | } |
100 | 0 | } Unexecuted instantiation: x264_8_cavlc_init Unexecuted instantiation: x264_10_cavlc_init |