0
|
1 /*
|
|
2 * BPG decoder
|
33
|
3 *
|
0
|
4 * Copyright (c) 2014 Fabrice Bellard
|
|
5 *
|
|
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7 * of this software and associated documentation files (the "Software"), to deal
|
|
8 * in the Software without restriction, including without limitation the rights
|
|
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10 * copies of the Software, and to permit persons to whom the Software is
|
|
11 * furnished to do so, subject to the following conditions:
|
|
12 *
|
|
13 * The above copyright notice and this permission notice shall be included in
|
|
14 * all copies or substantial portions of the Software.
|
|
15 *
|
|
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22 * THE SOFTWARE.
|
|
23 */
|
|
24 #ifndef _LIBBPG_H
|
|
25 #define _LIBBPG_H
|
|
26
|
|
27 #include <inttypes.h>
|
|
28
|
|
29 typedef struct BPGDecoderContext BPGDecoderContext;
|
|
30
|
|
31 typedef enum {
|
|
32 BPG_FORMAT_GRAY,
|
|
33 BPG_FORMAT_420, /* chroma at offset (0.5, 0.5) (JPEG) */
|
|
34 BPG_FORMAT_422, /* chroma at offset (0.5, 0) (JPEG) */
|
|
35 BPG_FORMAT_444,
|
|
36 BPG_FORMAT_420_VIDEO, /* chroma at offset (0, 0.5) (MPEG2) */
|
|
37 BPG_FORMAT_422_VIDEO, /* chroma at offset (0, 0) (MPEG2) */
|
|
38 } BPGImageFormatEnum;
|
|
39
|
|
40 typedef enum {
|
|
41 BPG_CS_YCbCr,
|
|
42 BPG_CS_RGB,
|
|
43 BPG_CS_YCgCo,
|
|
44 BPG_CS_YCbCr_BT709,
|
|
45 BPG_CS_YCbCr_BT2020,
|
|
46
|
|
47 BPG_CS_COUNT,
|
|
48 } BPGColorSpaceEnum;
|
|
49
|
|
50 typedef struct {
|
|
51 uint32_t width;
|
|
52 uint32_t height;
|
|
53 uint8_t format; /* see BPGImageFormatEnum */
|
|
54 uint8_t has_alpha; /* TRUE if an alpha plane is present */
|
|
55 uint8_t color_space; /* see BPGColorSpaceEnum */
|
|
56 uint8_t bit_depth;
|
|
57 uint8_t premultiplied_alpha; /* TRUE if the color is alpha premultiplied */
|
|
58 uint8_t has_w_plane; /* TRUE if a W plane is present (for CMYK encoding) */
|
|
59 uint8_t limited_range; /* TRUE if limited range for the color */
|
|
60 uint8_t has_animation; /* TRUE if the image contains animations */
|
|
61 uint16_t loop_count; /* animations: number of loop, 0 = infinity */
|
|
62 } BPGImageInfo;
|
|
63
|
|
64 typedef enum {
|
|
65 BPG_EXTENSION_TAG_EXIF = 1,
|
|
66 BPG_EXTENSION_TAG_ICCP = 2,
|
|
67 BPG_EXTENSION_TAG_XMP = 3,
|
|
68 BPG_EXTENSION_TAG_THUMBNAIL = 4,
|
|
69 BPG_EXTENSION_TAG_ANIM_CONTROL = 5,
|
|
70 } BPGExtensionTagEnum;
|
|
71
|
|
72 typedef struct BPGExtensionData {
|
|
73 BPGExtensionTagEnum tag;
|
|
74 uint32_t buf_len;
|
|
75 uint8_t *buf;
|
|
76 struct BPGExtensionData *next;
|
|
77 } BPGExtensionData;
|
|
78
|
|
79 typedef enum {
|
|
80 BPG_OUTPUT_FORMAT_RGB24,
|
|
81 BPG_OUTPUT_FORMAT_RGBA32, /* not premultiplied alpha */
|
|
82 BPG_OUTPUT_FORMAT_RGB48,
|
|
83 BPG_OUTPUT_FORMAT_RGBA64, /* not premultiplied alpha */
|
|
84 BPG_OUTPUT_FORMAT_CMYK32,
|
|
85 BPG_OUTPUT_FORMAT_CMYK64,
|
|
86 } BPGDecoderOutputFormat;
|
|
87
|
|
88 #define BPG_DECODER_INFO_BUF_SIZE 16
|
|
89
|
|
90 BPGDecoderContext *bpg_decoder_open(void);
|
|
91
|
|
92 /* If enable is true, extension data are kept during the image
|
|
93 decoding and can be accessed after bpg_decoder_decode() with
|
|
94 bpg_decoder_get_extension(). By default, the extension data are
|
|
95 discarded. */
|
|
96 void bpg_decoder_keep_extension_data(BPGDecoderContext *s, int enable);
|
|
97
|
|
98 /* return 0 if 0K, < 0 if error */
|
|
99 int bpg_decoder_decode(BPGDecoderContext *s, const uint8_t *buf, int buf_len);
|
|
100
|
|
101 /* Return the first element of the extension data list */
|
|
102 BPGExtensionData *bpg_decoder_get_extension_data(BPGDecoderContext *s);
|
|
103
|
|
104 /* return 0 if 0K, < 0 if error */
|
|
105 int bpg_decoder_get_info(BPGDecoderContext *s, BPGImageInfo *p);
|
|
106
|
|
107 /* return 0 if 0K, < 0 if error */
|
|
108 int bpg_decoder_start(BPGDecoderContext *s, BPGDecoderOutputFormat out_fmt);
|
|
109
|
|
110 /* return the frame delay for animations as a fraction (*pnum) / (*pden)
|
|
111 in seconds. In case there is no animation, 0 / 1 is returned. */
|
|
112 void bpg_decoder_get_frame_duration(BPGDecoderContext *s, int *pnum, int *pden);
|
|
113
|
|
114 /* return 0 if 0K, < 0 if error */
|
|
115 int bpg_decoder_get_line(BPGDecoderContext *s, void *buf);
|
|
116
|
|
117 void bpg_decoder_close(BPGDecoderContext *s);
|
|
118
|
|
119 /* only useful for low level access to the image data */
|
|
120 uint8_t *bpg_decoder_get_data(BPGDecoderContext *s, int *pline_size, int plane);
|
|
121
|
|
122 /* Get information from the start of the image data in 'buf' (at least
|
|
123 min(BPG_DECODER_INFO_BUF_SIZE, file_size) bytes must be given).
|
|
124
|
|
125 If pfirst_md != NULL, the extension data are also parsed and the
|
|
126 first element of the list is returned in *pfirst_md. The list must
|
|
127 be freed with bpg_decoder_free_extension_data().
|
|
128
|
|
129 BPGImageInfo.loop_count is only set if extension data are parsed.
|
|
130
|
|
131 Return 0 if OK, < 0 if unrecognized data. */
|
33
|
132 int bpg_decoder_get_info_from_buf(BPGImageInfo *p,
|
0
|
133 BPGExtensionData **pfirst_md,
|
|
134 const uint8_t *buf, int buf_len);
|
|
135 /* Free the extension data returned by bpg_decoder_get_info_from_buf() */
|
|
136 void bpg_decoder_free_extension_data(BPGExtensionData *first_md);
|
|
137
|
|
138 #endif /* _LIBBPG_H */
|