1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/magicyuvenc: Avoid PutBitContext for byte-aligned writes

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-17 07:22:20 +02:00
parent 3a90bbe4b7
commit 9c69e94354

View File

@ -392,7 +392,7 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane)
}
static int encode_table(AVCodecContext *avctx,
PutBitContext *pb, HuffEntry *he, int plane)
PutByteContext *pb, HuffEntry *he, int plane)
{
MagicYUVContext *s = avctx->priv_data;
PTable counts[256];
@ -416,8 +416,9 @@ static int encode_table(AVCodecContext *avctx,
calculate_codes(he, codes_counts);
for (int i = 0; i < 256; i++) {
put_bits(pb, 1, 0);
put_bits(pb, 7, he[i].len);
// The seven low bits are len; the top bit means the run of
// codes of this length has length one.
bytestream2_put_byte(pb, he[i].len);
}
return 0;
@ -548,8 +549,6 @@ static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
MagicYUVContext *s = avctx->priv_data;
const int width = avctx->width, height = avctx->height;
const int slice_height = s->slice_height;
unsigned tables_size;
PutBitContext pbit;
PutByteContext pb;
int pos, ret = 0;
@ -592,13 +591,8 @@ static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
avctx->execute2(avctx, predict_slice, (void *)frame, NULL, s->nb_slices);
init_put_bits(&pbit, pkt->data + bytestream2_tell_p(&pb), bytestream2_get_bytes_left_p(&pb));
for (int i = 0; i < s->planes; i++)
encode_table(avctx, &pbit, s->he[i], i);
tables_size = put_bytes_count(&pbit, 1);
bytestream2_skip_p(&pb, tables_size);
encode_table(avctx, &pb, s->he[i], i);
for (int i = 0; i < s->nb_slices; ++i) {
for (int j = 0; j < s->planes; ++j) {