FFmpeg
libjxldec.c
Go to the documentation of this file.
1 /*
2  * JPEG XL decoding support via libjxl
3  * Copyright (c) 2021 Leo Izen <leo.izen@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * JPEG XL decoder using libjxl
25  */
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/buffer.h"
29 #include "libavutil/common.h"
30 #include "libavutil/csp.h"
31 #include "libavutil/error.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/frame.h"
36 
37 #include "avcodec.h"
38 #include "codec_internal.h"
39 #include "internal.h"
40 
41 #include <jxl/decode.h>
42 #include <jxl/thread_parallel_runner.h>
43 #include "libjxl.h"
44 
45 typedef struct LibJxlDecodeContext {
46  void *runner;
47  JxlDecoder *decoder;
48  JxlBasicInfo basic_info;
49  JxlPixelFormat jxl_pixfmt;
50  JxlDecoderStatus events;
53 
55 {
57 
58  ctx->events = JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE | JXL_DEC_COLOR_ENCODING;
59  if (JxlDecoderSubscribeEvents(ctx->decoder, ctx->events) != JXL_DEC_SUCCESS) {
60  av_log(avctx, AV_LOG_ERROR, "Error subscribing to JXL events\n");
61  return AVERROR_EXTERNAL;
62  }
63 
64  if (JxlDecoderSetParallelRunner(ctx->decoder, JxlThreadParallelRunner, ctx->runner) != JXL_DEC_SUCCESS) {
65  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n");
66  return AVERROR_EXTERNAL;
67  }
68 
69  memset(&ctx->basic_info, 0, sizeof(JxlBasicInfo));
70  memset(&ctx->jxl_pixfmt, 0, sizeof(JxlPixelFormat));
71 
72  return 0;
73 }
74 
76 {
78  JxlMemoryManager manager;
79 
81  ctx->decoder = JxlDecoderCreate(&manager);
82  if (!ctx->decoder) {
83  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlDecoder\n");
84  return AVERROR_EXTERNAL;
85  }
86 
87  ctx->runner = JxlThreadParallelRunnerCreate(&manager, ff_libjxl_get_threadcount(avctx->thread_count));
88  if (!ctx->runner) {
89  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlThreadParallelRunner\n");
90  return AVERROR_EXTERNAL;
91  }
92 
93  return libjxl_init_jxl_decoder(avctx);
94 }
95 
96 static enum AVPixelFormat libjxl_get_pix_fmt(void *avctx, const JxlBasicInfo *basic_info, JxlPixelFormat *format)
97 {
98  format->endianness = JXL_NATIVE_ENDIAN;
99  format->num_channels = basic_info->num_color_channels + (basic_info->alpha_bits > 0);
100  /* Gray */
101  if (basic_info->num_color_channels == 1) {
102  if (basic_info->bits_per_sample <= 8) {
103  format->data_type = JXL_TYPE_UINT8;
104  return basic_info->alpha_bits ? AV_PIX_FMT_YA8 : AV_PIX_FMT_GRAY8;
105  }
106  if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
107  if (basic_info->alpha_bits)
108  return AV_PIX_FMT_NONE;
109  format->data_type = JXL_TYPE_FLOAT;
110  return AV_PIX_FMT_GRAYF32;
111  }
112  format->data_type = JXL_TYPE_UINT16;
113  return basic_info->alpha_bits ? AV_PIX_FMT_YA16 : AV_PIX_FMT_GRAY16;
114  }
115  /* rgb only */
116  /* libjxl only supports packed RGB and gray output at the moment */
117  if (basic_info->num_color_channels == 3) {
118  if (basic_info->bits_per_sample <= 8) {
119  format->data_type = JXL_TYPE_UINT8;
120  return basic_info->alpha_bits ? AV_PIX_FMT_RGBA : AV_PIX_FMT_RGB24;
121  }
122  if (basic_info->bits_per_sample > 16)
123  av_log(avctx, AV_LOG_WARNING, "Downsampling larger integer to 16-bit via libjxl\n");
124  if (basic_info->exponent_bits_per_sample)
125  av_log(avctx, AV_LOG_WARNING, "Downsampling float to 16-bit integer via libjxl\n");
126  format->data_type = JXL_TYPE_UINT16;
127  return basic_info->alpha_bits ? AV_PIX_FMT_RGBA64 : AV_PIX_FMT_RGB48;
128  }
129 
130  return AV_PIX_FMT_NONE;
131 }
132 
133 static enum AVColorPrimaries libjxl_get_primaries(void *avctx, const JxlColorEncoding *jxl_color)
134 {
136  enum AVColorPrimaries prim;
137 
138  /* libjxl populates these double values even if it uses an enum space */
139  desc.prim.r.x = av_d2q(jxl_color->primaries_red_xy[0], 300000);
140  desc.prim.r.y = av_d2q(jxl_color->primaries_red_xy[1], 300000);
141  desc.prim.g.x = av_d2q(jxl_color->primaries_green_xy[0], 300000);
142  desc.prim.g.y = av_d2q(jxl_color->primaries_green_xy[1], 300000);
143  desc.prim.b.x = av_d2q(jxl_color->primaries_blue_xy[0], 300000);
144  desc.prim.b.y = av_d2q(jxl_color->primaries_blue_xy[1], 300000);
145  desc.wp.x = av_d2q(jxl_color->white_point_xy[0], 300000);
146  desc.wp.y = av_d2q(jxl_color->white_point_xy[1], 300000);
147 
149  if (prim == AVCOL_PRI_UNSPECIFIED) {
150  /* try D65 with the same primaries */
151  /* BT.709 uses D65 white point */
153  av_log(avctx, AV_LOG_WARNING, "Changing unknown white point to D65\n");
155  }
156 
157  return prim;
158 }
159 
160 static enum AVColorTransferCharacteristic libjxl_get_trc(void *avctx, const JxlColorEncoding *jxl_color)
161 {
162  switch (jxl_color->transfer_function) {
163  case JXL_TRANSFER_FUNCTION_709: return AVCOL_TRC_BT709;
164  case JXL_TRANSFER_FUNCTION_LINEAR: return AVCOL_TRC_LINEAR;
165  case JXL_TRANSFER_FUNCTION_SRGB: return AVCOL_TRC_IEC61966_2_1;
166  case JXL_TRANSFER_FUNCTION_PQ: return AVCOL_TRC_SMPTE2084;
167  case JXL_TRANSFER_FUNCTION_DCI: return AVCOL_TRC_SMPTE428;
168  case JXL_TRANSFER_FUNCTION_HLG: return AVCOL_TRC_ARIB_STD_B67;
169  case JXL_TRANSFER_FUNCTION_GAMMA:
170  if (jxl_color->gamma > 2.199 && jxl_color->gamma < 2.201)
171  return AVCOL_TRC_GAMMA22;
172  else if (jxl_color->gamma > 2.799 && jxl_color->gamma < 2.801)
173  return AVCOL_TRC_GAMMA28;
174  else
175  av_log(avctx, AV_LOG_WARNING, "Unsupported gamma transfer: %f\n", jxl_color->gamma);
176  break;
177  default:
178  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function: %d\n", jxl_color->transfer_function);
179  }
180 
181  return AVCOL_TRC_UNSPECIFIED;
182 }
183 
184 static int libjxl_get_icc(AVCodecContext *avctx)
185 {
187  size_t icc_len;
188  JxlDecoderStatus jret;
189  /* an ICC profile is present, and we can meaningfully get it,
190  * because the pixel data is not XYB-encoded */
191  jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &icc_len);
192  if (jret == JXL_DEC_SUCCESS && icc_len > 0) {
193  av_buffer_unref(&ctx->iccp);
194  ctx->iccp = av_buffer_alloc(icc_len);
195  if (!ctx->iccp)
196  return AVERROR(ENOMEM);
197  jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA,
198  ctx->iccp->data, icc_len);
199  if (jret != JXL_DEC_SUCCESS) {
200  av_log(avctx, AV_LOG_WARNING, "Unable to obtain ICC Profile\n");
201  av_buffer_unref(&ctx->iccp);
202  }
203  }
204 
205  return 0;
206 }
207 
208 /*
209  * There's generally four cases when it comes to decoding a libjxl image
210  * with regard to color encoding:
211  * (a) There is an embedded ICC profile in the image, and the image is XYB-encoded.
212  * (b) There is an embedded ICC profile in the image, and the image is not XYB-encoded.
213  * (c) There is no embedded ICC profile, and FFmpeg supports the tagged colorspace.
214  * (d) There is no embedded ICC profile, and FFmpeg does not support the tagged colorspace.
215  *
216  * In case (b), we forward the pixel data as is and forward the ICC Profile as-is.
217  * In case (c), we request the pixel data in the space it's tagged as,
218  * and tag the space accordingly.
219  * In case (a), libjxl does not support getting the pixel data in the space described by the ICC
220  * profile, so instead we request the pixel data in BT.2020/PQ as it is the widest
221  * space that FFmpeg supports.
222  * In case (d), we also request wide-gamut pixel data as a fallback since FFmpeg doesn't support
223  * the custom primaries tagged in the space.
224  */
226 {
228  JxlDecoderStatus jret;
229  int ret;
230  JxlColorEncoding jxl_color;
231  /* set this flag if we need to fall back on wide gamut */
232  int fallback = 0;
233 
234  jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, NULL, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &jxl_color);
235  if (jret == JXL_DEC_SUCCESS) {
236  /* enum values describe the colors of this image */
237  jret = JxlDecoderSetPreferredColorProfile(ctx->decoder, &jxl_color);
238  if (jret == JXL_DEC_SUCCESS)
239  jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &jxl_color);
240  /* if we couldn't successfully request the pixel data space, we fall back on wide gamut */
241  /* this code path is very unlikely to happen in practice */
242  if (jret != JXL_DEC_SUCCESS)
243  fallback = 1;
244  } else {
245  /* an ICC Profile is present in the stream */
246  if (ctx->basic_info.uses_original_profile) {
247  /* uses_original_profile is the same as !xyb_encoded */
248  av_log(avctx, AV_LOG_VERBOSE, "Using embedded ICC Profile\n");
249  if ((ret = libjxl_get_icc(avctx)) < 0)
250  return ret;
251  } else {
252  /*
253  * an XYB-encoded image with an embedded ICC profile can't always have the
254  * pixel data requested in the original space, so libjxl has no feature
255  * to allow this to happen, so we fall back on wide gamut
256  */
257  fallback = 1;
258  }
259  }
260 
261  avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
262  if (ctx->jxl_pixfmt.num_channels >= 3)
263  avctx->colorspace = AVCOL_SPC_RGB;
266 
267  if (!ctx->iccp) {
268  /* checking enum values */
269  if (!fallback) {
270  if (avctx->colorspace == AVCOL_SPC_RGB)
271  avctx->color_primaries = libjxl_get_primaries(avctx, &jxl_color);
272  avctx->color_trc = libjxl_get_trc(avctx, &jxl_color);
273  }
274  /* fall back on wide gamut if enum values fail */
275  if (avctx->color_primaries == AVCOL_PRI_UNSPECIFIED) {
276  if (avctx->colorspace == AVCOL_SPC_RGB) {
277  av_log(avctx, AV_LOG_WARNING, "Falling back on wide gamut output\n");
278  jxl_color.primaries = JXL_PRIMARIES_2100;
280  }
281  /* libjxl requires this set even for grayscale */
282  jxl_color.white_point = JXL_WHITE_POINT_D65;
283  }
284  if (avctx->color_trc == AVCOL_TRC_UNSPECIFIED) {
285  if (ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT
286  || ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT16) {
287  av_log(avctx, AV_LOG_WARNING, "Falling back on Linear Light transfer\n");
288  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
289  avctx->color_trc = AVCOL_TRC_LINEAR;
290  } else {
291  av_log(avctx, AV_LOG_WARNING, "Falling back on iec61966-2-1/sRGB transfer\n");
292  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
294  }
295  }
296  /* all colors will be in-gamut so we want accurate colors */
297  jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
298  jxl_color.color_space = avctx->colorspace == AVCOL_SPC_RGB ? JXL_COLOR_SPACE_RGB : JXL_COLOR_SPACE_GRAY;
299  jret = JxlDecoderSetPreferredColorProfile(ctx->decoder, &jxl_color);
300  if (jret != JXL_DEC_SUCCESS) {
301  av_log(avctx, AV_LOG_WARNING, "Unable to set fallback color encoding\n");
302  /*
303  * This should only happen if there's a non-XYB encoded image with custom primaries
304  * embedded as enums and no embedded ICC Profile.
305  * In this case, libjxl will synthesize an ICC Profile for us.
306  */
309  if ((ret = libjxl_get_icc(avctx)) < 0)
310  return ret;
311  }
312  }
313 
314  frame->color_trc = avctx->color_trc;
315  frame->color_primaries = avctx->color_primaries;
316  frame->colorspace = avctx->colorspace;
317 
318  return 0;
319 }
320 
321 static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
322 {
324  const uint8_t *buf = avpkt->data;
325  size_t remaining = avpkt->size;
326  JxlDecoderStatus jret;
327  int ret;
328  *got_frame = 0;
329 
330  while (1) {
331 
332  jret = JxlDecoderSetInput(ctx->decoder, buf, remaining);
333 
334  if (jret == JXL_DEC_ERROR) {
335  /* this should never happen here unless there's a bug in libjxl */
336  av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
337  return AVERROR_EXTERNAL;
338  }
339 
340  jret = JxlDecoderProcessInput(ctx->decoder);
341  /*
342  * JxlDecoderReleaseInput returns the number
343  * of bytes remaining to be read, rather than
344  * the number of bytes that it did read
345  */
346  remaining = JxlDecoderReleaseInput(ctx->decoder);
347  buf = avpkt->data + avpkt->size - remaining;
348 
349  switch(jret) {
350  case JXL_DEC_ERROR:
351  av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
352  return AVERROR_INVALIDDATA;
353  case JXL_DEC_NEED_MORE_INPUT:
354  if (remaining == 0) {
355  av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL codestream\n");
356  return AVERROR_INVALIDDATA;
357  }
358  av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
359  continue;
360  case JXL_DEC_BASIC_INFO:
361  av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");
362  if (JxlDecoderGetBasicInfo(ctx->decoder, &ctx->basic_info) != JXL_DEC_SUCCESS) {
363  /*
364  * this should never happen
365  * if it does it is likely a libjxl decoder bug
366  */
367  av_log(avctx, AV_LOG_ERROR, "Bad libjxl basic info event\n");
368  return AVERROR_EXTERNAL;
369  }
370  avctx->pix_fmt = libjxl_get_pix_fmt(avctx, &ctx->basic_info, &ctx->jxl_pixfmt);
371  if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
372  av_log(avctx, AV_LOG_ERROR, "Bad libjxl pixel format\n");
373  return AVERROR_EXTERNAL;
374  }
375  if ((ret = ff_set_dimensions(avctx, ctx->basic_info.xsize, ctx->basic_info.ysize)) < 0)
376  return ret;
377  continue;
378  case JXL_DEC_COLOR_ENCODING:
379  av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
380  if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0)
381  return ret;
382  continue;
383  case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
384  av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n");
385  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
386  return ret;
387  ctx->jxl_pixfmt.align = frame->linesize[0];
388  if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size)
389  != JXL_DEC_SUCCESS) {
390  av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n");
391  return AVERROR_EXTERNAL;
392  }
393  continue;
394  case JXL_DEC_FULL_IMAGE:
395  /* full image is one frame, even if animated */
396  av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
397  frame->pict_type = AV_PICTURE_TYPE_I;
398  frame->key_frame = 1;
399  if (ctx->iccp) {
401  if (!sd)
402  return AVERROR(ENOMEM);
403  /* ownership is transfered, and it is not ref-ed */
404  ctx->iccp = NULL;
405  }
406  *got_frame = 1;
407  return avpkt->size - remaining;
408  case JXL_DEC_SUCCESS:
409  av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");
410  /*
411  * The SUCCESS event isn't fired until after JXL_DEC_FULL_IMAGE. If this
412  * stream only contains one JXL image then JXL_DEC_SUCCESS will never fire.
413  * If the image2 sequence being decoded contains several JXL files, then
414  * libjxl will fire this event after the next AVPacket has been passed,
415  * which means the current packet is actually the next image in the sequence.
416  * This is why we reset the decoder and populate the packet data now, since
417  * this is the next packet and it has not been decoded yet. The decoder does
418  * have to be reset to allow us to use it for the next image, or libjxl
419  * will become very confused if the header information is not identical.
420  */
421  JxlDecoderReset(ctx->decoder);
423  buf = avpkt->data;
424  remaining = avpkt->size;
425  continue;
426  default:
427  av_log(avctx, AV_LOG_ERROR, "Bad libjxl event: %d\n", jret);
428  return AVERROR_EXTERNAL;
429  }
430  }
431 }
432 
434 {
436 
437  if (ctx->runner)
438  JxlThreadParallelRunnerDestroy(ctx->runner);
439  ctx->runner = NULL;
440  if (ctx->decoder)
441  JxlDecoderDestroy(ctx->decoder);
442  ctx->decoder = NULL;
443  av_buffer_unref(&ctx->iccp);
444 
445  return 0;
446 }
447 
449  .p.name = "libjxl",
450  .p.long_name = NULL_IF_CONFIG_SMALL("libjxl JPEG XL"),
451  .p.type = AVMEDIA_TYPE_VIDEO,
452  .p.id = AV_CODEC_ID_JPEGXL,
453  .priv_data_size = sizeof(LibJxlDecodeContext),
456  .close = libjxl_decode_close,
457  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS,
459  .p.wrapper_name = "libjxl",
460 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
libjxl_init_jxl_decoder
static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
Definition: libjxldec.c:54
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ff_libjxl_get_threadcount
size_t ff_libjxl_get_threadcount(int threads)
Transform threadcount in ffmpeg to one used by libjxl.
Definition: libjxl.c:33
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:39
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:133
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:966
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:496
AVColorPrimariesDesc::wp
AVWhitepointCoefficients wp
Definition: csp.h:70
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:69
LibJxlDecodeContext::decoder
JxlDecoder * decoder
Definition: libjxldec.c:47
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:505
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:959
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:599
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:499
libjxl_decode_init
static av_cold int libjxl_decode_init(AVCodecContext *avctx)
Definition: libjxldec.c:75
FFCodec
Definition: codec_internal.h:112
libjxl.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:526
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:471
init
static int init
Definition: av_tx.c:47
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:116
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:510
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1463
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:502
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:390
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:501
avassert.h
LibJxlDecodeContext::events
JxlDecoderStatus events
Definition: libjxldec.c:50
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:952
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:254
av_csp_primaries_desc_from_id
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
Definition: csp.c:85
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:127
ff_libjxl_decoder
const FFCodec ff_libjxl_decoder
Definition: libjxldec.c:448
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_csp_primaries_id_from_desc
enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm)
Detects which enum AVColorPrimaries constant corresponds to the given complete gamut description.
Definition: csp.c:105
libjxl_get_icc
static int libjxl_get_icc(AVCodecContext *avctx)
Definition: libjxldec.c:184
LibJxlDecodeContext::jxl_pixfmt
JxlPixelFormat jxl_pixfmt
Definition: libjxldec.c:49
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:438
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:474
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:396
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:973
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:473
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:640
libjxl_decode_frame
static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: libjxldec.c:321
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
error.h
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:482
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:513
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1403
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
codec_internal.h
LibJxlDecodeContext::iccp
AVBufferRef * iccp
Definition: libjxldec.c:51
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:392
frame.h
buffer.h
csp.h
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
libjxl_get_primaries
static enum AVColorPrimaries libjxl_get_primaries(void *avctx, const JxlColorEncoding *jxl_color)
Definition: libjxldec.c:133
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:498
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:391
common.h
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:312
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:599
avcodec.h
ret
ret
Definition: filter_design.txt:187
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:389
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:517
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:90
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:70
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:231
LibJxlDecodeContext::runner
void * runner
Definition: libjxldec.c:46
libjxl_decode_close
static av_cold int libjxl_decode_close(AVCodecContext *avctx)
Definition: libjxldec.c:433
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:416
LibJxlDecodeContext
Definition: libjxldec.c:45
ff_libjxl_init_memory_manager
void ff_libjxl_init_memory_manager(JxlMemoryManager *manager)
Initialize and populate a JxlMemoryManager with av_malloc() and av_free() so libjxl will use these fu...
Definition: libjxl.c:65
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:515
libjxl_get_pix_fmt
static enum AVPixelFormat libjxl_get_pix_fmt(void *avctx, const JxlBasicInfo *basic_info, JxlPixelFormat *format)
Definition: libjxldec.c:96
LibJxlDecodeContext::basic_info
JxlBasicInfo basic_info
Definition: libjxldec.c:48
libjxl_get_trc
static enum AVColorTransferCharacteristic libjxl_get_trc(void *avctx, const JxlColorEncoding *jxl_color)
Definition: libjxldec.c:160
libjxl_color_encoding_event
static int libjxl_color_encoding_event(AVCodecContext *avctx, AVFrame *frame)
Definition: libjxldec.c:225