Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function
Date: Fri, 2 Feb 2024 10:52:09 +0100
Message-ID: <AS8P250MB0744081CD95179AAA5B7627F8F422@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20240202003444.30893-1-connorbworley@gmail.com>

Connor Worley:
> For future use in lavc/dxvenc.
> 
> Signed-off-by: Connor Worley <connorbworley@gmail.com>
> ---
>  libavcodec/texturedsp.h    |  1 +
>  libavcodec/texturedspenc.c | 41 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+)
> 
> diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h
> index 86c8eea02d..8881436187 100644
> --- a/libavcodec/texturedsp.h
> +++ b/libavcodec/texturedsp.h
> @@ -62,6 +62,7 @@ typedef struct TextureDSPContext {
>  
>  typedef struct TextureDSPEncContext {
>      int (*dxt1_block)        (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
> +    int (*dxt4_block)        (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
>      int (*dxt5_block)        (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
>      int (*dxt5ys_block)      (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
>  } TextureDSPEncContext;
> diff --git a/libavcodec/texturedspenc.c b/libavcodec/texturedspenc.c
> index 5657a6ef61..c98a277f56 100644
> --- a/libavcodec/texturedspenc.c
> +++ b/libavcodec/texturedspenc.c
> @@ -589,6 +589,20 @@ static void rgba2ycocg(uint8_t *dst, const uint8_t *pixel)
>      dst[3] = av_clip_uint8(g + t);                      /* Y */
>  }
>  
> +/** Convert a straight alpha pixel to a premultiplied alpha pixel. */
> +static av_always_inline void straight2premult(uint8_t *dst, const uint8_t *src)
> +{
> +    const int r = src[0];
> +    const int g = src[1];
> +    const int b = src[2];
> +    const int a = src[3]; /* unchanged */
> +
> +    dst[0] = (uint8_t) r * a / 255;
> +    dst[1] = (uint8_t) g * a / 255;
> +    dst[2] = (uint8_t) b * a / 255;
> +    dst[3] = a;
> +}
> +
>  /**
>   * Compress one block of RGBA pixels in a DXT1 texture and store the
>   * resulting bytes in 'dst'. Alpha is not preserved.
> @@ -605,6 +619,32 @@ static int dxt1_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
>      return 8;
>  }
>  
> +/**
> + * Compress one block of RGBA pixels in a DXT4 texture and store the
> + * resulting bytes in 'dst'. Alpha is preserved.
> + *
> + * @param dst    output buffer.
> + * @param stride scanline in bytes.
> + * @param block  block to compress.
> + * @return how much texture data has been written.
> + */
> +static int dxt4_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
> +{
> +    int x, y;
> +    uint8_t premult[64];
> +
> +    for (y = 0; y < 4; y++) {
> +        for (x = 0; x < 4; x++) {
> +            straight2premult(premult + x * 4 + y * 16, block + x * 4 + y * stride);
> +        }
> +    }
> +
> +    compress_alpha(dst, 16, premult);
> +    compress_color(dst + 8, 16, premult);
> +
> +    return 16;
> +}
> +
>  /**
>   * Compress one block of RGBA pixels in a DXT5 texture and store the
>   * resulting bytes in 'dst'. Alpha is preserved.
> @@ -650,6 +690,7 @@ static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
>  av_cold void ff_texturedspenc_init(TextureDSPEncContext *c)
>  {
>      c->dxt1_block         = dxt1_block;
> +    c->dxt4_block         = dxt4_block;
>      c->dxt5_block         = dxt5_block;
>      c->dxt5ys_block       = dxt5ys_block;
>  }

This should be added in a patchset that actually makes use of it to
avoid the fate of rgtc1_u_alpha.

- Andreas

_______________________________________________
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:[~2024-02-02  9:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02  0:34 Connor Worley
2024-02-02  9:52 ` Andreas Rheinhardt [this message]

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=AS8P250MB0744081CD95179AAA5B7627F8F422@AS8P250MB0744.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