Go to the documentation of this file.
44 #include <jxl/decode.h>
45 #include <jxl/thread_parallel_runner.h>
53 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
72 ctx->events = JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE
73 | JXL_DEC_COLOR_ENCODING | JXL_DEC_FRAME
74 | JXL_DEC_BOX | JXL_DEC_BOX_COMPLETE;
75 if (JxlDecoderSubscribeEvents(
ctx->decoder,
ctx->events) != JXL_DEC_SUCCESS) {
80 if (JxlDecoderSetDecompressBoxes(
ctx->decoder, JXL_TRUE) != JXL_DEC_SUCCESS) {
85 if (JxlDecoderSetParallelRunner(
ctx->decoder, JxlThreadParallelRunner,
ctx->runner) != JXL_DEC_SUCCESS) {
91 memset(&
ctx->basic_info, 0,
sizeof(JxlBasicInfo));
92 memset(&
ctx->jxl_pixfmt, 0,
sizeof(JxlPixelFormat));
93 ctx->prev_is_last = 1;
101 JxlMemoryManager manager;
104 ctx->decoder = JxlDecoderCreate(&manager);
126 const JxlBasicInfo *basic_info = &
ctx->basic_info;
127 JxlPixelFormat *
format = &
ctx->jxl_pixfmt;
128 format->endianness = JXL_NATIVE_ENDIAN;
129 format->num_channels = basic_info->num_color_channels + (basic_info->alpha_bits > 0);
130 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
132 ctx->jxl_bit_depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
133 ctx->jxl_bit_depth.exponent_bits_per_sample = basic_info->exponent_bits_per_sample;
136 if (basic_info->num_color_channels == 1) {
137 if (basic_info->bits_per_sample <= 8) {
138 format->data_type = JXL_TYPE_UINT8;
141 if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
142 if (!basic_info->alpha_bits) {
143 format->data_type = JXL_TYPE_FLOAT;
148 format->data_type = JXL_TYPE_UINT16;
153 if (basic_info->num_color_channels == 3) {
154 if (basic_info->bits_per_sample <= 8) {
155 format->data_type = JXL_TYPE_UINT8;
158 if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
159 format->data_type = JXL_TYPE_FLOAT;
162 format->data_type = JXL_TYPE_UINT16;
175 desc.prim.r.x =
av_d2q(jxl_color->primaries_red_xy[0], 300000);
176 desc.prim.r.y =
av_d2q(jxl_color->primaries_red_xy[1], 300000);
177 desc.prim.g.x =
av_d2q(jxl_color->primaries_green_xy[0], 300000);
178 desc.prim.g.y =
av_d2q(jxl_color->primaries_green_xy[1], 300000);
179 desc.prim.b.x =
av_d2q(jxl_color->primaries_blue_xy[0], 300000);
180 desc.prim.b.y =
av_d2q(jxl_color->primaries_blue_xy[1], 300000);
181 desc.wp.x =
av_d2q(jxl_color->white_point_xy[0], 300000);
182 desc.wp.y =
av_d2q(jxl_color->white_point_xy[1], 300000);
198 switch (jxl_color->transfer_function) {
205 case JXL_TRANSFER_FUNCTION_GAMMA:
206 if (jxl_color->gamma > 0.45355 && jxl_color->gamma < 0.45555)
208 else if (jxl_color->gamma > 0.35614 && jxl_color->gamma < 0.35814)
224 JxlDecoderStatus jret;
227 #if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
228 jret = JxlDecoderGetICCProfileSize(
ctx->decoder, &
ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &icc_len);
230 jret = JxlDecoderGetICCProfileSize(
ctx->decoder, JXL_COLOR_PROFILE_TARGET_DATA, &icc_len);
232 if (jret == JXL_DEC_SUCCESS && icc_len > 0) {
237 #if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
238 jret = JxlDecoderGetColorAsICCProfile(
ctx->decoder, &
ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA,
239 ctx->iccp->data, icc_len);
241 jret = JxlDecoderGetColorAsICCProfile(
ctx->decoder, JXL_COLOR_PROFILE_TARGET_DATA,
ctx->iccp->data, icc_len);
243 if (jret != JXL_DEC_SUCCESS) {
272 JxlDecoderStatus jret;
274 JxlColorEncoding jxl_color;
278 #if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
279 jret = JxlDecoderGetColorAsEncodedProfile(
ctx->decoder,
NULL, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &jxl_color);
281 jret = JxlDecoderGetColorAsEncodedProfile(
ctx->decoder, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &jxl_color);
283 if (jret == JXL_DEC_SUCCESS) {
285 jret = JxlDecoderSetPreferredColorProfile(
ctx->decoder, &jxl_color);
286 if (jret == JXL_DEC_SUCCESS)
287 #if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
288 jret = JxlDecoderGetColorAsEncodedProfile(
ctx->decoder, &
ctx->jxl_pixfmt,
289 JXL_COLOR_PROFILE_TARGET_DATA, &jxl_color);
291 jret = JxlDecoderGetColorAsEncodedProfile(
ctx->decoder, JXL_COLOR_PROFILE_TARGET_DATA, &jxl_color);
295 if (jret != JXL_DEC_SUCCESS)
299 if (
ctx->basic_info.uses_original_profile) {
315 if (
ctx->basic_info.num_color_channels > 1)
331 jxl_color.primaries = JXL_PRIMARIES_2100;
335 jxl_color.white_point = JXL_WHITE_POINT_D65;
338 if (
ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT
339 ||
ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT16) {
341 jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
345 jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
350 jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
351 jxl_color.color_space =
ctx->basic_info.num_color_channels > 1 ? JXL_COLOR_SPACE_RGB : JXL_COLOR_SPACE_GRAY;
352 jret = JxlDecoderSetPreferredColorProfile(
ctx->decoder, &jxl_color);
353 if (jret != JXL_DEC_SUCCESS) {
377 JxlDecoderStatus jret = JXL_DEC_SUCCESS;
390 ctx->accumulated_pts = 0;
391 ctx->frame_duration = 0;
394 if (jret == JXL_DEC_NEED_MORE_INPUT) {
404 if (jret == JXL_DEC_ERROR) {
410 jret = JxlDecoderProcessInput(
ctx->decoder);
416 remaining = JxlDecoderReleaseInput(
ctx->decoder);
424 case JXL_DEC_NEED_MORE_INPUT:
427 case JXL_DEC_BASIC_INFO:
429 if (JxlDecoderGetBasicInfo(
ctx->decoder, &
ctx->basic_info) != JXL_DEC_SUCCESS) {
444 if (
ctx->basic_info.have_animation)
445 ctx->anim_timebase =
av_make_q(
ctx->basic_info.animation.tps_denominator,
446 ctx->basic_info.animation.tps_numerator);
448 case JXL_DEC_COLOR_ENCODING:
454 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
459 ctx->jxl_pixfmt.align =
ctx->frame->linesize[0];
460 if (JxlDecoderSetImageOutBuffer(
ctx->decoder, &
ctx->jxl_pixfmt,
461 ctx->frame->data[0],
ctx->frame->buf[0]->size)
462 != JXL_DEC_SUCCESS) {
466 #if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 8, 0)
467 if (JxlDecoderSetImageOutBitDepth(
ctx->decoder, &
ctx->jxl_bit_depth) != JXL_DEC_SUCCESS) {
476 if (
ctx->prev_is_last) {
484 if (JxlDecoderGetFrameHeader(
ctx->decoder, &
header) != JXL_DEC_SUCCESS) {
490 if (
ctx->basic_info.have_animation &&
header.duration)
493 case JXL_DEC_FULL_IMAGE:
524 if (
ctx->basic_info.have_animation) {
533 ctx->accumulated_pts +=
ctx->frame_duration;
537 case JXL_DEC_SUCCESS:
545 JxlDecoderReset(
ctx->decoder);
551 if (JxlDecoderGetBoxType(
ctx->decoder,
type, JXL_TRUE) != JXL_DEC_SUCCESS) {
563 if (JxlDecoderSetBoxBuffer(
ctx->decoder,
ctx->exif->data,
ctx->exif->size) != JXL_DEC_SUCCESS) {
569 case JXL_DEC_BOX_NEED_MORE_OUTPUT: {
571 size_t remainder = JxlDecoderReleaseBoxBuffer(
ctx->decoder);
572 ctx->exif_pos =
ctx->exif->size - remainder;
573 size_t new_size =
ctx->exif->size << 1;
577 if (JxlDecoderSetBoxBuffer(
ctx->decoder,
ctx->exif->data +
ctx->exif_pos,
578 ctx->exif->size -
ctx->exif_pos) != JXL_DEC_SUCCESS) {
584 case JXL_DEC_BOX_COMPLETE: {
586 size_t remainder = JxlDecoderReleaseBoxBuffer(
ctx->decoder);
587 ctx->exif_pos =
ctx->exif->size - remainder;
602 JxlThreadParallelRunnerDestroy(
ctx->runner);
605 JxlDecoderDestroy(
ctx->decoder);
627 .p.wrapper_name =
"libjxl",
631 .
p.
name =
"libjxl_anim",
643 .p.wrapper_name =
"libjxl",
@ AV_EXIF_T_OFF
The first four bytes point to the actual start, then it's AV_EXIF_TIFF_HEADER.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
AVPixelFormat
Pixel format.
@ AV_CODEC_ID_JPEGXL_ANIM
size_t ff_libjxl_get_threadcount(int threads)
Transform threadcount in ffmpeg to one used by libjxl.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
8 bits gray, 8 bits alpha
int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size, AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
enum AVColorSpace colorspace
YUV colorspace type.
AVColorTransferCharacteristic
Color Transfer Characteristic.
AVWhitepointCoefficients wp
Struct that contains both white point location and primaries location, providing the complete descrip...
#define AVERROR_EOF
End of file.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
static av_cold int libjxl_decode_init(AVCodecContext *avctx)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define AV_LOG_VERBOSE
Detailed information.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
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.
AVCodec p
The public AVCodec.
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
static enum AVPixelFormat libjxl_get_pix_fmt(AVCodecContext *avctx, LibJxlDecodeContext *ctx)
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_PIX_FMT_GRAY16
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
int flags
Flags modifying the (de)muxer behaviour.
JxlBitDepth jxl_bit_depth
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
const FFCodec ff_libjxl_decoder
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm)
Detects which enum AVColorPrimaries constant corresponds to the given complete gamut description.
static int libjxl_get_icc(AVCodecContext *avctx)
#define AV_PIX_FMT_RGBF32
JxlPixelFormat jxl_pixfmt
#define AV_PIX_FMT_GRAYF32
#define CODEC_LONG_NAME(str)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_RGBA64
int32_t av_exif_get_tag_id(const char *name)
Retrieves the tag ID associated with the provided tag string name.
int ff_decode_exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd)
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
struct AVCodecInternal * internal
Private context used for internal data.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AV_PICTURE_TYPE_I
Intra.
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int av_exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags)
Remove an entry from the provided EXIF metadata struct.
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const uint8_t header[24]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
static enum AVColorPrimaries libjxl_get_primaries(void *avctx, const JxlColorEncoding *jxl_color)
@ AVCOL_TRC_BT709
also ITU-R BT1361
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
main external API structure.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
#define FF_CODEC_RECEIVE_FRAME_CB(func)
#define AV_PIX_FMT_RGBAF32
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
A reference to a data buffer.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
static av_cold int libjxl_decode_close(AVCodecContext *avctx)
This structure stores compressed data.
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...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
#define MKTAG(a, b, c, d)
const FFCodec ff_libjxl_anim_decoder
static enum AVColorTransferCharacteristic libjxl_get_trc(void *avctx, const JxlColorEncoding *jxl_color)
static int libjxl_color_encoding_event(AVCodecContext *avctx, AVFrame *frame)