Skip to content

Commit 3941db4

Browse files
ArildFuldsethThomas Davies
authored andcommitted
First version with configurable bit-depth
1 parent 5260185 commit 3941db4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1915
-1291
lines changed

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ ifeq ($(ARCH),sse4)
1616
CFLAGS += -msse4
1717
endif
1818

19-
2019
COMMON_SOURCES = \
2120
common/common_block.c \
2221
common/common_frame.c \
22+
common/common_tables.c \
2323
common/transform.c \
2424
common/intra_prediction.c \
2525
common/inter_prediction.c \
2626
common/common_kernels.c \
2727
common/snr.c \
28+
common/snr_hbd.c \
2829
common/simd.c \
2930
common/temporal_interp.c \
30-
common/wt_matrix.c
31+
common/wt_matrix.c \
32+
common/common_frame_hbd.c \
33+
common/common_block_hbd.c \
34+
common/inter_prediction_hbd.c \
35+
common/intra_prediction_hbd.c \
36+
common/temporal_interp_hbd.c
3137

3238

3339
ENCODER_SOURCES = \
@@ -40,7 +46,10 @@ ENCODER_SOURCES = \
4046
enc/write_bits.c \
4147
enc/enc_kernels.c \
4248
enc/rc.c \
43-
$(COMMON_SOURCES)
49+
enc/encode_block_hbd.c \
50+
enc/encode_frame_hbd.c \
51+
enc/encode_tables.c \
52+
$(COMMON_SOURCES)
4453

4554
DECODER_SOURCES = \
4655
dec/decode_block.c \
@@ -49,6 +58,7 @@ DECODER_SOURCES = \
4958
dec/maindec.c \
5059
dec/read_bits.c \
5160
dec/decode_frame.c \
61+
dec/decode_block_hbd.c \
5262
$(COMMON_SOURCES)
5363

5464
ENCODER_OBJECTS = $(ENCODER_SOURCES:.c=.o)

build/ThorDec/ThorDec.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@
2020
</ItemGroup>
2121
<ItemGroup>
2222
<ClCompile Include="..\..\common\common_block.c" />
23+
<ClCompile Include="..\..\common\common_block_hbd.c" />
2324
<ClCompile Include="..\..\common\common_frame.c" />
25+
<ClCompile Include="..\..\common\common_frame_hbd.c" />
2426
<ClCompile Include="..\..\common\common_kernels.c" />
27+
<ClCompile Include="..\..\common\common_tables.c" />
2528
<ClCompile Include="..\..\common\inter_prediction.c" />
29+
<ClCompile Include="..\..\common\inter_prediction_hbd.c" />
2630
<ClCompile Include="..\..\common\intra_prediction.c" />
31+
<ClCompile Include="..\..\common\intra_prediction_hbd.c" />
2732
<ClCompile Include="..\..\common\simd.c" />
2833
<ClCompile Include="..\..\common\snr.c" />
2934
<ClCompile Include="..\..\common\temporal_interp.c" />
35+
<ClCompile Include="..\..\common\temporal_interp_hbd.c" />
3036
<ClCompile Include="..\..\common\transform.c" />
3137
<ClCompile Include="..\..\common\wt_matrix.c" />
3238
<ClCompile Include="..\..\dec\decode_block.c" />
39+
<ClCompile Include="..\..\dec\decode_block_hbd.c" />
3340
<ClCompile Include="..\..\dec\decode_frame.c" />
3441
<ClCompile Include="..\..\dec\getbits.c" />
3542
<ClCompile Include="..\..\dec\getvlc.c" />

build/ThorEnc/ThorEnc.vcxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@
2020
</ItemGroup>
2121
<ItemGroup>
2222
<ClCompile Include="..\..\common\common_block.c" />
23+
<ClCompile Include="..\..\common\common_block_hbd.c" />
2324
<ClCompile Include="..\..\common\common_frame.c" />
25+
<ClCompile Include="..\..\common\common_frame_hbd.c" />
2426
<ClCompile Include="..\..\common\common_kernels.c" />
27+
<ClCompile Include="..\..\common\common_tables.c" />
2528
<ClCompile Include="..\..\common\inter_prediction.c" />
29+
<ClCompile Include="..\..\common\inter_prediction_hbd.c" />
2630
<ClCompile Include="..\..\common\intra_prediction.c" />
31+
<ClCompile Include="..\..\common\intra_prediction_hbd.c" />
2732
<ClCompile Include="..\..\common\simd.c" />
2833
<ClCompile Include="..\..\common\snr.c" />
34+
<ClCompile Include="..\..\common\snr_hbd.c" />
2935
<ClCompile Include="..\..\common\temporal_interp.c" />
36+
<ClCompile Include="..\..\common\temporal_interp_hbd.c" />
3037
<ClCompile Include="..\..\common\transform.c" />
3138
<ClCompile Include="..\..\common\wt_matrix.c" />
3239
<ClCompile Include="..\..\enc\encode_block.c" />
40+
<ClCompile Include="..\..\enc\encode_block_hbd.c" />
3341
<ClCompile Include="..\..\enc\encode_frame.c" />
42+
<ClCompile Include="..\..\enc\encode_frame_hbd.c" />
43+
<ClCompile Include="..\..\enc\encode_tables.c" />
3444
<ClCompile Include="..\..\enc\enc_kernels.c" />
3545
<ClCompile Include="..\..\enc\mainenc.c" />
3646
<ClCompile Include="..\..\enc\putbits.c" />

common/common_block.c

Lines changed: 25 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -35,102 +35,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
#include "global.h"
3636
#include "common_block.h"
3737

38-
int zigzag16[16] = {
39-
0, 1, 5, 6,
40-
2, 4, 7, 12,
41-
3, 8, 11, 13,
42-
9, 10, 14, 15
43-
};
44-
45-
int zigzag64[64] = {
46-
0, 1, 5, 6, 14, 15, 27, 28,
47-
2, 4, 7, 13, 16, 26, 29, 42,
48-
3, 8, 12, 17, 25, 30, 41, 43,
49-
9, 11, 18, 24, 31, 40, 44, 53,
50-
10, 19, 23, 32, 39, 45, 52, 54,
51-
20, 22, 33, 38, 46, 51, 55, 60,
52-
21, 34, 37, 47, 50, 56, 59, 61,
53-
35, 36, 48, 49, 57, 58, 62, 63
54-
};
55-
56-
int zigzag256[256] = {
57-
0, 1, 5, 6, 14, 15, 27, 28, 44, 45, 65, 66, 90, 91,119,120,
58-
2, 4, 7, 13, 16, 26, 29, 43, 46, 64, 67, 89, 92,118,121,150,
59-
3, 8, 12, 17, 25, 30, 42, 47, 63, 68, 88, 93,117,122,149,151,
60-
9, 11, 18, 24, 31, 41, 48, 62, 69, 87, 94,116,123,148,152,177,
61-
10, 19, 23, 32, 40, 49, 61, 70, 86, 95,115,124,147,153,176,178,
62-
20, 22, 33, 39, 50, 60, 71, 85, 96,114,125,146,154,175,179,200,
63-
21, 34, 38, 51, 59, 72, 84, 97,113,126,145,155,174,180,199,201,
64-
35, 37, 52, 58, 73, 83, 98,112,127,144,156,173,181,198,202,219,
65-
36, 53, 57, 74, 82, 99,111,128,143,157,172,182,197,203,218,220,
66-
54, 56, 75, 81,100,110,129,142,158,171,183,196,204,217,221,234,
67-
55, 76, 80,101,109,130,141,159,170,184,195,205,216,222,233,235,
68-
77, 79,102,108,131,140,160,169,185,194,206,215,223,232,236,245,
69-
78,103,107,132,139,161,168,186,193,207,214,224,231,237,244,246,
70-
104,106,133,138,162,167,187,192,208,213,225,230,238,243,247,252,
71-
105,134,137,163,166,188,191,209,212,226,229,239,242,248,251,253,
72-
135,136,164,165,189,190,210,211,227,228,240,241,249,250,254,255
73-
};
74-
75-
76-
int chroma_qp[52] = {
77-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
78-
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29,
79-
30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38,
80-
39, 40, 41, 42, 43, 44, 45
81-
};
82-
83-
const uint16_t gquant_table[6] = {26214,23302,20560,18396,16384,14564};
84-
const uint16_t gdequant_table[6] = {40,45,51,57,64,72};
85-
86-
int get_left_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
87-
int left_available = xpos > 0;
88-
return left_available;
89-
}
90-
91-
int get_up_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
92-
int up_available = ypos > 0;
93-
return up_available;
94-
}
95-
96-
int get_upright_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
97-
98-
int upright_available;
99-
int size, size2;
100-
101-
/* Test for frame boundaries */
102-
upright_available = (ypos > 0) && (xpos + bwidth < fwidth);
103-
104-
/* Test for coding block boundaries */
105-
size = max(bwidth, bheight);
106-
for (size2 = size; size2 < sb_size; size2 *= 2) {
107-
if ((ypos % (size2 << 1)) == size2 && (xpos % size2) == (size2 - size)) upright_available = 0;
108-
}
109-
return upright_available;
110-
}
111-
112-
int get_downleft_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
113-
114-
int downleft_available;
115-
int size, size2;
116-
117-
/* Test for frame boundaries */
118-
downleft_available = (xpos > 0) && (ypos + bheight < fheight);
119-
120-
size = max(bwidth, bheight);
121-
/* Test for external super block boundaries */
122-
if ((ypos % sb_size) == (sb_size - size) && (xpos % sb_size) == 0) downleft_available = 0;
123-
124-
/* Test for coding block boundaries */
125-
size = max(bwidth, bheight);
126-
for (size2 = 2 * size; size2 <= sb_size; size2 *= 2) {
127-
if ((ypos % size2) == (size2 - size) && (xpos % size2) > 0) downleft_available = 0;
128-
}
129-
130-
return downleft_available;
131-
}
132-
133-
void dequantize (int16_t *coeff, int16_t *rcoeff, int qp, int size, qmtx_t * wt_matrix)
38+
extern const int zigzag16[16];
39+
extern const int zigzag64[64];
40+
extern const int zigzag256[256];
41+
extern const int chroma_qp[52];
42+
extern const uint16_t gquant_table[6];
43+
extern const uint16_t gdequant_table[6];
44+
45+
void TEMPLATE(dequantize)(int16_t *coeff, int16_t *rcoeff, int qp, int size, qmtx_t * wt_matrix)
13446
{
13547
int tr_log2size = log2i(size);
13648
const int lshift = qp / 6;
@@ -157,21 +69,20 @@ void dequantize (int16_t *coeff, int16_t *rcoeff, int qp, int size, qmtx_t * wt_
15769
rcoeff[i*size+j] = (int16_t)((c * scale + add) >> (rshift - lshift));//needs clipping
15870
}
15971
}
160-
16172
}
16273
}
16374

164-
void reconstruct_block(int16_t *block, uint8_t *pblock, uint8_t *rec, int size, int pstride, int stride)
75+
void TEMPLATE(reconstruct_block)(int16_t *block, SAMPLE *pblock, SAMPLE *rec, int size, int pstride, int stride, int bitdepth)
16576
{
16677
int i,j;
16778
for(i=0;i<size;i++){
16879
for (j=0;j<size;j++){
169-
rec[i*stride+j] = (uint8_t)clip255(block[i*size+j] + (int16_t)pblock[i*pstride+j]);
80+
rec[i*stride+j] = (SAMPLE)saturate(block[i*size+j] + (int16_t)pblock[i*pstride+j], bitdepth);
17081
}
17182
}
17283
}
17384

174-
void find_block_contexts(int ypos, int xpos, int height, int width, int size, deblock_data_t *deblock_data, block_context_t *block_context, int enable){
85+
void TEMPLATE(find_block_contexts)(int ypos, int xpos, int height, int width, int size, deblock_data_t *deblock_data, block_context_t *block_context, int enable){
17586

17687
if (ypos >= MIN_BLOCK_SIZE && xpos >= MIN_BLOCK_SIZE && ypos + size < height && xpos + size < width && enable && size <= MAX_TR_SIZE) {
17788
int by = ypos/MIN_PB_SIZE;
@@ -193,14 +104,14 @@ void find_block_contexts(int ypos, int xpos, int height, int width, int size, de
193104
}
194105
}
195106

196-
int clpf_sample(int X, int A, int B, int C, int D, int E, int F, int b) {
107+
int TEMPLATE(clpf_sample)(int X, int A, int B, int C, int D, int E, int F, int b) {
197108
int delta =
198109
4*clip(A - X, -b, b) + clip(B - X, -b, b) + 3*clip(C - X, -b, b) +
199110
3*clip(D - X, -b, b) + clip(E - X, -b, b) + 4*clip(F - X, -b, b);
200111
return (8 + delta - (delta < 0)) >> 4;
201112
}
202113

203-
void clpf_block(const uint8_t *src, uint8_t *dst, int stride, int x0, int y0, int sizex, int sizey, int width, int height, unsigned int strength) {
114+
void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int stride, int x0, int y0, int sizex, int sizey, int width, int height, unsigned int strength) {
204115
for (int y = y0; y < y0+sizey; y++){
205116
for (int x = x0; x < x0+sizex; x++) {
206117
int X = src[y*stride + x];
@@ -211,13 +122,13 @@ void clpf_block(const uint8_t *src, uint8_t *dst, int stride, int x0, int y0, in
211122
int E = src[y*stride + min(width-1, x+2)];
212123
int F = src[min(height-1, y+1)*stride + x];
213124
int delta;
214-
delta = clpf_sample(X, A, B, C, D, E, F, strength);
125+
delta = TEMPLATE(clpf_sample)(X, A, B, C, D, E, F, strength);
215126
dst[y*stride + x] = X + delta;
216127
}
217128
}
218129
}
219130

220-
void improve_uv_prediction(uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *ry, int n, int cstride, int stride, int sub)
131+
void TEMPLATE(improve_uv_prediction)(SAMPLE *y, SAMPLE *u, SAMPLE *v, SAMPLE *ry, int n, int cstride, int stride, int sub, int bitdepth)
221132
{
222133
int nc = n >> sub;
223134
int lognc = log2i(nc);
@@ -272,11 +183,11 @@ void improve_uv_prediction(uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *ry, int
272183
for (int i = 0; i < nc; i++)
273184
for (int j = 0; j < nc; j++) {
274185
u[i*(cstride >> sub) + j] = sub ?
275-
(clip255((a*ry[(i*2+0)*stride+j*2+0] + b) >> 16) +
276-
clip255((a*ry[(i*2+0)*stride+j*2+1] + b) >> 16) +
277-
clip255((a*ry[(i*2+1)*stride+j*2+0] + b) >> 16) +
278-
clip255((a*ry[(i*2+1)*stride+j*2+1] + b) >> 16) + 2) >> 2 :
279-
clip255((a*ry[i*stride+j] + b) >> 16);
186+
(saturate((a*ry[(i*2+0)*stride+j*2+0] + b) >> 16, bitdepth) +
187+
saturate((a*ry[(i*2+0)*stride+j*2+1] + b) >> 16, bitdepth) +
188+
saturate((a*ry[(i*2+1)*stride+j*2+0] + b) >> 16, bitdepth) +
189+
saturate((a*ry[(i*2+1)*stride+j*2+1] + b) >> 16, bitdepth) + 2) >> 2 :
190+
saturate((a*ry[i*stride+j] + b) >> 16, bitdepth);
280191
}
281192
}
282193
if (ssyv * ssyv * 2 > ssyy * ssvv) {
@@ -289,11 +200,11 @@ void improve_uv_prediction(uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *ry, int
289200
for (int i = 0; i < nc; i++)
290201
for (int j = 0; j < nc; j++) {
291202
v[i*(cstride >> sub) + j] = sub ?
292-
(clip255((a*ry[(i*2+0)*stride+j*2+0] + b) >> 16) +
293-
clip255((a*ry[(i*2+0)*stride+j*2+1] + b) >> 16) +
294-
clip255((a*ry[(i*2+1)*stride+j*2+0] + b) >> 16) +
295-
clip255((a*ry[(i*2+1)*stride+j*2+1] + b) >> 16) + 2) >> 2 :
296-
clip255((a*ry[i*stride+j] + b) >> 16);
203+
(saturate((a*ry[(i*2+0)*stride+j*2+0] + b) >> 16, bitdepth) +
204+
saturate((a*ry[(i*2+0)*stride+j*2+1] + b) >> 16, bitdepth) +
205+
saturate((a*ry[(i*2+1)*stride+j*2+0] + b) >> 16, bitdepth) +
206+
saturate((a*ry[(i*2+1)*stride+j*2+1] + b) >> 16, bitdepth) + 2) >> 2 :
207+
saturate((a*ry[i*stride+j] + b) >> 16, bitdepth);
297208
}
298209
}
299210
}

common/common_block.h

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,60 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
#include "types.h"
3131
#include "simd.h"
3232

33-
int get_left_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size);
34-
int get_up_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size);
35-
int get_upright_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size);
36-
int get_downleft_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size);
33+
void TEMPLATE(dequantize)(int16_t *coeff, int16_t *rcoeff, int qp, int size, qmtx_t * wt_matrix);
34+
void TEMPLATE(reconstruct_block)(int16_t *block, SAMPLE *pblock, SAMPLE *rec, int size, int pstride, int stride, int bitdepth);
3735

38-
void dequantize (int16_t *coeff, int16_t *rcoeff, int qp, int size, qmtx_t * wt_matrix);
39-
void reconstruct_block(int16_t *block, uint8_t *pblock, uint8_t *rec, int size, int pstride, int stride);
36+
void TEMPLATE(find_block_contexts)(int ypos, int xpos, int height, int width, int size, deblock_data_t *deblock_data, block_context_t *block_context, int enable);
4037

41-
void find_block_contexts(int ypos, int xpos, int height, int width, int size, deblock_data_t *deblock_data, block_context_t *block_context, int enable);
38+
void TEMPLATE(clpf_block)(const SAMPLE *src, SAMPLE *dst, int stride, int x0, int y0, int sizex, int sizey, int width, int height, unsigned int strength);
4239

43-
void clpf_block(const uint8_t *src, uint8_t *dst, int stride, int x0, int y0, int sizex, int sizey, int width, int height, unsigned int strength);
40+
int TEMPLATE(clpf_sample)(int X, int A, int B, int C, int D, int E, int F, int b);
4441

45-
int clpf_sample(int X, int A, int B, int C, int D, int E, int F, int b);
42+
void TEMPLATE(improve_uv_prediction)(SAMPLE *y, SAMPLE *u, SAMPLE *v, SAMPLE *ry, int n, int cstride, int stride, int sub, int bitdepth);
4643

47-
void improve_uv_prediction(uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *ry, int n, int cstride, int stride, int sub);
44+
SIMD_INLINE int get_left_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
45+
return xpos > 0;
46+
}
47+
48+
SIMD_INLINE int get_up_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
49+
return ypos > 0;
50+
}
51+
52+
SIMD_INLINE int get_upright_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
53+
54+
int upright_available;
55+
int size, size2;
56+
57+
/* Test for frame boundaries */
58+
upright_available = (ypos > 0) && (xpos + bwidth < fwidth);
59+
60+
/* Test for coding block boundaries */
61+
size = max(bwidth, bheight);
62+
for (size2 = size; size2 < sb_size; size2 *= 2) {
63+
if ((ypos % (size2 << 1)) == size2 && (xpos % size2) == (size2 - size)) upright_available = 0;
64+
}
65+
return upright_available;
66+
}
67+
68+
SIMD_INLINE int get_downleft_available(int ypos, int xpos, int bwidth, int bheight, int fwidth, int fheight, int sb_size) {
69+
70+
int downleft_available;
71+
int size, size2;
72+
73+
/* Test for frame boundaries */
74+
downleft_available = (xpos > 0) && (ypos + bheight < fheight);
75+
76+
size = max(bwidth, bheight);
77+
/* Test for external super block boundaries */
78+
if ((ypos % sb_size) == (sb_size - size) && (xpos % sb_size) == 0) downleft_available = 0;
79+
80+
/* Test for coding block boundaries */
81+
size = max(bwidth, bheight);
82+
for (size2 = 2 * size; size2 <= sb_size; size2 *= 2) {
83+
if ((ypos % size2) == (size2 - size) && (xpos % size2) > 0) downleft_available = 0;
84+
}
85+
86+
return downleft_available;
87+
}
4888

4989
#endif

0 commit comments

Comments
 (0)