mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-24 16:00:02 +01:00
This patch adds a fully-featured level 3 and 4 decoder for FFv1, supporting Golomb and all Range coding variants, all pixel formats, and all features, except for the newly added floating-point formats. On a 6000 Ada, for 3840x2160 bgr0 content at 50Mbps (standard desktop recording), it is able to do 400fps. An Alder Lake with 24 threads can barely do 100fps.
96 lines
2.8 KiB
Plaintext
96 lines
2.8 KiB
Plaintext
/*
|
|
* 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;
|
|
|
|
#if !defined(DECODE)
|
|
PutBitContext pb; /* 8*8 bytes */
|
|
#else
|
|
GetBitContext gb;
|
|
#endif
|
|
|
|
ivec2 slice_dim;
|
|
ivec2 slice_pos;
|
|
ivec2 slice_rct_coef;
|
|
u8vec4 quant_table_idx;
|
|
uint context_count;
|
|
|
|
uint hdr_len; // only used for golomb
|
|
|
|
uint slice_coding_mode;
|
|
bool slice_reset_contexts;
|
|
};
|
|
|
|
/* -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,
|
|
};
|
|
|
|
uint slice_coord(uint width, uint sx, uint num_h_slices, uint chroma_shift)
|
|
{
|
|
uint mpw = 1 << chroma_shift;
|
|
uint awidth = align(width, mpw);
|
|
|
|
if ((version < 4) || ((version == 4) && (micro_version < 3)))
|
|
return width * sx / num_h_slices;
|
|
|
|
sx = (2 * awidth * sx + num_h_slices * mpw) / (2 * num_h_slices * mpw) * mpw;
|
|
if (sx == awidth)
|
|
sx = width;
|
|
|
|
return sx;
|
|
}
|