* [FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function
@ 2024-02-02 0:34 Connor Worley
2024-02-02 9:52 ` Andreas Rheinhardt
0 siblings, 1 reply; 2+ messages in thread
From: Connor Worley @ 2024-02-02 0:34 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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;
}
--
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function
2024-02-02 0:34 [FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function Connor Worley
@ 2024-02-02 9:52 ` Andreas Rheinhardt
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2024-02-02 9:52 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-02 9:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 0:34 [FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function Connor Worley
2024-02-02 9:52 ` Andreas Rheinhardt
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