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 "decode.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  JxlBitDepth jxl_bit_depth;
51  JxlDecoderStatus events;
54 
56 {
58 
59  ctx->events = JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE | JXL_DEC_COLOR_ENCODING;
60  if (JxlDecoderSubscribeEvents(ctx->decoder, ctx->events) != JXL_DEC_SUCCESS) {
61  av_log(avctx, AV_LOG_ERROR, "Error subscribing to JXL events\n");
62  return AVERROR_EXTERNAL;
63  }
64 
65  if (JxlDecoderSetParallelRunner(ctx->decoder, JxlThreadParallelRunner, ctx->runner) != JXL_DEC_SUCCESS) {
66  av_log(avctx, AV_LOG_ERROR, "Failed to set JxlThreadParallelRunner\n");
67  return AVERROR_EXTERNAL;
68  }
69 
70  memset(&ctx->basic_info, 0, sizeof(JxlBasicInfo));
71  memset(&ctx->jxl_pixfmt, 0, sizeof(JxlPixelFormat));
72 
73  return 0;
74 }
75 
77 {
79  JxlMemoryManager manager;
80 
82  ctx->decoder = JxlDecoderCreate(&manager);
83  if (!ctx->decoder) {
84  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlDecoder\n");
85  return AVERROR_EXTERNAL;
86  }
87 
88  ctx->runner = JxlThreadParallelRunnerCreate(&manager, ff_libjxl_get_threadcount(avctx->thread_count));
89  if (!ctx->runner) {
90  av_log(avctx, AV_LOG_ERROR, "Failed to create JxlThreadParallelRunner\n");
91  return AVERROR_EXTERNAL;
92  }
93 
94  return libjxl_init_jxl_decoder(avctx);
95 }
96 
97 static enum AVPixelFormat libjxl_get_pix_fmt(AVCodecContext *avctx, const JxlBasicInfo *basic_info,
98  JxlPixelFormat *format, JxlBitDepth *depth)
99 {
100  format->endianness = JXL_NATIVE_ENDIAN;
101  format->num_channels = basic_info->num_color_channels + (basic_info->alpha_bits > 0);
102  depth->bits_per_sample = avctx->bits_per_raw_sample = basic_info->bits_per_sample;
103  depth->type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
104  depth->exponent_bits_per_sample = basic_info->exponent_bits_per_sample;
105  /* Gray */
106  if (basic_info->num_color_channels == 1) {
107  if (basic_info->bits_per_sample <= 8) {
108  format->data_type = JXL_TYPE_UINT8;
109  return basic_info->alpha_bits ? AV_PIX_FMT_YA8 : AV_PIX_FMT_GRAY8;
110  }
111  if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
112  if (basic_info->alpha_bits)
113  return AV_PIX_FMT_NONE;
114  format->data_type = JXL_TYPE_FLOAT;
115  return AV_PIX_FMT_GRAYF32;
116  }
117  format->data_type = JXL_TYPE_UINT16;
118  return basic_info->alpha_bits ? AV_PIX_FMT_YA16 : AV_PIX_FMT_GRAY16;
119  }
120  /* rgb only */
121  /* libjxl only supports packed RGB and gray output at the moment */
122  if (basic_info->num_color_channels == 3) {
123  if (basic_info->bits_per_sample <= 8) {
124  format->data_type = JXL_TYPE_UINT8;
125  return basic_info->alpha_bits ? AV_PIX_FMT_RGBA : AV_PIX_FMT_RGB24;
126  }
127  if (basic_info->exponent_bits_per_sample)
128  av_log(avctx, AV_LOG_WARNING, "Downsampling float to 16-bit integer via libjxl\n");
129  else if (basic_info->bits_per_sample > 16)
130  av_log(avctx, AV_LOG_WARNING, "Downsampling larger integer to 16-bit via libjxl\n");
131  format->data_type = JXL_TYPE_UINT16;
132  return basic_info->alpha_bits ? AV_PIX_FMT_RGBA64 : AV_PIX_FMT_RGB48;
133  }
134 
135  return AV_PIX_FMT_NONE;
136 }
137 
138 static enum AVColorPrimaries libjxl_get_primaries(void *avctx, const JxlColorEncoding *jxl_color)
139 {
141  enum AVColorPrimaries prim;
142 
143  /* libjxl populates these double values even if it uses an enum space */
144  desc.prim.r.x = av_d2q(jxl_color->primaries_red_xy[0], 300000);
145  desc.prim.r.y = av_d2q(jxl_color->primaries_red_xy[1], 300000);
146  desc.prim.g.x = av_d2q(jxl_color->primaries_green_xy[0], 300000);
147  desc.prim.g.y = av_d2q(jxl_color->primaries_green_xy[1], 300000);
148  desc.prim.b.x = av_d2q(jxl_color->primaries_blue_xy[0], 300000);
149  desc.prim.b.y = av_d2q(jxl_color->primaries_blue_xy[1], 300000);
150  desc.wp.x = av_d2q(jxl_color->white_point_xy[0], 300000);
151  desc.wp.y = av_d2q(jxl_color->white_point_xy[1], 300000);
152 
154  if (prim == AVCOL_PRI_UNSPECIFIED) {
155  /* try D65 with the same primaries */
156  /* BT.709 uses D65 white point */
158  av_log(avctx, AV_LOG_WARNING, "Changing unknown white point to D65\n");
160  }
161 
162  return prim;
163 }
164 
165 static enum AVColorTransferCharacteristic libjxl_get_trc(void *avctx, const JxlColorEncoding *jxl_color)
166 {
167  switch (jxl_color->transfer_function) {
168  case JXL_TRANSFER_FUNCTION_709: return AVCOL_TRC_BT709;
169  case JXL_TRANSFER_FUNCTION_LINEAR: return AVCOL_TRC_LINEAR;
170  case JXL_TRANSFER_FUNCTION_SRGB: return AVCOL_TRC_IEC61966_2_1;
171  case JXL_TRANSFER_FUNCTION_PQ: return AVCOL_TRC_SMPTE2084;
172  case JXL_TRANSFER_FUNCTION_DCI: return AVCOL_TRC_SMPTE428;
173  case JXL_TRANSFER_FUNCTION_HLG: return AVCOL_TRC_ARIB_STD_B67;
174  case JXL_TRANSFER_FUNCTION_GAMMA:
175  if (jxl_color->gamma > 0.45355 && jxl_color->gamma < 0.45555)
176  return AVCOL_TRC_GAMMA22;
177  else if (jxl_color->gamma > 0.35614 && jxl_color->gamma < 0.35814)
178  return AVCOL_TRC_GAMMA28;
179  else
180  av_log(avctx, AV_LOG_WARNING, "Unsupported gamma transfer: %f\n", jxl_color->gamma);
181  break;
182  default:
183  av_log(avctx, AV_LOG_WARNING, "Unknown transfer function: %d\n", jxl_color->transfer_function);
184  }
185 
186  return AVCOL_TRC_UNSPECIFIED;
187 }
188 
189 static int libjxl_get_icc(AVCodecContext *avctx)
190 {
192  size_t icc_len;
193  JxlDecoderStatus jret;
194  /* an ICC profile is present, and we can meaningfully get it,
195  * because the pixel data is not XYB-encoded */
196  jret = JxlDecoderGetICCProfileSize(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &icc_len);
197  if (jret == JXL_DEC_SUCCESS && icc_len > 0) {
198  av_buffer_unref(&ctx->iccp);
199  ctx->iccp = av_buffer_alloc(icc_len);
200  if (!ctx->iccp)
201  return AVERROR(ENOMEM);
202  jret = JxlDecoderGetColorAsICCProfile(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA,
203  ctx->iccp->data, icc_len);
204  if (jret != JXL_DEC_SUCCESS) {
205  av_log(avctx, AV_LOG_WARNING, "Unable to obtain ICC Profile\n");
206  av_buffer_unref(&ctx->iccp);
207  }
208  }
209 
210  return 0;
211 }
212 
213 /*
214  * There's generally four cases when it comes to decoding a libjxl image
215  * with regard to color encoding:
216  * (a) There is an embedded ICC profile in the image, and the image is XYB-encoded.
217  * (b) There is an embedded ICC profile in the image, and the image is not XYB-encoded.
218  * (c) There is no embedded ICC profile, and FFmpeg supports the tagged colorspace.
219  * (d) There is no embedded ICC profile, and FFmpeg does not support the tagged colorspace.
220  *
221  * In case (b), we forward the pixel data as is and forward the ICC Profile as-is.
222  * In case (c), we request the pixel data in the space it's tagged as,
223  * and tag the space accordingly.
224  * In case (a), libjxl does not support getting the pixel data in the space described by the ICC
225  * profile, so instead we request the pixel data in BT.2020/PQ as it is the widest
226  * space that FFmpeg supports.
227  * In case (d), we also request wide-gamut pixel data as a fallback since FFmpeg doesn't support
228  * the custom primaries tagged in the space.
229  */
231 {
233  JxlDecoderStatus jret;
234  int ret;
235  JxlColorEncoding jxl_color;
236  /* set this flag if we need to fall back on wide gamut */
237  int fallback = 0;
238 
239  jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, NULL, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &jxl_color);
240  if (jret == JXL_DEC_SUCCESS) {
241  /* enum values describe the colors of this image */
242  jret = JxlDecoderSetPreferredColorProfile(ctx->decoder, &jxl_color);
243  if (jret == JXL_DEC_SUCCESS)
244  jret = JxlDecoderGetColorAsEncodedProfile(ctx->decoder, &ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &jxl_color);
245  /* if we couldn't successfully request the pixel data space, we fall back on wide gamut */
246  /* this code path is very unlikely to happen in practice */
247  if (jret != JXL_DEC_SUCCESS)
248  fallback = 1;
249  } else {
250  /* an ICC Profile is present in the stream */
251  if (ctx->basic_info.uses_original_profile) {
252  /* uses_original_profile is the same as !xyb_encoded */
253  av_log(avctx, AV_LOG_VERBOSE, "Using embedded ICC Profile\n");
254  if ((ret = libjxl_get_icc(avctx)) < 0)
255  return ret;
256  } else {
257  /*
258  * an XYB-encoded image with an embedded ICC profile can't always have the
259  * pixel data requested in the original space, so libjxl has no feature
260  * to allow this to happen, so we fall back on wide gamut
261  */
262  fallback = 1;
263  }
264  }
265 
266  avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
267  if (ctx->jxl_pixfmt.num_channels >= 3)
268  avctx->colorspace = AVCOL_SPC_RGB;
271 
272  if (!ctx->iccp) {
273  /* checking enum values */
274  if (!fallback) {
275  if (avctx->colorspace == AVCOL_SPC_RGB)
276  avctx->color_primaries = libjxl_get_primaries(avctx, &jxl_color);
277  avctx->color_trc = libjxl_get_trc(avctx, &jxl_color);
278  }
279  /* fall back on wide gamut if enum values fail */
280  if (avctx->color_primaries == AVCOL_PRI_UNSPECIFIED) {
281  if (avctx->colorspace == AVCOL_SPC_RGB) {
282  av_log(avctx, AV_LOG_WARNING, "Falling back on wide gamut output\n");
283  jxl_color.primaries = JXL_PRIMARIES_2100;
285  }
286  /* libjxl requires this set even for grayscale */
287  jxl_color.white_point = JXL_WHITE_POINT_D65;
288  }
289  if (avctx->color_trc == AVCOL_TRC_UNSPECIFIED) {
290  if (ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT
291  || ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT16) {
292  av_log(avctx, AV_LOG_WARNING, "Falling back on Linear Light transfer\n");
293  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
294  avctx->color_trc = AVCOL_TRC_LINEAR;
295  } else {
296  av_log(avctx, AV_LOG_WARNING, "Falling back on iec61966-2-1/sRGB transfer\n");
297  jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
299  }
300  }
301  /* all colors will be in-gamut so we want accurate colors */
302  jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
303  jxl_color.color_space = avctx->colorspace == AVCOL_SPC_RGB ? JXL_COLOR_SPACE_RGB : JXL_COLOR_SPACE_GRAY;
304  jret = JxlDecoderSetPreferredColorProfile(ctx->decoder, &jxl_color);
305  if (jret != JXL_DEC_SUCCESS) {
306  av_log(avctx, AV_LOG_WARNING, "Unable to set fallback color encoding\n");
307  /*
308  * This should only happen if there's a non-XYB encoded image with custom primaries
309  * embedded as enums and no embedded ICC Profile.
310  * In this case, libjxl will synthesize an ICC Profile for us.
311  */
314  if ((ret = libjxl_get_icc(avctx)) < 0)
315  return ret;
316  }
317  }
318 
319  frame->color_trc = avctx->color_trc;
320  frame->color_primaries = avctx->color_primaries;
321  frame->colorspace = avctx->colorspace;
322 
323  return 0;
324 }
325 
326 static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
327 {
329  const uint8_t *buf = avpkt->data;
330  size_t remaining = avpkt->size;
331  JxlDecoderStatus jret;
332  int ret;
333  *got_frame = 0;
334 
335  while (1) {
336 
337  jret = JxlDecoderSetInput(ctx->decoder, buf, remaining);
338 
339  if (jret == JXL_DEC_ERROR) {
340  /* this should never happen here unless there's a bug in libjxl */
341  av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
342  return AVERROR_EXTERNAL;
343  }
344 
345  jret = JxlDecoderProcessInput(ctx->decoder);
346  /*
347  * JxlDecoderReleaseInput returns the number
348  * of bytes remaining to be read, rather than
349  * the number of bytes that it did read
350  */
351  remaining = JxlDecoderReleaseInput(ctx->decoder);
352  buf = avpkt->data + avpkt->size - remaining;
353 
354  switch(jret) {
355  case JXL_DEC_ERROR:
356  av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
357  return AVERROR_INVALIDDATA;
358  case JXL_DEC_NEED_MORE_INPUT:
359  if (remaining == 0) {
360  av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL codestream\n");
361  return AVERROR_INVALIDDATA;
362  }
363  av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
364  continue;
365  case JXL_DEC_BASIC_INFO:
366  av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");
367  if (JxlDecoderGetBasicInfo(ctx->decoder, &ctx->basic_info) != JXL_DEC_SUCCESS) {
368  /*
369  * this should never happen
370  * if it does it is likely a libjxl decoder bug
371  */
372  av_log(avctx, AV_LOG_ERROR, "Bad libjxl basic info event\n");
373  return AVERROR_EXTERNAL;
374  }
375  avctx->pix_fmt = libjxl_get_pix_fmt(avctx, &ctx->basic_info, &ctx->jxl_pixfmt, &ctx->jxl_bit_depth);
376  if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
377  av_log(avctx, AV_LOG_ERROR, "Bad libjxl pixel format\n");
378  return AVERROR_EXTERNAL;
379  }
380  if ((ret = ff_set_dimensions(avctx, ctx->basic_info.xsize, ctx->basic_info.ysize)) < 0)
381  return ret;
382  continue;
383  case JXL_DEC_COLOR_ENCODING:
384  av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
385  if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0)
386  return ret;
387  continue;
388  case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
389  av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n");
390  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
391  return ret;
392  ctx->jxl_pixfmt.align = frame->linesize[0];
393  if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size)
394  != JXL_DEC_SUCCESS) {
395  av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n");
396  return AVERROR_EXTERNAL;
397  }
398  if (JxlDecoderSetImageOutBitDepth(ctx->decoder, &ctx->jxl_bit_depth) != JXL_DEC_SUCCESS) {
399  av_log(avctx, AV_LOG_ERROR, "Error setting output bit depth\n");
400  return AVERROR_EXTERNAL;
401  }
402  continue;
403  case JXL_DEC_FULL_IMAGE:
404  /* full image is one frame, even if animated */
405  av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
406  frame->pict_type = AV_PICTURE_TYPE_I;
407  frame->key_frame = 1;
408  if (ctx->iccp) {
410  if (!sd)
411  return AVERROR(ENOMEM);
412  /* ownership is transfered, and it is not ref-ed */
413  ctx->iccp = NULL;
414  }
415  *got_frame = 1;
416  return avpkt->size - remaining;
417  case JXL_DEC_SUCCESS:
418  av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");
419  /*
420  * The SUCCESS event isn't fired until after JXL_DEC_FULL_IMAGE. If this
421  * stream only contains one JXL image then JXL_DEC_SUCCESS will never fire.
422  * If the image2 sequence being decoded contains several JXL files, then
423  * libjxl will fire this event after the next AVPacket has been passed,
424  * which means the current packet is actually the next image in the sequence.
425  * This is why we reset the decoder and populate the packet data now, since
426  * this is the next packet and it has not been decoded yet. The decoder does
427  * have to be reset to allow us to use it for the next image, or libjxl
428  * will become very confused if the header information is not identical.
429  */
430  JxlDecoderReset(ctx->decoder);
432  buf = avpkt->data;
433  remaining = avpkt->size;
434  continue;
435  default:
436  av_log(avctx, AV_LOG_ERROR, "Bad libjxl event: %d\n", jret);
437  return AVERROR_EXTERNAL;
438  }
439  }
440 }
441 
443 {
445 
446  if (ctx->runner)
447  JxlThreadParallelRunnerDestroy(ctx->runner);
448  ctx->runner = NULL;
449  if (ctx->decoder)
450  JxlDecoderDestroy(ctx->decoder);
451  ctx->decoder = NULL;
452  av_buffer_unref(&ctx->iccp);
453 
454  return 0;
455 }
456 
458  .p.name = "libjxl",
459  CODEC_LONG_NAME("libjxl JPEG XL"),
460  .p.type = AVMEDIA_TYPE_VIDEO,
461  .p.id = AV_CODEC_ID_JPEGXL,
462  .priv_data_size = sizeof(LibJxlDecodeContext),
465  .close = libjxl_decode_close,
466  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS,
467  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
470  .p.wrapper_name = "libjxl",
471 };
libjxl_get_pix_fmt
static enum AVPixelFormat libjxl_get_pix_fmt(AVCodecContext *avctx, const JxlBasicInfo *basic_info, JxlPixelFormat *format, JxlBitDepth *depth)
Definition: libjxldec.c:97
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:55
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:42
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:1017
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:558
AVColorPrimariesDesc::wp
AVWhitepointCoefficients wp
Definition: csp.h:75
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:74
LibJxlDecodeContext::decoder
JxlDecoder * decoder
Definition: libjxldec.c:47
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:567
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1010
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:661
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
libjxl_decode_init
static av_cold int libjxl_decode_init(AVCodecContext *avctx)
Definition: libjxldec.c:76
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
FFCodec
Definition: codec_internal.h:127
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:588
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:533
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:91
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:572
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1513
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:564
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:443
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:563
avassert.h
LibJxlDecodeContext::events
JxlDecoderStatus events
Definition: libjxldec.c:51
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1003
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:306
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
LibJxlDecodeContext::jxl_bit_depth
JxlBitDepth jxl_bit_depth
Definition: libjxldec.c:50
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
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
ff_libjxl_decoder
const FFCodec ff_libjxl_decoder
Definition: libjxldec.c:457
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1498
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
decode.h
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:189
LibJxlDecodeContext::jxl_pixfmt
JxlPixelFormat jxl_pixfmt
Definition: libjxldec.c:49
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:491
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:536
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
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:449
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1024
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:535
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:651
libjxl_decode_frame
static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: libjxldec.c:326
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:544
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:575
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1473
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
codec_internal.h
LibJxlDecodeContext::iccp
AVBufferRef * iccp
Definition: libjxldec.c:52
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:445
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:138
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:560
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:444
common.h
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:316
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:211
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:650
FF_CODEC_CAP_ICC_PROFILES
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
Definition: codec_internal.h:82
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:440
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:579
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
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:73
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:236
LibJxlDecodeContext::runner
void * runner
Definition: libjxldec.c:46
libjxl_decode_close
static av_cold int libjxl_decode_close(AVCodecContext *avctx)
Definition: libjxldec.c:442
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:467
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:577
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:165
libjxl_color_encoding_event
static int libjxl_color_encoding_event(AVCodecContext *avctx, AVFrame *frame)
Definition: libjxldec.c:230