diff mbox series

[FFmpeg-devel] avcodec/libjxlenc: add option to disable xyb encoding

Message ID 20240129225050.18436-1-leo.izen@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/libjxlenc: add option to disable xyb encoding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Leo Izen Jan. 29, 2024, 10:50 p.m. UTC
Add an AVOption to the libjxl encoder wrapper, which exposes the flag
uses_original_profile in libjxl. For highly unusual ICC profiles where
the target needs to stay in the original space, this can be useful.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavcodec/libjxlenc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index 67be8a01ca..5541fc2bb3 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -52,6 +52,7 @@  typedef struct LibJxlEncodeContext {
     int effort;
     float distance;
     int modular;
+    int xyb;
     uint8_t *buffer;
     size_t buffer_size;
 } LibJxlEncodeContext;
@@ -302,7 +303,7 @@  static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
         av_log(avctx, AV_LOG_WARNING, "Unknown color range, assuming full (pc)\n");
 
     /* bitexact lossless requires there to be no XYB transform */
-    info.uses_original_profile = ctx->distance == 0.0;
+    info.uses_original_profile = ctx->distance == 0.0 || !ctx->xyb;
 
     if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
@@ -466,6 +467,8 @@  static const AVOption libjxl_encode_options[] = {
     { "distance",      "Maximum Butteraugli distance (quality setting, "
                         "lower = better, zero = lossless, default 1.0)",   OFFSET(distance),   AV_OPT_TYPE_FLOAT,  { .dbl = -1.0 }, -1.0,  15.0, VE },
     { "modular",       "Force modular mode",                               OFFSET(modular),    AV_OPT_TYPE_INT,    { .i64 =    0 },    0,     1, VE },
+    { "xyb",           "Use XYB-encoding for lossy images",                OFFSET(xyb),
+        AV_OPT_TYPE_INT,   { .i64 =    1 },    0,     1, VE },
     { NULL },
 };