Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Thilo Borgmann <thilo.borgmann@mail.de>
Subject: Re: [FFmpeg-devel] [PATCH v9 3/6] libavcodec/webp: add support for animated WebP
Date: Sun, 31 Dec 2023 15:54:10 +0100
Message-ID: <4b327c16-c606-4b1f-9ee4-3d6e54d2baa5@mail.de> (raw)
In-Reply-To: <a98d80ed81e2cd3060f1201c0348a11d0228528c.camel@haerdin.se>


Am 31.12.23 um 13:56 schrieb Tomas Härdin:
>> +    for (int y = 0; y < height; y++) {
>> +        const uint8_t *src1 = src1_data[0] + y * src1_linesize[0];
>> +        const uint8_t *src2 = src2_data[0] + (y + pos_y) *
>> src2_linesize[0] + pos_x * src2_step[0];
>> +        uint8_t       *dest = dest_data[0] + (y + pos_y) *
>> dest_linesize[0] + pos_x * sizeof(uint32_t);
>> +        for (int x = 0; x < width; x++) {
>> +            int src1_alpha = src1[0];
>> +            int src2_alpha = src2[0];
>> +
>> +            if (src1_alpha == 255) {
>> +                memcpy(dest, src1, sizeof(uint32_t));
>> +            } else if (src1_alpha + src2_alpha == 0) {
>> +                memset(dest, 0, sizeof(uint32_t));
>> +            } else {
>> +                int tmp_alpha = src2_alpha - ROUNDED_DIV(src1_alpha
>> * src2_alpha, 255);
>> +                int blend_alpha = src1_alpha + tmp_alpha;
>> +
>> +                dest[0] = blend_alpha;
>> +                dest[1] = ROUNDED_DIV(src1[1] * src1_alpha + src2[1]
>> * tmp_alpha, blend_alpha);
>> +                dest[2] = ROUNDED_DIV(src1[2] * src1_alpha + src2[2]
>> * tmp_alpha, blend_alpha);
>> +                dest[3] = ROUNDED_DIV(src1[3] * src1_alpha + src2[3]
>> * tmp_alpha, blend_alpha);
>> +            }
>
> Is branching and a bunch of function calls (which I hope get optimized
> out) really faster than just always doing the blending?

If I trust my START_TIMER/STOP_TIMER interpretation, I'd say so:

With branches:
253315 UNITS in blend_alpha_yuva,     128 runs,      0 skips

Always blending:
351104 UNITS in blend_alpha_yuva,     128 runs,      0 skips



> It mgiht also be worthwhile to check 8 bytes at a time against
> UINT64_MAX and 0. That doesn't need to hold up this patch though. Same
> with the YUVA version.
>
>> +static int blend_frame_into_canvas(WebPContext *s)
>> +{
>> +    AVFrame *canvas = s->canvas_frame.f;
>> +    AVFrame *frame  = s->frame;
>> +    int width, height;
>> +    int pos_x, pos_y;
>> +
>> +    if ((s->anmf_flags & ANMF_BLENDING_METHOD) ==
>> ANMF_BLENDING_METHOD_OVERWRITE
>> +        || frame->format == AV_PIX_FMT_YUV420P) {
>> +        // do not blend, overwrite
>> +
>> +        if (canvas->format == AV_PIX_FMT_ARGB) {
>> +            width  = s->width;
>> +            height = s->height;
>> +            pos_x  = s->pos_x;
>> +            pos_y  = s->pos_y;
>> +
>> +            for (int y = 0; y < height; y++) {
>> +                const uint32_t *src = (uint32_t *) (frame->data[0] +
>> y * frame->linesize[0]);
>> +                uint32_t *dst = (uint32_t *) (canvas->data[0] + (y +
>> pos_y) * canvas->linesize[0]) + pos_x;
>> +                memcpy(dst, src, width * sizeof(uint32_t));
>> +            }
>
> This could be reduced to a single memcpy() when linesizes are equal.
> Same for the other memcpy()s

Its a subimage copied into a canvas (see pos_x and pos_y).
Has to be copied line-by-line.

Same for the other loops.

-Thilo

_______________________________________________
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".

  reply	other threads:[~2023-12-31 14:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31 12:30 [FFmpeg-devel] [PATCH v9 0/6] webp: add support for animated WebP decoding Thilo Borgmann via ffmpeg-devel
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 1/6] avcodec/webp: remove unused definitions Thilo Borgmann via ffmpeg-devel
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 2/6] avcodec/webp: separate VP8 decoding Thilo Borgmann via ffmpeg-devel
2024-01-25 10:04   ` Anton Khirnov
2024-01-25 15:39     ` Thilo Borgmann via ffmpeg-devel
2024-01-28 10:29       ` Anton Khirnov
2024-01-30 18:39         ` Thilo Borgmann via ffmpeg-devel
2024-02-03 13:53           ` Andreas Rheinhardt
2024-02-04 11:09             ` Thilo Borgmann via ffmpeg-devel
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 3/6] libavcodec/webp: add support for animated WebP Thilo Borgmann via ffmpeg-devel
2023-12-31 12:56   ` Tomas Härdin
2023-12-31 14:54     ` Thilo Borgmann via ffmpeg-devel [this message]
2023-12-31 15:17       ` Tomas Härdin
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 4/6] avcodec/webp: make init_canvas_frame static Thilo Borgmann via ffmpeg-devel
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 5/6] libavformat/webp: add WebP demuxer Thilo Borgmann via ffmpeg-devel
2023-12-31 12:59   ` Tomas Härdin
2023-12-31 14:55     ` Thilo Borgmann via ffmpeg-devel
2023-12-31 12:30 ` [FFmpeg-devel] [PATCH v9 6/6] fate: add test for animated WebP Thilo Borgmann via ffmpeg-devel

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=4b327c16-c606-4b1f-9ee4-3d6e54d2baa5@mail.de \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=thilo.borgmann@mail.de \
    /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