[FFmpeg-cvslog] avcodec/magicyuvenc: Simplify padding slice
Andreas Rheinhardt
git at videolan.org
Sun Apr 20 23:31:21 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Apr 17 07:32:12 2025 +0200| [3a90bbe4b76b8dd3ab630a2505686356aa4733ea] | committer: Andreas Rheinhardt
avcodec/magicyuvenc: Simplify padding slice
Do it before writing the actual slice to be able to use
a single AV_WN32().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a90bbe4b76b8dd3ab630a2505686356aa4733ea
---
libavcodec/magicyuvenc.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c
index a01cafcec6..067441f00a 100644
--- a/libavcodec/magicyuvenc.c
+++ b/libavcodec/magicyuvenc.c
@@ -423,14 +423,13 @@ static int encode_table(AVCodecContext *avctx,
return 0;
}
-static void encode_plane_slice_raw(const uint8_t *src, uint8_t *dst, int dst_size,
+static void encode_plane_slice_raw(const uint8_t *src, uint8_t *dst,
int width, int height, int prediction)
{
unsigned count = width * height;
dst[0] = 1;
dst[1] = prediction;
- AV_WN32(dst + dst_size - 4, 0);
memcpy(dst + 2, src, count);
}
@@ -439,7 +438,6 @@ static void encode_plane_slice(const uint8_t *src, uint8_t *dst, unsigned dst_si
int width, int height, HuffEntry *he, int prediction)
{
PutBitContext pb;
- int count;
init_put_bits(&pb, dst, dst_size);
@@ -456,13 +454,8 @@ static void encode_plane_slice(const uint8_t *src, uint8_t *dst, unsigned dst_si
src += width;
}
- count = put_bits_count(&pb) & 0x1F;
-
- if (count)
- put_bits(&pb, 32 - count, 0);
-
flush_put_bits(&pb);
- av_assert1(put_bytes_left(&pb, 0) == 0);
+ av_assert1(put_bytes_left(&pb, 0) <= 3);
}
static int encode_slice(AVCodecContext *avctx, void *tdata,
@@ -473,8 +466,11 @@ static int encode_slice(AVCodecContext *avctx, void *tdata,
for (int i = 0; i < s->planes; i++) {
Slice *sl = &s->slices[n * s->planes + i];
+ // Zero the padding now
+ AV_WN32(sl->dst + sl->size - 4, 0);
+
if (sl->encode_raw)
- encode_plane_slice_raw(sl->slice, sl->dst, sl->size,
+ encode_plane_slice_raw(sl->slice, sl->dst,
sl->width, sl->height, s->frame_pred);
else
encode_plane_slice(sl->slice,
More information about the ffmpeg-cvslog
mailing list