aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/vulkan/ffv1_common.comp
blob: 5b4a882367d2241a52d97031654f6d8dba43bc48 (plain) (blame)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * FFv1 codec
 *
 * Copyright (c) 2024 Lynne <dev@lynne.ee>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

struct SliceContext {
    RangeCoder c;

#ifdef GOLOMB
    PutBitContext pb; /* 8*8 bytes */
#endif

    ivec2 slice_dim;
    ivec2 slice_pos;
    ivec2 slice_rct_coef;

    uint hdr_len; // only used for golomb
    int slice_coding_mode;
};

/* -1, { -1, 0 } */
int predict(int L, ivec2 top)
{
    return mid_pred(L, L + top[1] - top[0], top[1]);
}

/* { -2, -1 }, { -1, 0, 1 }, 0 */
int get_context(VTYPE2 cur_l, VTYPE3 top_l, TYPE top2, uint8_t quant_table_idx)
{
    const int LT = top_l[0]; /* -1 */
    const int T  = top_l[1]; /*  0 */
    const int RT = top_l[2]; /*  1 */
    const int L  = cur_l[1]; /* -1 */

    int base = quant_table[quant_table_idx][0][(L - LT) & MAX_QUANT_TABLE_MASK] +
               quant_table[quant_table_idx][1][(LT - T) & MAX_QUANT_TABLE_MASK] +
               quant_table[quant_table_idx][2][(T - RT) & MAX_QUANT_TABLE_MASK];

    if ((quant_table[quant_table_idx][3][127] == 0) &&
        (quant_table[quant_table_idx][4][127] == 0))
        return base;

    const int TT = top2;     /* -2 */
    const int LL = cur_l[0]; /* -2 */
    return base +
           quant_table[quant_table_idx][3][(LL - L) & MAX_QUANT_TABLE_MASK] +
           quant_table[quant_table_idx][4][(TT - T) & MAX_QUANT_TABLE_MASK];
}

const uint32_t log2_run[41] = {
     0,  0,  0,  0,  1,  1,  1,  1,
     2,  2,  2,  2,  3,  3,  3,  3,
     4,  4,  5,  5,  6,  6,  7,  7,
     8,  9, 10, 11, 12, 13, 14, 15,
    16, 17, 18, 19, 20, 21, 22, 23,
    24,
};