Go to the documentation of this file.
41 #include <jxl/decode.h>
42 #include <jxl/thread_parallel_runner.h>
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) {
64 if (JxlDecoderSetParallelRunner(
ctx->decoder, JxlThreadParallelRunner,
ctx->runner) != JXL_DEC_SUCCESS) {
69 memset(&
ctx->basic_info, 0,
sizeof(JxlBasicInfo));
70 memset(&
ctx->jxl_pixfmt, 0,
sizeof(JxlPixelFormat));
78 JxlMemoryManager manager;
81 ctx->decoder = JxlDecoderCreate(&manager);
98 format->endianness = JXL_NATIVE_ENDIAN;
99 format->num_channels = basic_info->num_color_channels + (basic_info->alpha_bits > 0);
101 if (basic_info->num_color_channels == 1) {
102 if (basic_info->bits_per_sample <= 8) {
103 format->data_type = JXL_TYPE_UINT8;
106 if (basic_info->exponent_bits_per_sample || basic_info->bits_per_sample > 16) {
107 if (basic_info->alpha_bits)
109 format->data_type = JXL_TYPE_FLOAT;
112 format->data_type = JXL_TYPE_UINT16;
117 if (basic_info->num_color_channels == 3) {
118 if (basic_info->bits_per_sample <= 8) {
119 format->data_type = JXL_TYPE_UINT8;
122 if (basic_info->bits_per_sample > 16)
124 if (basic_info->exponent_bits_per_sample)
126 format->data_type = JXL_TYPE_UINT16;
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);
162 switch (jxl_color->transfer_function) {
169 case JXL_TRANSFER_FUNCTION_GAMMA:
170 if (jxl_color->gamma > 2.199 && jxl_color->gamma < 2.201)
172 else if (jxl_color->gamma > 2.799 && jxl_color->gamma < 2.801)
188 JxlDecoderStatus jret;
191 jret = JxlDecoderGetICCProfileSize(
ctx->decoder, &
ctx->jxl_pixfmt, JXL_COLOR_PROFILE_TARGET_DATA, &icc_len);
192 if (jret == JXL_DEC_SUCCESS && icc_len > 0) {
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) {
228 JxlDecoderStatus jret;
230 JxlColorEncoding jxl_color;
234 jret = JxlDecoderGetColorAsEncodedProfile(
ctx->decoder,
NULL, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &jxl_color);
235 if (jret == JXL_DEC_SUCCESS) {
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);
242 if (jret != JXL_DEC_SUCCESS)
246 if (
ctx->basic_info.uses_original_profile) {
262 if (
ctx->jxl_pixfmt.num_channels >= 3)
278 jxl_color.primaries = JXL_PRIMARIES_2100;
282 jxl_color.white_point = JXL_WHITE_POINT_D65;
285 if (
ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT
286 ||
ctx->jxl_pixfmt.data_type == JXL_TYPE_FLOAT16) {
288 jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
292 jxl_color.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
297 jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
299 jret = JxlDecoderSetPreferredColorProfile(
ctx->decoder, &jxl_color);
300 if (jret != JXL_DEC_SUCCESS) {
324 const uint8_t *buf = avpkt->
data;
325 size_t remaining = avpkt->
size;
326 JxlDecoderStatus jret;
332 jret = JxlDecoderSetInput(
ctx->decoder, buf, remaining);
334 if (jret == JXL_DEC_ERROR) {
340 jret = JxlDecoderProcessInput(
ctx->decoder);
346 remaining = JxlDecoderReleaseInput(
ctx->decoder);
347 buf = avpkt->
data + avpkt->
size - remaining;
353 case JXL_DEC_NEED_MORE_INPUT:
354 if (remaining == 0) {
360 case JXL_DEC_BASIC_INFO:
362 if (JxlDecoderGetBasicInfo(
ctx->decoder, &
ctx->basic_info) != JXL_DEC_SUCCESS) {
378 case JXL_DEC_COLOR_ENCODING:
383 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
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) {
394 case JXL_DEC_FULL_IMAGE:
398 frame->key_frame = 1;
407 return avpkt->
size - remaining;
408 case JXL_DEC_SUCCESS:
421 JxlDecoderReset(
ctx->decoder);
424 remaining = avpkt->
size;
438 JxlThreadParallelRunnerDestroy(
ctx->runner);
441 JxlDecoderDestroy(
ctx->decoder);
459 .p.wrapper_name =
"libjxl",
#define AV_LOG_WARNING
Something somehow does not look correct.
static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
AVPixelFormat
Pixel format.
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
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...
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
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 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
AVColorPrimaries
Chromaticity coordinates of the source primaries.
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
#define AV_PIX_FMT_GRAY16
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_CODEC_DECODE_CB(func)
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
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
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
const FFCodec ff_libjxl_decoder
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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)
JxlPixelFormat jxl_pixfmt
#define AV_PIX_FMT_GRAYF32
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_RGBA64
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.
@ 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...
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.
static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ 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.
@ 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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#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
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.
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
main external API structure.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
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.
A reference to a data buffer.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Structure to hold side data for an AVFrame.
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.
static enum AVPixelFormat libjxl_get_pix_fmt(void *avctx, const JxlBasicInfo *basic_info, JxlPixelFormat *format)
static enum AVColorTransferCharacteristic libjxl_get_trc(void *avctx, const JxlColorEncoding *jxl_color)
static int libjxl_color_encoding_event(AVCodecContext *avctx, AVFrame *frame)