Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libtheora/decint.h
9896 views
1
/********************************************************************
2
* *
3
* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7
* *
8
* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
9
* by the Xiph.Org Foundation and contributors *
10
* https://www.xiph.org/ *
11
* *
12
********************************************************************
13
14
function:
15
16
********************************************************************/
17
18
#include <limits.h>
19
#if !defined(_decint_H)
20
# define _decint_H (1)
21
# include "theora/theoradec.h"
22
# include "state.h"
23
# include "bitpack.h"
24
# include "huffdec.h"
25
# include "dequant.h"
26
27
typedef struct th_setup_info oc_setup_info;
28
typedef struct oc_dec_opt_vtable oc_dec_opt_vtable;
29
typedef struct oc_dec_pipeline_state oc_dec_pipeline_state;
30
typedef struct th_dec_ctx oc_dec_ctx;
31
32
33
34
/*Decoder-specific accelerated functions.*/
35
# if defined(OC_C64X_ASM)
36
# include "c64x/c64xdec.h"
37
# endif
38
39
# if !defined(oc_dec_accel_init)
40
# define oc_dec_accel_init oc_dec_accel_init_c
41
# endif
42
# if defined(OC_DEC_USE_VTABLE)
43
# if !defined(oc_dec_dc_unpredict_mcu_plane)
44
# define oc_dec_dc_unpredict_mcu_plane(_dec,_pipe,_pli) \
45
((*(_dec)->opt_vtable.dc_unpredict_mcu_plane)(_dec,_pipe,_pli))
46
# endif
47
# else
48
# if !defined(oc_dec_dc_unpredict_mcu_plane)
49
# define oc_dec_dc_unpredict_mcu_plane oc_dec_dc_unpredict_mcu_plane_c
50
# endif
51
# endif
52
53
54
55
/*Constants for the packet-in state machine specific to the decoder.*/
56
57
/*Next packet to read: Data packet.*/
58
#define OC_PACKET_DATA (0)
59
60
61
62
struct th_setup_info{
63
/*The Huffman codes.*/
64
ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES];
65
/*The quantization parameters.*/
66
th_quant_info qinfo;
67
};
68
69
70
71
/*Decoder specific functions with accelerated variants.*/
72
struct oc_dec_opt_vtable{
73
void (*dc_unpredict_mcu_plane)(oc_dec_ctx *_dec,
74
oc_dec_pipeline_state *_pipe,int _pli);
75
};
76
77
78
79
struct oc_dec_pipeline_state{
80
/*Decoded DCT coefficients.
81
These are placed here instead of on the stack so that they can persist
82
between blocks, which makes clearing them back to zero much faster when
83
only a few non-zero coefficients were decoded.
84
It requires at least 65 elements because the zig-zag index array uses the
85
65th element as a dumping ground for out-of-range indices to protect us
86
from buffer overflow.
87
We make it fully twice as large so that the second half can serve as the
88
reconstruction buffer, which saves passing another parameter to all the
89
acceleration functions.
90
It also solves problems with 16-byte alignment for NEON on ARM.
91
gcc (as of 4.2.1) only seems to be able to give stack variables 8-byte
92
alignment, and silently produces incorrect results if you ask for 16.
93
Finally, keeping it off the stack means there's less likely to be a data
94
hazard between the NEON co-processor and the regular ARM core, which avoids
95
unnecessary stalls.*/
96
OC_ALIGN16(ogg_int16_t dct_coeffs[128]);
97
OC_ALIGN16(signed char bounding_values[256]);
98
ptrdiff_t ti[3][64];
99
ptrdiff_t ebi[3][64];
100
ptrdiff_t eob_runs[3][64];
101
const ptrdiff_t *coded_fragis[3];
102
const ptrdiff_t *uncoded_fragis[3];
103
ptrdiff_t ncoded_fragis[3];
104
ptrdiff_t nuncoded_fragis[3];
105
const ogg_uint16_t *dequant[3][3][2];
106
int fragy0[3];
107
int fragy_end[3];
108
int pred_last[3][4];
109
int mcu_nvfrags;
110
int loop_filter;
111
int pp_level;
112
};
113
114
115
struct th_dec_ctx{
116
/*Shared encoder/decoder state.*/
117
oc_theora_state state;
118
/*Whether or not packets are ready to be emitted.
119
This takes on negative values while there are remaining header packets to
120
be emitted, reaches 0 when the codec is ready for input, and goes to 1
121
when a frame has been processed and a data packet is ready.*/
122
int packet_state;
123
/*Buffer in which to assemble packets.*/
124
oc_pack_buf opb;
125
/*Huffman decode trees.*/
126
ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES];
127
/*The index of the first token in each plane for each coefficient.*/
128
ptrdiff_t ti0[3][64];
129
/*The number of outstanding EOB runs at the start of each coefficient in each
130
plane.*/
131
ptrdiff_t eob_runs[3][64];
132
/*The DCT token lists.*/
133
unsigned char *dct_tokens;
134
/*The extra bits associated with DCT tokens.*/
135
unsigned char *extra_bits;
136
/*The number of dct tokens unpacked so far.*/
137
int dct_tokens_count;
138
/*The out-of-loop post-processing level.*/
139
int pp_level;
140
/*The DC scale used for out-of-loop deblocking.*/
141
int pp_dc_scale[64];
142
/*The sharpen modifier used for out-of-loop deringing.*/
143
int pp_sharp_mod[64];
144
/*The DC quantization index of each block.*/
145
unsigned char *dc_qis;
146
/*The variance of each block.*/
147
int *variances;
148
/*The storage for the post-processed frame buffer.*/
149
unsigned char *pp_frame_data;
150
/*Whether or not the post-processsed frame buffer has space for chroma.*/
151
int pp_frame_state;
152
/*The buffer used for the post-processed frame.
153
Note that this is _not_ guaranteed to have the same strides and offsets as
154
the reference frame buffers.*/
155
th_ycbcr_buffer pp_frame_buf;
156
/*The striped decode callback function.*/
157
th_stripe_callback stripe_cb;
158
oc_dec_pipeline_state pipe;
159
# if defined(OC_DEC_USE_VTABLE)
160
/*Table for decoder acceleration functions.*/
161
oc_dec_opt_vtable opt_vtable;
162
# endif
163
# if defined(HAVE_CAIRO)
164
/*Output metrics for debugging.*/
165
int telemetry_mbmode;
166
int telemetry_mv;
167
int telemetry_qi;
168
int telemetry_bits;
169
int telemetry_frame_bytes;
170
int telemetry_coding_bytes;
171
int telemetry_mode_bytes;
172
int telemetry_mv_bytes;
173
int telemetry_qi_bytes;
174
int telemetry_dc_bytes;
175
unsigned char *telemetry_frame_data;
176
# endif
177
};
178
179
/*Default pure-C implementations of decoder-specific accelerated functions.*/
180
void oc_dec_accel_init_c(oc_dec_ctx *_dec);
181
182
void oc_dec_dc_unpredict_mcu_plane_c(oc_dec_ctx *_dec,
183
oc_dec_pipeline_state *_pipe,int _pli);
184
185
#endif
186
187