Unverified Commit 0c0dd23f authored by Leo Izen's avatar Leo Izen

avcodec/jpegxl_parser: add JPEG XL parser

Add a full parser to libavcodec for AV_CODEC_ID_JPEGXL. It finds the
end of the stream in order to packetize the codec, and it looks at
the headers to set preliminary information like dimensions and pixel
format.

Note that much of this code is duplicated from avformat/jpegxl_probe.c,
but that code will be removed and call this instead in the next commit.
Signed-off-by: 's avatarLeo Izen <leo.izen@gmail.com>
parent 7a69f731
......@@ -1056,6 +1056,8 @@ STLIBOBJS-$(CONFIG_AVFORMAT) += to_upper4.o
STLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o
STLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o
STLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o
STLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += jpegxl_parse.o
STLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER) += jpegxl_parse.o
STLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o
STLIBOBJS-$(CONFIG_MOV_DEMUXER) += ac3_channel_layout_tab.o
STLIBOBJS-$(CONFIG_MXF_MUXER) += golomb.o
......@@ -1185,6 +1187,7 @@ OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o
OBJS-$(CONFIG_HDR_PARSER) += hdr_parser.o
OBJS-$(CONFIG_IPU_PARSER) += ipu_parser.o
OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o
OBJS-$(CONFIG_JPEGXL_PARSER) += jpegxl_parser.o jpegxl_parse.o
OBJS-$(CONFIG_MISC4_PARSER) += misc4_parser.o
OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o
OBJS-$(CONFIG_MLP_PARSER) += mlp_parse.o mlp_parser.o mlp.o
......
/*
* JPEG XL Common Header Definitions
* Copyright (c) 2023 Leo Izen <leo.izen@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_JPEGXL_H
#define AVCODEC_JPEGXL_H
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
#define FF_JPEGXL_CONTAINER_SIGNATURE_LE 0x204c584a0c000000
#define FF_JPEGXL_CODESTREAM_SIGNATURE_BE 0xff0a
#define FF_JPEGXL_CONTAINER_SIGNATURE_BE 0x0000000c4a584c20
typedef enum FFJXLFrameEncoding {
JPEGXL_ENC_VARDCT,
JPEGXL_ENC_MODULAR
} FFJXLFrameEncoding;
typedef enum FFJXLFrameType {
JPEGXL_FRAME_REGULAR,
JPEGXL_FRAME_LF,
JPEGXL_FRAME_REFERENCE_ONLY,
JPEGXL_FRAME_SKIP_PROGRESSIVE
} FFJXLFrameType;
typedef enum FFJXLBlendMode {
JPEGXL_BM_REPLACE,
JPEGXL_BM_ADD,
JPEGXL_BM_BLEND,
JPEGXL_BM_MULADD,
JPEGXL_BM_MUL
} FFJXLBlendMode;
typedef enum FFJXLExtraChannelType {
JPEGXL_CT_ALPHA = 0,
JPEGXL_CT_DEPTH,
JPEGXL_CT_SPOT_COLOR,
JPEGXL_CT_SELECTION_MASK,
JPEGXL_CT_BLACK,
JPEGXL_CT_CFA,
JPEGXL_CT_THERMAL,
JPEGXL_CT_NON_OPTIONAL = 15,
JPEGXL_CT_OPTIONAL
} FFJXLExtraChannelType;
typedef enum FFJXLColorSpace {
JPEGXL_CS_RGB = 0,
JPEGXL_CS_GRAY,
JPEGXL_CS_XYB,
JPEGXL_CS_UNKNOWN
} FFJXLColorSpace;
typedef enum FFJXLWhitePoint {
JPEGXL_WP_D65 = 1,
JPEGXL_WP_CUSTOM,
JPEGXL_WP_E = 10,
JPEGXL_WP_DCI = 11
} FFJXLWhitePoint;
typedef enum FFJXLPrimaries {
JPEGXL_PR_SRGB = 1,
JPEGXL_PR_CUSTOM,
JPEGXL_PR_2100 = 9,
JPEGXL_PR_P3 = 11,
} FFJXLPrimaries;
typedef enum FFJXLTransferCharacteristic {
JPEGXL_TR_BT709 = 1,
JPEGXL_TR_UNKNOWN,
JPEGXL_TR_LINEAR = 8,
JPEGXL_TR_SRGB = 13,
JPEGXL_TR_PQ = 16,
JPEGXL_TR_DCI,
JPEGXL_TR_HLG,
JPEGXL_TR_GAMMA = 1 << 24,
} FFJXLTransferCharacteristic;
#endif /* AVCODEC_JPEGXL_H */
This diff is collapsed.
/*
* JPEG XL Header Parser
* Copyright (c) 2023 Leo Izen <leo.izen@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_JPEGXL_PARSE_H
#define AVCODEC_JPEGXL_PARSE_H
#include <stdint.h>
#include "libavutil/rational.h"
#include "jpegxl.h"
typedef struct FFJXLMetadata {
uint32_t width;
uint32_t height;
uint32_t coded_width;
uint32_t coded_height;
int bit_depth;
int have_alpha;
/*
* offset, in bits, of the animation header
* zero if not animated
*/
int animation_offset;
AVRational timebase;
FFJXLColorSpace csp;
FFJXLWhitePoint wp;
FFJXLPrimaries primaries;
FFJXLTransferCharacteristic trc;
/* used by the parser */
int xyb_encoded;
int have_icc_profile;
int have_timecodes;
uint32_t num_extra_channels;
} FFJXLMetadata;
/*
* copies as much of the codestream into the buffer as possible
* pass a shorter buflen to request less
* returns the number of bytes consumed from input, may be greater than input_len
* if the input doesn't end on an ISOBMFF-box boundary
*/
int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_len,
uint8_t *buffer, int buflen, int *copied);
/*
* Parse the codestream header with the provided buffer. Returns negative upon failure,
* or the number of bits consumed upon success.
* The FFJXLMetadata parameter may be NULL, in which case it's ignored.
*/
int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, FFJXLMetadata *meta, int validate);
#endif /* AVCODEC_JPEGXL_PARSE_H */
This diff is collapsed.
......@@ -55,6 +55,7 @@ extern const AVCodecParser ff_hevc_parser;
extern const AVCodecParser ff_hdr_parser;
extern const AVCodecParser ff_ipu_parser;
extern const AVCodecParser ff_jpeg2000_parser;
extern const AVCodecParser ff_jpegxl_parser;
extern const AVCodecParser ff_misc4_parser;
extern const AVCodecParser ff_mjpeg_parser;
extern const AVCodecParser ff_mlp_parser;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment