From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avcodec/exr: deprecate gamma and apply_trc options
Date: Sat, 15 Mar 2025 21:30:26 -0300
Message-ID: <20250316003026.1192-1-jamrial@gmail.com> (raw)
In-Reply-To: <20250314020809.14220-1-jamrial@gmail.com>
Decoders should not modify sample values, as that's the job of a library like swscale.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/exr.c | 38 ++++++++++++++++++++++++++------------
libavcodec/version_major.h | 1 +
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index e1e05902c6..0bd9ce9ebe 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -189,15 +189,17 @@ typedef struct EXRContext {
const char *layer;
int selected_part;
- enum AVColorTransferCharacteristic apply_trc_type;
- float gamma;
uint8_t *offset_table;
+#if FF_API_EXR_GAMMA
+ enum AVColorTransferCharacteristic apply_trc_type;
+ float gamma;
uint16_t gamma_table[65536];
+ Float2HalfTables f2h_tables;
+#endif
Half2FloatTables h2f_tables;
- Float2HalfTables f2h_tables;
} EXRContext;
static int zip_uncompress(const EXRContext *s, const uint8_t *src, int compressed_size,
@@ -1194,8 +1196,10 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
int data_xoffset, data_yoffset, data_window_offset, xsize, ysize;
int i, x, buf_size = s->buf_size;
int c, rgb_channel_count;
+#if FF_API_EXR_GAMMA
float one_gamma = 1.0f / s->gamma;
av_csp_trc_function trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
+#endif
int ret;
line_offset = AV_RL64(s->gb.buffer + jobnr * 8);
@@ -1387,6 +1391,7 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
s->compression == EXR_DWAA ||
s->compression == EXR_DWAB) {
// 32-bit
+#if FF_API_EXR_GAMMA
if (trc_func && (!c || (c < 3 && s->desc->flags & AV_PIX_FMT_FLAG_PLANAR))) {
for (int x = 0; x < xsize; x++, ptr_x += step) {
float f = av_int2float(bytestream_get_le32(&src));
@@ -1399,19 +1404,20 @@ static int decode_block(AVCodecContext *avctx, void *tdata,
f = powf(f, one_gamma);
AV_WN32A(ptr_x, av_float2int(f));
}
- } else {
+ } else
+#endif
for (int x = 0; x < xsize; x++, ptr_x += step)
AV_WN32A(ptr_x, bytestream_get_le32(&src));
- }
} else if (s->pixel_type == EXR_HALF) {
// 16-bit
+#if FF_API_EXR_GAMMA
if (one_gamma != 1.f || (trc_func && (!c || (c < 3 && s->desc->flags & AV_PIX_FMT_FLAG_PLANAR)))) {
for (int x = 0; x < xsize; x++, ptr_x += step)
AV_WN16A(ptr_x, s->gamma_table[bytestream_get_le16(&src)]);
- } else {
+ } else
+#endif
for (int x = 0; x < xsize; x++, ptr_x += step)
AV_WN16A(ptr_x, bytestream_get_le16(&src));
- }
}
// Zero out the end if xmax+1 is not w
@@ -2093,10 +2099,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
return AVERROR_INVALIDDATA;
}
+#if FF_API_EXR_GAMMA
if (s->apply_trc_type != AVCOL_TRC_UNSPECIFIED)
avctx->color_trc = s->apply_trc_type;
else if (s->gamma > 0.9999f && s->gamma < 1.0001f)
avctx->color_trc = AVCOL_TRC_LINEAR;
+#endif
switch (s->compression) {
case EXR_RAW:
@@ -2221,13 +2229,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
static av_cold int decode_init(AVCodecContext *avctx)
{
EXRContext *s = avctx->priv_data;
+#if FF_API_EXR_GAMMA
uint32_t i;
union av_intfloat32 t;
float one_gamma = 1.0f / s->gamma;
av_csp_trc_function trc_func = NULL;
+ ff_init_float2half_tables(&s->f2h_tables);
+#endif
ff_init_half2float_tables(&s->h2f_tables);
- ff_init_float2half_tables(&s->f2h_tables);
s->avctx = avctx;
@@ -2237,6 +2247,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
ff_bswapdsp_init(&s->bbdsp);
#endif
+#if FF_API_EXR_GAMMA
trc_func = av_csp_trc_func_from_id(s->apply_trc_type);
if (trc_func) {
for (i = 0; i < 65536; ++i) {
@@ -2256,6 +2267,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
}
}
}
+#endif
// allocate thread data, used for non EXR_RAW compression types
s->thread_data = av_calloc(avctx->thread_count, sizeof(*s->thread_data));
@@ -2298,12 +2310,13 @@ static const AVOption options[] = {
AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
{ "part", "Set the decoding part", OFFSET(selected_part),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VD },
- { "gamma", "Set the float gamma value when decoding", OFFSET(gamma),
- AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD },
+#if FF_API_EXR_GAMMA
+ { "gamma", "Set the float gamma value when decoding (deprecated, use a scaler)", OFFSET(gamma),
+ AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD | AV_OPT_FLAG_DEPRECATED },
// XXX: Note the abuse of the enum using AVCOL_TRC_UNSPECIFIED to subsume the existing gamma option
- { "apply_trc", "color transfer characteristics to apply to EXR linear input", OFFSET(apply_trc_type),
- AV_OPT_TYPE_INT, {.i64 = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, VD, .unit = "apply_trc_type"},
+ { "apply_trc", "color transfer characteristics to apply to EXR linear input (deprecated, use a scaler)", OFFSET(apply_trc_type),
+ AV_OPT_TYPE_INT, {.i64 = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, VD | AV_OPT_FLAG_DEPRECATED, .unit = "apply_trc_type"},
{ "bt709", "BT.709", 0,
AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT709 }, INT_MIN, INT_MAX, VD, .unit = "apply_trc_type"},
{ "gamma", "gamma", 0,
@@ -2336,6 +2349,7 @@ static const AVOption options[] = {
AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST2084 }, INT_MIN, INT_MAX, VD, .unit = "apply_trc_type"},
{ "smpte428_1", "SMPTE ST 428-1", 0,
AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST428_1 }, INT_MIN, INT_MAX, VD, .unit = "apply_trc_type"},
+#endif
{ NULL },
};
diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h
index 35df5eb779..55e79d5505 100644
--- a/libavcodec/version_major.h
+++ b/libavcodec/version_major.h
@@ -50,6 +50,7 @@
#define FF_API_QUALITY_FACTOR (LIBAVCODEC_VERSION_MAJOR < 62)
#define FF_API_V408_CODECID (LIBAVCODEC_VERSION_MAJOR < 62)
#define FF_API_CODEC_PROPS (LIBAVCODEC_VERSION_MAJOR < 63)
+#define FF_API_EXR_GAMMA (LIBAVCODEC_VERSION_MAJOR < 63)
// reminder to remove the OMX encoder on next major bump
#define FF_CODEC_OMX (LIBAVCODEC_VERSION_MAJOR < 62)
--
2.48.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".
prev parent reply other threads:[~2025-03-16 0:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 2:08 [FFmpeg-devel] [PATCH] avcodec/exrdec: restore applying color transfer characteristics for float16 samples James Almer
2025-03-15 23:35 ` Michael Niedermayer
2025-03-15 23:36 ` James Almer
2025-03-15 23:42 ` Michael Niedermayer
2025-03-16 0:09 ` James Almer
2025-03-16 0:20 ` Michael Niedermayer
2025-03-16 0:30 ` James Almer [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=20250316003026.1192-1-jamrial@gmail.com \
--to=jamrial@gmail.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