ffmpeg | branch: master | James Almer <jamr...@gmail.com> | Sat Mar 15 21:28:50 2025 -0300| [b6bcc1c3c26891fa7e301437eacc120cc91860eb] | committer: James Almer
avcodec/exr: deprecate gamma and apply_trc options Decoders should not modify sample values, as that's the job of a library like swscale. Signed-off-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b6bcc1c3c26891fa7e301437eacc120cc91860eb --- 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..a16dd96502 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,9 +2099,11 @@ 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) +#endif avctx->color_trc = AVCOL_TRC_LINEAR; switch (s->compression) { @@ -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 75f9fce9d3..14e49f0e15 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -41,6 +41,7 @@ #define FF_API_V408_CODECID (LIBAVCODEC_VERSION_MAJOR < 63) #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 < 63) _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".