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};
49 return jxl_u32(gb, 0, 1, 2, 18, 0, 0, 4, 6);
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 uint32_t
type, name_len = 0;
195 if (!default_alpha) {
197 if (validate &&
type > 63)
202 jxl_u32(gb, 0, 3, 4, 1, 0, 0, 0, 3);
204 name_len = 8 *
jxl_u32(gb, 0, 0, 16, 48, 0, 4, 5, 10);
222 jxl_u32(gb, 1, 0, 3, 19, 0, 2, 4, 8);
232 uint64_t extensions =
jxl_u64(gb), extensions_len = 0;
240 for (
int i = 0;
i < 64;
i++) {
241 if (extensions & (UINT64_C(1) <<
i))
247 if (extensions_len > INT_MAX ||
get_bits_left(gb) <= extensions_len)
259 int all_default, extra_fields = 0;
260 int xyb_encoded = 1, have_icc_profile = 0;
261 int animation_offset = 0, have_timecodes = 0;
269 uint32_t num_extra_channels = 0;
289 if (orientation > 3 && meta)
310 tb.
den =
jxl_u32(gb, 100, 1000, 1, 1, 0, 0, 10, 30);
311 tb.
num =
jxl_u32(gb, 1, 1001, 1, 1, 0, 0, 8, 10);
312 jxl_u32(gb, 0, 0, 0, 0, 0, 3, 16, 32);
317 if (animation_offset && meta) {
330 if (!
get_bits1(gb) && validate && validate < 10)
333 num_extra_channels =
jxl_u32(gb, 0, 1, 2, 1, 0, 0, 4, 12);
334 if (num_extra_channels > 4 && validate && validate < 10)
336 for (uint32_t
i = 0;
i < num_extra_channels;
i++) {
350 if (color_space > 63 && validate)
352 if (!have_icc_profile) {
355 if (white_point > 63 && validate)
359 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
360 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
369 for (
int i = 0;
i < 6;
i++) {
370 jxl_u32(gb, 0, 524288, 1048576, 2097152, 19, 19, 20, 21);
385 if (trc > 63 && validate)
408 meta->
csp = color_space;
410 meta->
wp = white_point;
431 if (!have_icc_profile) {
433 if (bits_remaining &&
get_bits(gb, bits_remaining))
450 uint8_t *
buffer,
int buflen,
int *copied)
453 int pos = 0, last_box = 0;
464 size = bytestream2_get_be32(&gb);
465 tag = bytestream2_get_le32(&gb);
470 size = bytestream2_get_be64(&gb);
479 if (
tag ==
MKTAG(
'j',
'x',
'l',
'p')) {
483 idx = bytestream2_get_be32(&gb);
484 if (idx >= UINT32_C(0x80000000))
505 if (
size > buflen - *copied)
506 size = buflen - *copied;