FFmpeg
Data Structures | Macros | Functions | Variables
jpegxl_parser.c File Reference
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include "libavutil/attributes.h"
#include "libavutil/error.h"
#include "libavutil/intmath.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/pixfmt.h"
#include "bytestream.h"
#include "codec_id.h"
#include "get_bits.h"
#include "jpegxl.h"
#include "jpegxl_parse.h"
#include "parser.h"
#include "vlc.h"

Go to the source code of this file.

Data Structures

struct  JXLHybridUintConf
 
struct  JXLSymbolDistribution
 
struct  JXLDistributionBundle
 
struct  JXLEntropyDecoder
 
struct  JXLFrame
 
struct  JXLCodestream
 
struct  JXLParseContext
 

Macros

#define UNCHECKED_BITSTREAM_READER   0
 JPEG XL parser Copyright (c) 2023 Leo Izen leo.i.nosp@m.zen@.nosp@m.gmail.nosp@m..com More...
 
#define BITSTREAM_READER_LE
 
#define JXL_FLAG_NOISE   1
 
#define JXL_FLAG_PATCHES   2
 
#define JXL_FLAG_SPLINES   16
 
#define JXL_FLAG_USE_LF_FRAME   32
 
#define JXL_FLAG_SKIP_ADAPTIVE_LF_SMOOTH   128
 
#define MAX_PREFIX_ALPHABET_SIZE   (1u << 15)
 
#define clog1p(x)   (ff_log2(x) + !!(x))
 
#define unpack_signed(x)   (((x) & 1 ? -(x)-1 : (x))/2)
 
#define div_ceil(x, y)   (((x) - 1) / (y) + 1)
 
#define vlm(a, b)   {.sym = (a), .len = (b)}
 

Functions

static av_always_inline uint8_t jxl_u8 (GetBitContext *gb)
 Read a variable-length 8-bit integer. More...
 
static av_always_inline uint32_t jxl_u32 (GetBitContext *gb, uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3)
 
static uint64_t jxl_u64 (GetBitContext *gb)
 
static int read_hybrid_uint_conf (GetBitContext *gb, JXLHybridUintConf *conf, int log_alphabet_size)
 
static int read_hybrid_uint (GetBitContext *gb, const JXLHybridUintConf *conf, uint32_t token, uint32_t *hybrid_uint)
 
static uint32_t read_prefix_symbol (GetBitContext *gb, const JXLSymbolDistribution *dist)
 
static uint32_t read_ans_symbol (GetBitContext *gb, JXLEntropyDecoder *dec, const JXLSymbolDistribution *dist)
 
static int decode_hybrid_varlen_uint (GetBitContext *gb, JXLEntropyDecoder *dec, const JXLDistributionBundle *bundle, uint32_t context, uint32_t *hybrid_uint)
 
static int populate_distribution (GetBitContext *gb, JXLSymbolDistribution *dist, int log_alphabet_size)
 
static void dist_bundle_close (JXLDistributionBundle *bundle)
 
static int read_distribution_bundle (GetBitContext *gb, JXLEntropyDecoder *dec, JXLDistributionBundle *bundle, int num_dist, int disallow_lz77)
 
static int read_dist_clustering (GetBitContext *gb, JXLEntropyDecoder *dec, JXLDistributionBundle *bundle)
 
static int gen_alias_map (JXLEntropyDecoder *dec, JXLSymbolDistribution *dist, int log_alphabet_size)
 
static int read_simple_vlc_prefix (GetBitContext *gb, JXLEntropyDecoder *dec, JXLSymbolDistribution *dist)
 
static int read_vlc_prefix (GetBitContext *gb, JXLEntropyDecoder *dec, JXLSymbolDistribution *dist)
 
static void entropy_decoder_close (JXLEntropyDecoder *dec)
 
static int entropy_decoder_init (void *avctx, GetBitContext *gb, JXLEntropyDecoder *dec, int num_dist)
 
static int64_t entropy_decoder_read_symbol (GetBitContext *gb, JXLEntropyDecoder *dec, uint32_t context)
 
static uint32_t icc_context (uint64_t i, uint32_t b1, uint32_t b2)
 
static uint32_t toc_context (uint32_t x)
 
static void populate_fields (AVCodecParserContext *s, AVCodecContext *avctx, const FFJXLMetadata *meta)
 
static int skip_icc_profile (void *avctx, JXLParseContext *ctx, GetBitContext *gb)
 
static int skip_extensions (GetBitContext *gb)
 
static int parse_frame_header (void *avctx, JXLParseContext *ctx, GetBitContext *gb)
 
static int skip_boxes (JXLParseContext *ctx, const uint8_t *buf, int buf_size)
 
static int try_parse (AVCodecParserContext *s, AVCodecContext *avctx, JXLParseContext *ctx, const uint8_t *buf, int buf_size)
 
static int jpegxl_parse (AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
 

Variables

static const VLCElem level0_table [16]
 
static const VLCElem dist_prefix_table [128]
 
static const uint8_t prefix_codelen_map [18]
 
const AVCodecParser ff_jpegxl_parser
 

Macro Definition Documentation

◆ UNCHECKED_BITSTREAM_READER

#define UNCHECKED_BITSTREAM_READER   0

JPEG XL parser Copyright (c) 2023 Leo Izen leo.i.nosp@m.zen@.nosp@m.gmail.nosp@m..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

Definition at line 35 of file jpegxl_parser.c.

◆ BITSTREAM_READER_LE

#define BITSTREAM_READER_LE

Definition at line 36 of file jpegxl_parser.c.

◆ JXL_FLAG_NOISE

#define JXL_FLAG_NOISE   1

Definition at line 43 of file jpegxl_parser.c.

◆ JXL_FLAG_PATCHES

#define JXL_FLAG_PATCHES   2

Definition at line 44 of file jpegxl_parser.c.

◆ JXL_FLAG_SPLINES

#define JXL_FLAG_SPLINES   16

Definition at line 45 of file jpegxl_parser.c.

◆ JXL_FLAG_USE_LF_FRAME

#define JXL_FLAG_USE_LF_FRAME   32

Definition at line 46 of file jpegxl_parser.c.

◆ JXL_FLAG_SKIP_ADAPTIVE_LF_SMOOTH

#define JXL_FLAG_SKIP_ADAPTIVE_LF_SMOOTH   128

Definition at line 47 of file jpegxl_parser.c.

◆ MAX_PREFIX_ALPHABET_SIZE

#define MAX_PREFIX_ALPHABET_SIZE   (1u << 15)

Definition at line 49 of file jpegxl_parser.c.

◆ clog1p

#define clog1p (   x)    (ff_log2(x) + !!(x))

Definition at line 51 of file jpegxl_parser.c.

◆ unpack_signed

#define unpack_signed (   x)    (((x) & 1 ? -(x)-1 : (x))/2)

Definition at line 52 of file jpegxl_parser.c.

◆ div_ceil

#define div_ceil (   x,
 
)    (((x) - 1) / (y) + 1)

Definition at line 53 of file jpegxl_parser.c.

◆ vlm

#define vlm (   a,
  b 
)    {.sym = (a), .len = (b)}

Definition at line 54 of file jpegxl_parser.c.

Function Documentation

◆ jxl_u8()

static av_always_inline uint8_t jxl_u8 ( GetBitContext gb)
static

Read a variable-length 8-bit integer.

Used when populating the ANS frequency tables.

Definition at line 202 of file jpegxl_parser.c.

Referenced by populate_distribution().

◆ jxl_u32()

static av_always_inline uint32_t jxl_u32 ( GetBitContext gb,
uint32_t  c0,
uint32_t  c1,
uint32_t  c2,
uint32_t  c3,
uint32_t  u0,
uint32_t  u1,
uint32_t  u2,
uint32_t  u3 
)
static

Definition at line 213 of file jpegxl_parser.c.

Referenced by parse_frame_header(), and read_distribution_bundle().

◆ jxl_u64()

static uint64_t jxl_u64 ( GetBitContext gb)
static

Definition at line 229 of file jpegxl_parser.c.

Referenced by parse_frame_header(), skip_extensions(), and skip_icc_profile().

◆ read_hybrid_uint_conf()

static int read_hybrid_uint_conf ( GetBitContext gb,
JXLHybridUintConf conf,
int  log_alphabet_size 
)
static

Definition at line 259 of file jpegxl_parser.c.

Referenced by read_distribution_bundle().

◆ read_hybrid_uint()

static int read_hybrid_uint ( GetBitContext gb,
const JXLHybridUintConf conf,
uint32_t  token,
uint32_t *  hybrid_uint 
)
static

Definition at line 277 of file jpegxl_parser.c.

Referenced by decode_hybrid_varlen_uint().

◆ read_prefix_symbol()

static uint32_t read_prefix_symbol ( GetBitContext gb,
const JXLSymbolDistribution dist 
)
inlinestatic

Definition at line 299 of file jpegxl_parser.c.

Referenced by decode_hybrid_varlen_uint().

◆ read_ans_symbol()

static uint32_t read_ans_symbol ( GetBitContext gb,
JXLEntropyDecoder dec,
const JXLSymbolDistribution dist 
)
static

Definition at line 307 of file jpegxl_parser.c.

Referenced by decode_hybrid_varlen_uint().

◆ decode_hybrid_varlen_uint()

static int decode_hybrid_varlen_uint ( GetBitContext gb,
JXLEntropyDecoder dec,
const JXLDistributionBundle bundle,
uint32_t  context,
uint32_t *  hybrid_uint 
)
static

Definition at line 327 of file jpegxl_parser.c.

Referenced by entropy_decoder_read_symbol(), and read_dist_clustering().

◆ populate_distribution()

static int populate_distribution ( GetBitContext gb,
JXLSymbolDistribution dist,
int  log_alphabet_size 
)
static

Definition at line 380 of file jpegxl_parser.c.

Referenced by read_distribution_bundle().

◆ dist_bundle_close()

static void dist_bundle_close ( JXLDistributionBundle bundle)
static

Definition at line 480 of file jpegxl_parser.c.

Referenced by entropy_decoder_close(), and read_dist_clustering().

◆ read_distribution_bundle()

static int read_distribution_bundle ( GetBitContext gb,
JXLEntropyDecoder dec,
JXLDistributionBundle bundle,
int  num_dist,
int  disallow_lz77 
)
static

Definition at line 828 of file jpegxl_parser.c.

Referenced by entropy_decoder_init(), and read_dist_clustering().

◆ read_dist_clustering()

static int read_dist_clustering ( GetBitContext gb,
JXLEntropyDecoder dec,
JXLDistributionBundle bundle 
)
static

Definition at line 493 of file jpegxl_parser.c.

Referenced by read_distribution_bundle().

◆ gen_alias_map()

static int gen_alias_map ( JXLEntropyDecoder dec,
JXLSymbolDistribution dist,
int  log_alphabet_size 
)
static

Definition at line 562 of file jpegxl_parser.c.

Referenced by read_distribution_bundle().

◆ read_simple_vlc_prefix()

static int read_simple_vlc_prefix ( GetBitContext gb,
JXLEntropyDecoder dec,
JXLSymbolDistribution dist 
)
static

Definition at line 624 of file jpegxl_parser.c.

Referenced by read_vlc_prefix().

◆ read_vlc_prefix()

static int read_vlc_prefix ( GetBitContext gb,
JXLEntropyDecoder dec,
JXLSymbolDistribution dist 
)
static

Definition at line 682 of file jpegxl_parser.c.

Referenced by read_distribution_bundle().

◆ entropy_decoder_close()

static void entropy_decoder_close ( JXLEntropyDecoder dec)
static

Definition at line 914 of file jpegxl_parser.c.

Referenced by entropy_decoder_init(), parse_frame_header(), and skip_icc_profile().

◆ entropy_decoder_init()

static int entropy_decoder_init ( void *  avctx,
GetBitContext gb,
JXLEntropyDecoder dec,
int  num_dist 
)
static

Definition at line 922 of file jpegxl_parser.c.

Referenced by parse_frame_header(), and skip_icc_profile().

◆ entropy_decoder_read_symbol()

static int64_t entropy_decoder_read_symbol ( GetBitContext gb,
JXLEntropyDecoder dec,
uint32_t  context 
)
static

Definition at line 939 of file jpegxl_parser.c.

Referenced by parse_frame_header(), and skip_icc_profile().

◆ icc_context()

static uint32_t icc_context ( uint64_t  i,
uint32_t  b1,
uint32_t  b2 
)
inlinestatic

Definition at line 951 of file jpegxl_parser.c.

Referenced by skip_icc_profile().

◆ toc_context()

static uint32_t toc_context ( uint32_t  x)
inlinestatic

Definition at line 985 of file jpegxl_parser.c.

Referenced by parse_frame_header().

◆ populate_fields()

static void populate_fields ( AVCodecParserContext s,
AVCodecContext avctx,
const FFJXLMetadata meta 
)
static

Definition at line 990 of file jpegxl_parser.c.

Referenced by try_parse().

◆ skip_icc_profile()

static int skip_icc_profile ( void *  avctx,
JXLParseContext ctx,
GetBitContext gb 
)
static

Definition at line 1076 of file jpegxl_parser.c.

Referenced by try_parse().

◆ skip_extensions()

static int skip_extensions ( GetBitContext gb)
static

Definition at line 1136 of file jpegxl_parser.c.

Referenced by parse_frame_header().

◆ parse_frame_header()

static int parse_frame_header ( void *  avctx,
JXLParseContext ctx,
GetBitContext gb 
)
static

Definition at line 1161 of file jpegxl_parser.c.

Referenced by try_parse().

◆ skip_boxes()

static int skip_boxes ( JXLParseContext ctx,
const uint8_t *  buf,
int  buf_size 
)
static

Definition at line 1350 of file jpegxl_parser.c.

Referenced by jpegxl_parse().

◆ try_parse()

static int try_parse ( AVCodecParserContext s,
AVCodecContext avctx,
JXLParseContext ctx,
const uint8_t *  buf,
int  buf_size 
)
static

Definition at line 1396 of file jpegxl_parser.c.

Referenced by jpegxl_parse().

◆ jpegxl_parse()

static int jpegxl_parse ( AVCodecParserContext s,
AVCodecContext avctx,
const uint8_t **  poutbuf,
int *  poutbuf_size,
const uint8_t *  buf,
int  buf_size 
)
static

Definition at line 1469 of file jpegxl_parser.c.

Variable Documentation

◆ level0_table

const VLCElem level0_table[16]
static
Initial value:
= {
vlm(0, 2), vlm(4, 2), vlm(3, 2), vlm(2, 3), vlm(0, 2), vlm(4, 2), vlm(3, 2), vlm(1, 4),
vlm(0, 2), vlm(4, 2), vlm(3, 2), vlm(2, 3), vlm(0, 2), vlm(4, 2), vlm(3, 2), vlm(5, 4),
}

Definition at line 169 of file jpegxl_parser.c.

Referenced by read_vlc_prefix().

◆ dist_prefix_table

const VLCElem dist_prefix_table[128]
static
Initial value:
= {
vlm(10, 3), vlm(12, 7), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(0, 5), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(11, 6), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(0, 5), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(13, 7), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(0, 5), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(11, 6), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
vlm(10, 3), vlm(0, 5), vlm(7, 3), vlm(3, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(5, 4),
vlm(10, 3), vlm(4, 4), vlm(7, 3), vlm(1, 4), vlm(6, 3), vlm(8, 3), vlm(9, 3), vlm(2, 4),
}

Definition at line 175 of file jpegxl_parser.c.

Referenced by populate_distribution().

◆ prefix_codelen_map

const uint8_t prefix_codelen_map[18]
static
Initial value:
= {
1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15,
}

Definition at line 194 of file jpegxl_parser.c.

Referenced by read_vlc_prefix().

◆ ff_jpegxl_parser

const AVCodecParser ff_jpegxl_parser
Initial value:
= {
.codec_ids = { AV_CODEC_ID_JPEGXL },
.priv_data_size = sizeof(JXLParseContext),
.parser_parse = jpegxl_parse,
.parser_close = ff_parse_close,
}

Definition at line 1533 of file jpegxl_parser.c.

ff_parse_close
void ff_parse_close(AVCodecParserContext *s)
Definition: parser.c:290
jpegxl_parse
static int jpegxl_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: jpegxl_parser.c:1469
JXLParseContext
Definition: jpegxl_parser.c:152
vlm
#define vlm(a, b)
Definition: jpegxl_parser.c:54
AV_CODEC_ID_JPEGXL
@ AV_CODEC_ID_JPEGXL
Definition: codec_id.h:317