Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avcodec/exr: Remove write-only gamma_table
@ 2025-03-05 13:51 Andreas Rheinhardt
  2025-03-05 16:07 ` Michael Niedermayer
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-03-05 13:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 102 bytes --]

Patches attached. None of which are meant to address the fate failure
mentioned by Martin.

- Andreas

[-- Attachment #2: 0001-avcodec-exr-Remove-write-only-gamma_table.patch --]
[-- Type: text/x-patch, Size: 2331 bytes --]

From d1a59c3fa3101192256bf67484b0cc9d5f2967b2 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 5 Mar 2025 13:57:16 +0100
Subject: [PATCH 1/2] avcodec/exr: Remove write-only gamma_table

Forgotten in 0e917389fe73c932049635d947bba076f1709589.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/exr.c | 31 -------------------------------
 1 file changed, 31 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 7e8020a0ff..8b673046c1 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -190,7 +190,6 @@ typedef struct EXRContext {
 
     enum AVColorTransferCharacteristic apply_trc_type;
     float gamma;
-    union av_intfloat32 gamma_table[65536];
 
     uint8_t *offset_table;
 
@@ -2240,10 +2239,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
 static av_cold int decode_init(AVCodecContext *avctx)
 {
     EXRContext *s = avctx->priv_data;
-    uint32_t i;
-    union av_intfloat32 t;
-    float one_gamma = 1.0f / s->gamma;
-    av_csp_trc_function trc_func = NULL;
 
     ff_init_half2float_tables(&s->h2f_tables);
 
@@ -2255,32 +2250,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
     ff_bswapdsp_init(&s->bbdsp);
 #endif
 
-    trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
-    if (trc_func) {
-        for (i = 0; i < 65536; ++i) {
-            t.i = half2float(i, &s->h2f_tables);
-            t.f = trc_func(t.f);
-            s->gamma_table[i] = t;
-        }
-    } else {
-        if (one_gamma > 0.9999f && one_gamma < 1.0001f) {
-            for (i = 0; i < 65536; ++i) {
-                s->gamma_table[i].i = half2float(i, &s->h2f_tables);
-            }
-        } else {
-            for (i = 0; i < 65536; ++i) {
-                t.i = half2float(i, &s->h2f_tables);
-                /* If negative value we reuse half value */
-                if (t.f <= 0.0f) {
-                    s->gamma_table[i] = t;
-                } else {
-                    t.f = powf(t.f, one_gamma);
-                    s->gamma_table[i] = t;
-                }
-            }
-        }
-    }
-
     // allocate thread data, used for non EXR_RAW compression types
     s->thread_data = av_calloc(avctx->thread_count, sizeof(*s->thread_data));
     if (!s->thread_data)
-- 
2.45.2


[-- Attachment #3: 0002-avcodec-exr-Fix-potential-effective-type-violation.patch --]
[-- Type: text/x-patch, Size: 3393 bytes --]

From a0f2d79445366fda3b485e701c84e69d11148259 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 5 Mar 2025 14:19:13 +0100
Subject: [PATCH 2/2] avcodec/exr: Fix potential effective-type violation

Storing the values via a union of an uint32_t and a float makes
said union the effective type of the destination. This means that
it may only be read via such a union which is of course not what
our users do/expect. So store the values via AV_WN32A instead
which disables effective type analysis (for compilers that perform it).

This also fixes a -Wdeclaration-after-statement warning
introduced in 0e917389fe73c932049635d947bba076f1709589.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/exr.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 8b673046c1..1c753edb9f 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1383,34 +1383,29 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
                     s->compression == EXR_DWAA ||
                     s->compression == EXR_DWAB) {
                     // 32-bit
-                    union av_intfloat32 *ptr_x;
+                    uint8_t *ptr_x = ptr;
 
                     src = channel_buffer[c];
-                    ptr_x = (union av_intfloat32 *)ptr;
 
                     // Zero out the start if xmin is not 0
                     memset(ptr_x, 0, bxmin);
-                    ptr_x += window_xoffset;
+                    ptr_x += 4 * window_xoffset;
 
-                    union av_intfloat32 t;
                     if (trc_func && c < 3) {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            t.f = trc_func(t.f);
-                            *ptr_x++ = t;
+                        for (int x = 0; x < xsize; x++, ptr_x += 4) {
+                            float f = av_int2float(bytestream_get_le32(&src));
+                            AV_WN32A(ptr_x, av_float2int(trc_func(f)));
                         }
                     } else if (one_gamma != 1.f) {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            if (t.f > 0.0f && c < 3)  /* avoid negative values */
-                                t.f = powf(t.f, one_gamma);
-                            *ptr_x++ = t;
+                        for (int x = 0; x < xsize; x++, ptr_x += 4) {
+                            float f = av_int2float(bytestream_get_le32(&src));
+                            if (f > 0.0f && c < 3)  /* avoid negative values */
+                                f = powf(f, one_gamma);
+                            AV_WN32A(ptr_x, av_float2int(f));
                         }
                     } else {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            *ptr_x++ = t;
-                        }
+                        for (int x = 0; x < xsize; x++, ptr_x += 4)
+                            AV_WN32A(ptr_x, bytestream_get_le32(&src));
                     }
                     memset(ptr_x, 0, axmax);
                 } else if (s->pixel_type == EXR_HALF) {
-- 
2.45.2


[-- Attachment #4: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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 1/2] avcodec/exr: Remove write-only gamma_table
  2025-03-05 13:51 [FFmpeg-devel] [PATCH 1/2] avcodec/exr: Remove write-only gamma_table Andreas Rheinhardt
@ 2025-03-05 16:07 ` Michael Niedermayer
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Niedermayer @ 2025-03-05 16:07 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 657 bytes --]

Hi Andreas

On Wed, Mar 05, 2025 at 02:51:39PM +0100, Andreas Rheinhardt wrote:
> Patches attached. None of which are meant to address the fate failure
> mentioned by Martin.

patches LGTM

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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:[~2025-03-05 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-05 13:51 [FFmpeg-devel] [PATCH 1/2] avcodec/exr: Remove write-only gamma_table Andreas Rheinhardt
2025-03-05 16:07 ` Michael Niedermayer

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