25#define UNCHECKED_BITSTREAM_READER 0
26#define BITSTREAM_READER_LE
33 uint32_t c0, uint32_t
c1, uint32_t
c2, uint32_t c3,
34 uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3)
37 const uint32_t ubits [4] = {u0, u1, u2, u3};
38 uint32_t ret, choice =
get_bits(gb, 2);
49 return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6);
55 uint64_t
shift = 12, ret;
85 uint64_t height64 =
height;
90 return (uint32_t)((height64 * 12) / 10);
92 return (uint32_t)((height64 * 4) / 3);
94 return (uint32_t)((height64 * 3) / 2);
96 return (uint32_t)((height64 * 16) / 9);
98 return (uint32_t)((height64 * 5) / 4);
100 return (uint32_t)(height64 * 2);
129 if (validate && (
width > (1 << 18) ||
height > (1 << 18)
193 int alpha_associated = 0;
194 uint32_t
type, name_len = 0;
196 if (!default_alpha) {
198 if (validate &&
type > 63)
203 jxl_u32(gb, 0, 3, 4, 1, 0, 0, 0, 3);
205 name_len = 8 *
jxl_u32(gb, 0, 0, 16, 48, 0, 4, 5, 10);
223 jxl_u32(gb, 1, 0, 3, 19, 0, 2, 4, 8);
235 uint64_t extensions =
jxl_u64(gb), extensions_len = 0;
243 for (
int i = 0;
i < 64;
i++) {
244 if (extensions & (UINT64_C(1) <<
i))
250 if (extensions_len > INT_MAX ||
get_bits_left(gb) <= extensions_len)
262 int all_default, extra_fields = 0;
263 int xyb_encoded = 1, have_icc_profile = 0;
264 int animation_offset = 0, have_timecodes = 0;
272 uint32_t num_extra_channels = 0;
292 if (orientation > 3 && meta)
313 tb.
den =
jxl_u32(gb, 100, 1000, 1, 1, 0, 0, 10, 30);
314 tb.
num =
jxl_u32(gb, 1, 1001, 1, 1, 0, 0, 8, 10);
315 jxl_u32(gb, 0, 0, 0, 0, 0, 3, 16, 32);
320 if (animation_offset && meta) {
333 if (!
get_bits1(gb) && validate && validate < 10)
336 num_extra_channels =
jxl_u32(gb, 0, 1, 2, 1, 0, 0, 4, 12);
337 if (num_extra_channels > 4 && validate && validate < 10)
339 for (uint32_t
i = 0;
i < num_extra_channels;
i++) {
353 if (color_space > 63 && validate)
355 if (!have_icc_profile) {
358 if (white_point > 63 && validate)
362 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
363 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
372 for (
int i = 0;
i < 6;
i++) {
373 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
388 if (trc > 63 && validate)
411 meta->
csp = color_space;
413 meta->
wp = white_point;
434 if (!have_icc_profile) {
436 if (bits_remaining &&
get_bits(gb, bits_remaining))
453 uint8_t *
buffer,
int buflen,
int *copied)
468 size = bytestream2_get_be32(&gb);
469 tag = bytestream2_get_le32(&gb);
474 size = bytestream2_get_be64(&gb);
483 if (
tag ==
MKTAG(
'j',
'x',
'l',
'p')) {
487 idx = bytestream2_get_be32(&gb);
488 if (idx >= UINT32_C(0x80000000))
509 if (
size > buflen - *copied)
510 size = buflen - *copied;
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
static const struct @033145243110221005363036244076252070150076110330 constants[]
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
FFJXLTransferCharacteristic
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE
static int shift(int a, int b)
static int jpegxl_read_extra_channel_info(GetBitContext *gb, FFJXLMetadata *meta, int validate)
validate a Jpeg XL Extra Channel Info bundle
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 uint32_t jpegxl_width_from_ratio(uint32_t height, int ratio)
static int jpegxl_read_preview_header(GetBitContext *gb, int validate)
validate a Jpeg XL Preview Header
static int jpegxl_read_size_header(GetBitContext *gb, FFJXLMetadata *meta, int validate)
validate a Jpeg XL Size Header
static uint64_t jxl_u64(GetBitContext *gb)
int ff_jpegxl_collect_codestream_header(const uint8_t *input_buffer, int input_len, uint8_t *buffer, int buflen, int *copied)
static void jpegxl_get_bit_depth(GetBitContext *gb, FFJXLMetadata *meta)
get a Jpeg XL BitDepth Header.
int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, FFJXLMetadata *meta, int validate)
static int jpegxl_skip_extensions(GetBitContext *gb)
static av_always_inline uint32_t jxl_enum(GetBitContext *gb)
#define FFSWAP(type, a, b)
#define MKTAG(a, b, c, d)
Rational number (pair of numerator and denominator).