[FFmpeg-devel] [PATCH 2/2] avcodec/libjxl: use RGB32F or RGBA32F for 32-bit float JPEG XL
Leo Izen
leo.izen at gmail.com
Fri Oct 14 19:51:06 EEST 2022
On 10/2/22 03:58, Leo Izen wrote:
> Use AV_PIX_FMT_RGB32F or AV_PIX_FMT_RGBA32F for encoding and decoding
> JPEG XL files when encountered, rather than returning an error and
> refusing to do anything.
>
> Signed-off-by: Leo Izen <leo.izen at gmail.com>
> ---
> libavcodec/libjxldec.c | 15 +++++++++------
> libavcodec/libjxlenc.c | 1 +
> 2 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
> index de48bea4b2..92b98388d4 100644
> --- a/libavcodec/libjxldec.c
> +++ b/libavcodec/libjxldec.c
> @@ -104,9 +104,12 @@ static enum AVPixelFormat libjxl_get_pix_fmt(void *avctx, const JxlBasicInfo *ba
> return basic_info->alpha_bits ? AV_PIX_FMT_YA8 : AV_PIX_FMT_GRAY8;
> }
> if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
> - if (basic_info->alpha_bits)
> - return AV_PIX_FMT_NONE;
> format->data_type = JXL_TYPE_FLOAT;
> + if (basic_info->alpha_bits) {
> + av_log(avctx, AV_LOG_WARNING, "Decoding gray+alpha JXL input as RGBA\n");
> + format->num_channels = 4;
> + return AV_PIX_FMT_RGBAF32;
> + }
> return AV_PIX_FMT_GRAYF32;
> }
> format->data_type = JXL_TYPE_UINT16;
> @@ -119,10 +122,10 @@ static enum AVPixelFormat libjxl_get_pix_fmt(void *avctx, const JxlBasicInfo *ba
> format->data_type = JXL_TYPE_UINT8;
> return basic_info->alpha_bits ? AV_PIX_FMT_RGBA : AV_PIX_FMT_RGB24;
> }
> - if (basic_info->bits_per_sample > 16)
> - av_log(avctx, AV_LOG_WARNING, "Downsampling larger integer to 16-bit via libjxl\n");
> - if (basic_info->exponent_bits_per_sample)
> - av_log(avctx, AV_LOG_WARNING, "Downsampling float to 16-bit integer via libjxl\n");
> + if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
> + format->data_type = JXL_TYPE_FLOAT;
> + return basic_info->alpha_bits ? AV_PIX_FMT_RGBAF32 : AV_PIX_FMT_RGBF32;
> + }
> format->data_type = JXL_TYPE_UINT16;
> return basic_info->alpha_bits ? AV_PIX_FMT_RGBA64 : AV_PIX_FMT_RGB48;
> }
> diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
> index 0793ed251b..f9ae086e38 100644
> --- a/libavcodec/libjxlenc.c
> +++ b/libavcodec/libjxlenc.c
> @@ -474,6 +474,7 @@ const FFCodec ff_libjxl_encoder = {
> .p.pix_fmts = (const enum AVPixelFormat[]) {
> AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
> AV_PIX_FMT_RGB48, AV_PIX_FMT_RGBA64,
> + AV_PIX_FMT_RGBF32, AV_PIX_FMT_RGBAF32,
> AV_PIX_FMT_GRAY8, AV_PIX_FMT_YA8,
> AV_PIX_FMT_GRAY16, AV_PIX_FMT_YA16,
> AV_PIX_FMT_GRAYF32,
Bump, thanks.
- Leo Izen (thebombzen)
More information about the ffmpeg-devel
mailing list