From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/magicyuvenc: Don't modify input frame
Date: Wed, 23 Feb 2022 00:16:39 +0100
Message-ID: <AM7PR03MB666026C87AFD75513D9BD1348F3B9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB66602D3222786A979F95023B8F3B9@AM7PR03MB6660.eurprd03.prod.outlook.com>
It need not be writable at all. Instead, use temporary buffers
for decorrelation.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
The prediction functions could be rewritten to allow src and dst
to alias each other; yet LLVidEncDSPContext.diff_bytes has the
requirement that dst has an alignment of 16.
libavcodec/magicyuvenc.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c
index ffb0be1d14..5a37a49d63 100644
--- a/libavcodec/magicyuvenc.c
+++ b/libavcodec/magicyuvenc.c
@@ -67,6 +67,7 @@ typedef struct MagicYUVContext {
uint8_t *slices[4];
unsigned slice_pos[4];
unsigned tables_size;
+ uint8_t *decorrelate_buf[2];
HuffEntry he[4][256];
LLVidEncDSPContext llvidencdsp;
void (*predict)(struct MagicYUVContext *s, const uint8_t *src, uint8_t *dst,
@@ -190,6 +191,12 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
s->format = 0x6b;
break;
}
+ if (s->correlate) {
+ s->decorrelate_buf[0] = av_calloc(2U * avctx->height, FFALIGN(avctx->width, 16));
+ if (!s->decorrelate_buf[0])
+ return AVERROR(ENOMEM);
+ s->decorrelate_buf[1] = s->decorrelate_buf[0] + avctx->height * FFALIGN(avctx->width, 16);
+ }
ff_llvidencdsp_init(&s->llvidencdsp);
@@ -452,22 +459,26 @@ static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
if (s->correlate) {
- uint8_t *const data[4] = { frame->data[1], frame->data[0],
- frame->data[2], frame->data[3] };
- const int linesize[4] = { frame->linesize[1], frame->linesize[0],
- frame->linesize[2], frame->linesize[3] };
- uint8_t *r, *g, *b;
+ uint8_t *r, *g, *b, *decorrelated[2] = { s->decorrelate_buf[0],
+ s->decorrelate_buf[1] };
+ const int decorrelate_linesize = FFALIGN(width, 16);
+ const uint8_t *const data[4] = { decorrelated[0], frame->data[0],
+ decorrelated[1], frame->data[3] };
+ const int linesize[4] = { decorrelate_linesize, frame->linesize[0],
+ decorrelate_linesize, frame->linesize[3] };
g = frame->data[0];
b = frame->data[1];
r = frame->data[2];
for (i = 0; i < height; i++) {
- s->llvidencdsp.diff_bytes(b, b, g, width);
- s->llvidencdsp.diff_bytes(r, r, g, width);
+ s->llvidencdsp.diff_bytes(decorrelated[0], b, g, width);
+ s->llvidencdsp.diff_bytes(decorrelated[1], r, g, width);
g += frame->linesize[0];
b += frame->linesize[1];
r += frame->linesize[2];
+ decorrelated[0] += decorrelate_linesize;
+ decorrelated[1] += decorrelate_linesize;
}
for (i = 0; i < s->planes; i++) {
@@ -531,6 +542,7 @@ static av_cold int magy_encode_close(AVCodecContext *avctx)
for (i = 0; i < s->planes; i++)
av_freep(&s->slices[i]);
+ av_freep(&s->decorrelate_buf);
return 0;
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-22 23:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 23:10 [FFmpeg-devel] [PATCH 1/5] avcodec/magicyuvenc: Avoid unnecessary av_frame_clone() Andreas Rheinhardt
2022-02-22 23:14 ` [FFmpeg-devel] [PATCH 2/5] avcodec/magicyuvenc: Add const where appropriate Andreas Rheinhardt
2022-02-23 8:56 ` Paul B Mahol
2022-02-22 23:16 ` Andreas Rheinhardt [this message]
2022-02-23 8:54 ` [FFmpeg-devel] [PATCH 3/5] avcodec/magicyuvenc: Don't modify input frame Paul B Mahol
2022-02-22 23:16 ` [FFmpeg-devel] [PATCH 4/5] avcodec/libopenjpegenc: Don't clone AVFrame unnecessarily Andreas Rheinhardt
2022-02-24 9:44 ` Andreas Rheinhardt
2022-02-24 14:30 ` Michael Bradshaw
2022-02-22 23:16 ` [FFmpeg-devel] [PATCH 5/5] avcodec/magicyuvenc: Remove unused context variable Andreas Rheinhardt
2022-02-23 8:56 ` [FFmpeg-devel] [PATCH 1/5] avcodec/magicyuvenc: Avoid unnecessary av_frame_clone() Paul B Mahol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM7PR03MB666026C87AFD75513D9BD1348F3B9@AM7PR03MB6660.eurprd03.prod.outlook.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git