You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avcodec/vc2enc: Use LUT to assemble interleaved golomb code
Up until now, the encoder processed only one bit at a time. With this patch, it is eight bits. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "libavutil/mem.h"
|
#include "libavutil/mem.h"
|
||||||
#include "libavutil/pixdesc.h"
|
#include "libavutil/pixdesc.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
|
#include "libavutil/thread.h"
|
||||||
#include "libavutil/version.h"
|
#include "libavutil/version.h"
|
||||||
#include "codec_internal.h"
|
#include "codec_internal.h"
|
||||||
#include "dirac.h"
|
#include "dirac.h"
|
||||||
@@ -186,22 +187,39 @@ typedef struct VC2EncContext {
|
|||||||
enum DiracParseCodes last_parse_code;
|
enum DiracParseCodes last_parse_code;
|
||||||
} VC2EncContext;
|
} VC2EncContext;
|
||||||
|
|
||||||
|
/// x_k x_{k-1} ... x_0 -> 0 x_k 0 x_{k - 1} ... 0 x_0
|
||||||
|
static uint16_t interleaved_ue_golomb_tab[256];
|
||||||
|
/// 1 x_{k-1} ... x_0 -> 0 0 0 x_{k - 1} ... 0 x_0
|
||||||
|
static uint16_t top_interleaved_ue_golomb_tab[256];
|
||||||
|
/// 1 x_{k-1} ... x_0 -> 2 * k
|
||||||
|
static uint8_t golomb_len_tab[256];
|
||||||
|
|
||||||
|
static av_cold void vc2_init_static_data(void)
|
||||||
|
{
|
||||||
|
interleaved_ue_golomb_tab[1] = 1;
|
||||||
|
for (unsigned i = 2; i < 256; ++i) {
|
||||||
|
golomb_len_tab[i] = golomb_len_tab[i >> 1] + 2;
|
||||||
|
interleaved_ue_golomb_tab[i] = (interleaved_ue_golomb_tab[i >> 1] << 2) | (i & 1);
|
||||||
|
top_interleaved_ue_golomb_tab[i] = interleaved_ue_golomb_tab[i] ^ (1 << golomb_len_tab[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
|
static av_always_inline void put_vc2_ue_uint(PutBitContext *pb, uint32_t val)
|
||||||
{
|
{
|
||||||
int i;
|
uint64_t pbits = 1;
|
||||||
int bits = av_log2(++val);
|
int bits = 1;
|
||||||
unsigned topbit = 1 << bits;
|
|
||||||
uint64_t pbits = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < bits; i++) {
|
++val;
|
||||||
topbit >>= 1;
|
|
||||||
av_assert2(pbits <= UINT64_MAX>>3);
|
while (val >> 8) {
|
||||||
pbits <<= 2;
|
pbits |= (uint64_t)interleaved_ue_golomb_tab[val & 0xff] << bits;
|
||||||
if (val & topbit)
|
val >>= 8;
|
||||||
pbits |= 0x1;
|
bits += 16;
|
||||||
}
|
}
|
||||||
|
pbits |= (uint64_t)top_interleaved_ue_golomb_tab[val] << bits;
|
||||||
|
bits += golomb_len_tab[val];
|
||||||
|
|
||||||
put_bits63(pb, 2 * bits + 1, (pbits << 1) | 1);
|
put_bits63(pb, bits, pbits);
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_always_inline int count_vc2_ue_uint(uint32_t val)
|
static av_always_inline int count_vc2_ue_uint(uint32_t val)
|
||||||
@@ -1003,6 +1021,7 @@ static av_cold int vc2_encode_end(AVCodecContext *avctx)
|
|||||||
|
|
||||||
static av_cold int vc2_encode_init(AVCodecContext *avctx)
|
static av_cold int vc2_encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
Plane *p;
|
Plane *p;
|
||||||
SubBand *b;
|
SubBand *b;
|
||||||
int i, level, o, shift;
|
int i, level, o, shift;
|
||||||
@@ -1165,6 +1184,8 @@ static av_cold int vc2_encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ff_thread_once(&init_static_once, vc2_init_static_data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user