From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 6/6] avcodec/huffyuvenc: Avoid code duplication Date: Thu, 4 Apr 2024 07:02:50 +0200 Message-ID: <GV1P250MB07377EA49F11961B4A38F4018F3C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <GV1P250MB07373EAE6095C91504AB56B98F3C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> This also fixes misindentated code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/huffyuvenc.c | 146 ++++++++++++---------------------------- 1 file changed, 43 insertions(+), 103 deletions(-) diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index fd6b01de81..d822793406 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -499,7 +499,7 @@ static int encode_422_bitstream(HYuvEncContext *s, int offset, int count) static int encode_plane_bitstream(HYuvEncContext *s, int width, int plane) { - int i, count = width/2; + int count = width/2; if (put_bytes_left(&s->pb, 0) < count * s->bps / 2) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); @@ -546,112 +546,52 @@ static int encode_plane_bitstream(HYuvEncContext *s, int width, int plane) put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\ put_bits(&s->pb, 2, y1&3); - if (s->bps <= 8) { - if (s->flags & AV_CODEC_FLAG_PASS1) { - for (i = 0; i < count; i++) { - LOAD2; - STAT2; - } - if (width&1) { - LOADEND; - STATEND; - } - } - if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) - return 0; +#define ENCODE_PLANE(LOAD, LOADEND, WRITE, WRITEEND, STAT, STATEND) \ +do { \ + if (s->flags & AV_CODEC_FLAG_PASS1) { \ + for (int i = 0; i < count; i++) { \ + LOAD; \ + STAT; \ + } \ + if (width & 1) { \ + LOADEND; \ + STATEND; \ + } \ + } \ + if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) \ + return 0; \ + \ + if (s->context) { \ + for (int i = 0; i < count; i++) { \ + LOAD; \ + STAT; \ + WRITE; \ + } \ + if (width & 1) { \ + LOADEND; \ + STATEND; \ + WRITEEND; \ + } \ + } else { \ + for (int i = 0; i < count; i++) { \ + LOAD; \ + WRITE; \ + } \ + if (width & 1) { \ + LOADEND; \ + WRITEEND; \ + } \ + } \ +} while (0) - if (s->context) { - for (i = 0; i < count; i++) { - LOAD2; - STAT2; - WRITE2; - } - if (width&1) { - LOADEND; - STATEND; - WRITEEND; - } - } else { - for (i = 0; i < count; i++) { - LOAD2; - WRITE2; - } - if (width&1) { - LOADEND; - WRITEEND; - } - } + if (s->bps <= 8) { + ENCODE_PLANE(LOAD2, LOADEND, WRITE2, WRITEEND, STAT2, STATEND); } else if (s->bps <= 14) { int mask = s->n - 1; - if (s->flags & AV_CODEC_FLAG_PASS1) { - for (i = 0; i < count; i++) { - LOAD2_14; - STAT2; - } - if (width&1) { - LOADEND_14; - STATEND; - } - } - if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) - return 0; - - if (s->context) { - for (i = 0; i < count; i++) { - LOAD2_14; - STAT2; - WRITE2; - } - if (width&1) { - LOADEND_14; - STATEND; - WRITEEND; - } - } else { - for (i = 0; i < count; i++) { - LOAD2_14; - WRITE2; - } - if (width&1) { - LOADEND_14; - WRITEEND; - } - } + + ENCODE_PLANE(LOAD2_14, LOADEND_14, WRITE2, WRITEEND, STAT2, STATEND); } else { - if (s->flags & AV_CODEC_FLAG_PASS1) { - for (i = 0; i < count; i++) { - LOAD2_16; - STAT2_16; - } - if (width&1) { - LOADEND_16; - STATEND_16; - } - } - if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) - return 0; - - if (s->context) { - for (i = 0; i < count; i++) { - LOAD2_16; - STAT2_16; - WRITE2_16; - } - if (width&1) { - LOADEND_16; - STATEND_16; - WRITEEND_16; - } - } else { - for (i = 0; i < count; i++) { - LOAD2_16; - WRITE2_16; - } - if (width&1) { - LOADEND_16; - WRITEEND_16; - } - } + ENCODE_PLANE(LOAD2_16, LOADEND_16, WRITE2_16, WRITEEND_16, STAT2_16, STATEND_16); } #undef LOAD2 #undef STAT2 -- 2.40.1 _______________________________________________ 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:[~2024-04-04 5:03 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-04 4:59 [FFmpeg-devel] [PATCH 1/6] avcodec/huffyuvdec: Don't zero unnecessarily Andreas Rheinhardt 2024-04-04 5:02 ` [FFmpeg-devel] [PATCH 2/6] avcodec/huffyuv: Inline common alloc/free functions in their callers Andreas Rheinhardt 2024-04-04 5:02 ` [FFmpeg-devel] [PATCH 3/6] avcodec/huffyuv(dec|enc): Use union for temp/temp16 Andreas Rheinhardt 2024-04-04 5:02 ` [FFmpeg-devel] [PATCH 4/6] avcodec/huffyuv: Return proper error code Andreas Rheinhardt 2024-04-04 5:02 ` [FFmpeg-devel] [PATCH 5/6] avcodec/huffyuvenc: Avoid duplicate variables Andreas Rheinhardt 2024-04-04 5:02 ` Andreas Rheinhardt [this message] 2024-04-04 17:52 ` [FFmpeg-devel] [PATCH 7/7] avcodec/huffyuvenc: Deduplicate options Andreas Rheinhardt 2024-04-04 19:30 ` [FFmpeg-devel] [PATCH 8/9] avcodec/huffyuvdec: Use assert to check for things that can't fail Andreas Rheinhardt 2024-04-04 19:30 ` [FFmpeg-devel] [PATCH 9/9] avcodec/dv: Don't pretend initializing work chunks can fail Andreas Rheinhardt 2024-04-04 19:33 ` Andreas Rheinhardt 2024-04-04 19:33 ` [FFmpeg-devel] [PATCH v2 8/9] avcodec/huffyuvdec: Use bytestream API for byte-aligned reads Andreas Rheinhardt 2024-04-04 19:33 ` [FFmpeg-devel] [PATCH v2 9/9] avcodec/huffyuvdec: Use assert to check for things that can't fail Andreas Rheinhardt 2024-04-05 22:23 ` [FFmpeg-devel] [PATCH 1/6] avcodec/huffyuvdec: Don't zero unnecessarily Andreas Rheinhardt
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=GV1P250MB07377EA49F11961B4A38F4018F3C2@GV1P250MB0737.EURP250.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