Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Zsolt Vadász via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: "Zsolt Vadász" <zsolt_vadasz@protonmail.com>
Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/libjxlenc: Move JxlBasicInfo to LibJxlEncodeContext
Date: Mon, 11 Dec 2023 17:05:13 +0000
Message-ID: <pS2jlZqMdQ_AGDQU10Aiw8gOViZGDn8qxhQ4I8EXeF7uzIsgtTnBtDDoZr2BMf82o349lMI0seVvZt_WgSR1DQPeCPMyTVIlxSoCvFoKOjw=@protonmail.com> (raw)

---
 libavcodec/libjxlenc.c | 45 +++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index d707f3a61b..92a458d51a 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -49,6 +49,7 @@ typedef struct LibJxlEncodeContext {
     void *runner;
     JxlEncoder *encoder;
     JxlEncoderFrameSettings *options;
+    JxlBasicInfo info;
     int effort;
     float distance;
     int modular;
@@ -95,9 +96,6 @@ static int libjxl_init_jxl_encoder(AVCodecContext *avctx)
 {
     LibJxlEncodeContext *ctx = avctx->priv_data;
 
-    /* reset the encoder every frame for image2 muxer */
-    JxlEncoderReset(ctx->encoder);
-
     ctx->options = JxlEncoderFrameSettingsCreate(ctx->encoder, NULL);
     if (!ctx->options) {
         av_log(avctx, AV_LOG_ERROR, "Failed to create JxlEncoderOptions\n");
@@ -247,7 +245,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
     LibJxlEncodeContext *ctx = avctx->priv_data;
     AVFrameSideData *sd;
     const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(frame->format);
-    JxlBasicInfo info;
+    JxlBasicInfo *info = &ctx->info;
     JxlColorEncoding jxl_color;
     JxlPixelFormat jxl_fmt;
     int bits_per_sample;
@@ -260,6 +258,9 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
     size_t bytes_written = 0;
     uint8_t *next_out = ctx->buffer;
 
+    /* reset the encoder every frame for image2 muxer */
+    JxlEncoderReset(ctx->encoder);
+
     ret = libjxl_init_jxl_encoder(avctx);
     if (ret) {
         av_log(avctx, AV_LOG_ERROR, "Error frame-initializing JxlEncoder\n");
@@ -267,31 +268,31 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
     }
 
     /* populate the basic info settings */
-    JxlEncoderInitBasicInfo(&info);
+    JxlEncoderInitBasicInfo(info);
     jxl_fmt.num_channels = pix_desc->nb_components;
-    info.xsize = frame->width;
-    info.ysize = frame->height;
-    info.num_extra_channels = (jxl_fmt.num_channels + 1) % 2;
-    info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
+    info->xsize = frame->width;
+    info->ysize = frame->height;
+    info->num_extra_channels = (jxl_fmt.num_channels + 1) % 2;
+    info->num_color_channels = jxl_fmt.num_channels - info->num_extra_channels;
     bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt.num_channels;
-    info.bits_per_sample = avctx->bits_per_raw_sample > 0 && !(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT)
+    info->bits_per_sample = avctx->bits_per_raw_sample > 0 && !(pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT)
                            ? avctx->bits_per_raw_sample : bits_per_sample;
-    info.alpha_bits = (info.num_extra_channels > 0) * info.bits_per_sample;
+    info->alpha_bits = (info->num_extra_channels > 0) * info->bits_per_sample;
     if (pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
-        info.exponent_bits_per_sample = info.bits_per_sample > 16 ? 8 : 5;
-        info.alpha_exponent_bits = info.alpha_bits ? info.exponent_bits_per_sample : 0;
-        jxl_fmt.data_type = info.bits_per_sample > 16 ? JXL_TYPE_FLOAT : JXL_TYPE_FLOAT16;
+        info->exponent_bits_per_sample = info->bits_per_sample > 16 ? 8 : 5;
+        info->alpha_exponent_bits = info->alpha_bits ? info->exponent_bits_per_sample : 0;
+        jxl_fmt.data_type = info->bits_per_sample > 16 ? JXL_TYPE_FLOAT : JXL_TYPE_FLOAT16;
     } else {
-        info.exponent_bits_per_sample = 0;
-        info.alpha_exponent_bits = 0;
-        jxl_fmt.data_type = info.bits_per_sample <= 8 ? JXL_TYPE_UINT8 : JXL_TYPE_UINT16;
+        info->exponent_bits_per_sample = 0;
+        info->alpha_exponent_bits = 0;
+        jxl_fmt.data_type = info->bits_per_sample <= 8 ? JXL_TYPE_UINT8 : JXL_TYPE_UINT16;
     }
 
 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
     jxl_bit_depth.bits_per_sample = bits_per_sample;
     jxl_bit_depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
     jxl_bit_depth.exponent_bits_per_sample = pix_desc->flags & AV_PIX_FMT_FLAG_FLOAT ?
-                                             info.exponent_bits_per_sample : 0;
+                                             info->exponent_bits_per_sample : 0;
 #endif
 
     /* JPEG XL format itself does not support limited range */
@@ -302,9 +303,9 @@ 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;
 
-    if (JxlEncoderSetBasicInfo(ctx->encoder, &info) != JXL_ENC_SUCCESS) {
+    if (JxlEncoderSetBasicInfo(ctx->encoder, info) != JXL_ENC_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to set JxlBasicInfo\n");
         return AVERROR_EXTERNAL;
     }
@@ -353,7 +354,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
 
     /* This should be implied to be honest
      * but a libjxl bug makes it fail otherwise */
-    if (info.num_color_channels == 1)
+    if (info->num_color_channels == 1)
         jxl_color.color_space = JXL_COLOR_SPACE_GRAY;
     else
         jxl_color.color_space = JXL_COLOR_SPACE_RGB;
@@ -385,7 +386,7 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
     jxl_fmt.endianness = JXL_NATIVE_ENDIAN;
     jxl_fmt.align = frame->linesize[0];
 
-    if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, frame->data[0], jxl_fmt.align * info.ysize) != JXL_ENC_SUCCESS) {
+    if (JxlEncoderAddImageFrame(ctx->options, &jxl_fmt, frame->data[0], jxl_fmt.align * info->ysize) != JXL_ENC_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to add Image Frame\n");
         return AVERROR_EXTERNAL;
     }
-- 
2.43.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".

             reply	other threads:[~2023-12-11 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 17:05 Zsolt Vadász via ffmpeg-devel [this message]
2023-12-12 20:17 ` Leo Izen
2023-12-13 18:12   ` Zsolt Vadász via ffmpeg-devel

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='pS2jlZqMdQ_AGDQU10Aiw8gOViZGDn8qxhQ4I8EXeF7uzIsgtTnBtDDoZr2BMf82o349lMI0seVvZt_WgSR1DQPeCPMyTVIlxSoCvFoKOjw=@protonmail.com' \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=zsolt_vadasz@protonmail.com \
    /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