Skip to content

Commit

Permalink
avcodec/jpegxl_parser: add JPEG XL parser
Browse files Browse the repository at this point in the history
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: Leo Izen <leo.izen@gmail.com>
  • Loading branch information
Traneptora committed Aug 27, 2023
1 parent 7a69f73 commit 0c0dd23
Show file tree
Hide file tree
Showing 6 changed files with 2,167 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libavcodec/Makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
94 changes: 94 additions & 0 deletions libavcodec/jpegxl.h
@@ -0,0 +1,94 @@
/*
* 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 */

0 comments on commit 0c0dd23

Please sign in to comment.