aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/jpegxl_parse.h
blob: 0602f4d409991ba0bc0163bdf63700c0a7253df8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * 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 */