From: Leo Izen <leo.izen@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Leo Izen <leo.izen@gmail.com> Subject: [FFmpeg-devel] [PATCH] avcodec/libjxlenc: prevent color encoding from being set twice Date: Sun, 13 Apr 2025 06:12:13 -0400 Message-ID: <20250413101213.26628-1-leo.izen@gmail.com> (raw) We currently populate the color encoding bundle and then check to see if there's an ICC profile to attach, and set the color encoding bundle in either case. The ICC profile overrides the color encoding bundle, so we should not calculate enum-based color encoding if we have an ICC profile present. Fixes several unnecessary warnings from being emitted. Signed-off-by: Leo Izen <leo.izen@gmail.com> --- libavcodec/libjxlenc.c | 115 +++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c index 81d466e6cc..54ba745672 100644 --- a/libavcodec/libjxlenc.c +++ b/libavcodec/libjxlenc.c @@ -258,7 +258,6 @@ static int libjxl_preprocess_stream(AVCodecContext *avctx, const AVFrame *frame, AVFrameSideData *sd; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(frame->format); JxlBasicInfo info; - JxlColorEncoding jxl_color; JxlPixelFormat *jxl_fmt = &ctx->jxl_fmt; int bits_per_sample; #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0) @@ -320,66 +319,70 @@ static int libjxl_preprocess_stream(AVCodecContext *avctx, const AVFrame *frame, return AVERROR_EXTERNAL; } - /* rendering intent doesn't matter here - * but libjxl will whine if we don't set it */ - jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE; - - switch (frame->color_trc && frame->color_trc != AVCOL_TRC_UNSPECIFIED - ? frame->color_trc : avctx->color_trc) { - case AVCOL_TRC_BT709: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709; - break; - case AVCOL_TRC_LINEAR: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR; - break; - case AVCOL_TRC_IEC61966_2_1: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB; - break; - case AVCOL_TRC_SMPTE428: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI; - break; - case AVCOL_TRC_SMPTE2084: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_PQ; - break; - case AVCOL_TRC_ARIB_STD_B67: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG; - break; - case AVCOL_TRC_GAMMA22: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA; - jxl_color.gamma = 1/2.2f; - break; - case AVCOL_TRC_GAMMA28: - jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA; - jxl_color.gamma = 1/2.8f; - break; - default: - if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) { - av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming Linear Light. Colors may be wrong.\n"); + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE); + if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS) { + av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n"); + sd = NULL; + } + + if ((!sd || !sd->size)) { + /* no ICC Profile means enum-style color options */ + JxlColorEncoding jxl_color; + + switch (frame->color_trc && frame->color_trc != AVCOL_TRC_UNSPECIFIED + ? frame->color_trc : avctx->color_trc) { + case AVCOL_TRC_BT709: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_709; + break; + case AVCOL_TRC_LINEAR: jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR; - } else { - av_log(avctx, AV_LOG_WARNING, "Unknown transfer function, assuming IEC61966-2-1/sRGB. Colors may be wrong.\n"); + break; + case AVCOL_TRC_IEC61966_2_1: jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB; + break; + case AVCOL_TRC_SMPTE428: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_DCI; + break; + case AVCOL_TRC_SMPTE2084: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_PQ; + break; + case AVCOL_TRC_ARIB_STD_B67: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_HLG; + break; + case AVCOL_TRC_GAMMA22: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA; + jxl_color.gamma = 1/2.2f; + break; + case AVCOL_TRC_GAMMA28: + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA; + jxl_color.gamma = 1/2.8f; + break; + default: + if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) { + av_log(avctx, AV_LOG_WARNING, + "Unknown transfer function, assuming Linear Light. Colors may be wrong.\n"); + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR; + } else { + av_log(avctx, AV_LOG_WARNING, + "Unknown transfer function, assuming IEC61966-2-1/sRGB. Colors may be wrong.\n"); + jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB; + } } - } - - /* This should be implied to be honest - * but a libjxl bug makes it fail otherwise */ - if (info.num_color_channels == 1) - jxl_color.color_space = JXL_COLOR_SPACE_GRAY; - else - jxl_color.color_space = JXL_COLOR_SPACE_RGB; - ret = libjxl_populate_primaries(avctx, &jxl_color, - frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED - ? frame->color_primaries : avctx->color_primaries); - if (ret < 0) - return ret; + jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE; + if (info.num_color_channels == 1) + jxl_color.color_space = JXL_COLOR_SPACE_GRAY; + else + jxl_color.color_space = JXL_COLOR_SPACE_RGB; - sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE); - if (sd && sd->size && JxlEncoderSetICCProfile(ctx->encoder, sd->data, sd->size) != JXL_ENC_SUCCESS) - av_log(avctx, AV_LOG_WARNING, "Could not set ICC Profile\n"); - if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != JXL_ENC_SUCCESS) - av_log(avctx, AV_LOG_WARNING, "Failed to set JxlColorEncoding\n"); + ret = libjxl_populate_primaries(avctx, &jxl_color, + frame->color_primaries && frame->color_primaries != AVCOL_PRI_UNSPECIFIED + ? frame->color_primaries : avctx->color_primaries); + if (ret < 0) + return ret; + if (JxlEncoderSetColorEncoding(ctx->encoder, &jxl_color) != JXL_ENC_SUCCESS) + av_log(avctx, AV_LOG_WARNING, "Failed to set JxlColorEncoding\n"); + } #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0) if (JxlEncoderSetFrameBitDepth(ctx->options, &jxl_bit_depth) != JXL_ENC_SUCCESS) -- 2.49.0 _______________________________________________ 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".
next reply other threads:[~2025-04-13 10:12 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-04-13 10:12 Leo Izen [this message] 2025-04-15 19:41 ` Leo Izen
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=20250413101213.26628-1-leo.izen@gmail.com \ --to=leo.izen@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