History

vulkan/ffv1: unify encode and decode get/put primitives

This simply makes a get_rac/put_rac_internal variant that can be reused.

Lynne committed 1 year ago

Commit cb8f4b61 parent 75764101 file · +17 −40Browse files

Unified · Split

libavcodec/vulkan/rangecoder.comp+17−40
@@ -95,26 +95,26 @@ void renorm_encoder(inout RangeCoder c) · 94 unmodified lines
95}95}
96#endif96#endif
97 97
98void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)98void put_rac_internal(inout RangeCoder c, const int range1, bool bit)
99{99{
100 int range1 = uint16_t((c.range * state) >> 8);
101
102#ifdef DEBUG100#ifdef DEBUG
103 if (state == 0)
104 debugPrintfEXT("Error: state is zero");
105 if (range1 >= c.range)101 if (range1 >= c.range)
106 debugPrintfEXT("Error: range1 >= c.range");102 debugPrintfEXT("Error: range1 >= c.range");
107 if (range1 <= 0)103 if (range1 <= 0)
108 debugPrintfEXT("Error: range1 <= 0");104 debugPrintfEXT("Error: range1 <= 0");
109#endif105#endif
110 106
111 int diff = c.range - range1;107 int ranged = c.range - range1;
112 c.low += bit ? diff : 0;108 c.low += bit ? ranged : 0;
113 c.range = bit ? range1 : diff;109 c.range = bit ? range1 : ranged;
114 110
115 if (expectEXT(c.range < 0x100, false))111 if (expectEXT(c.range < 0x100, false))
116 renorm_encoder(c);112 renorm_encoder(c);
113}
117 114
115void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
116{
117 put_rac_internal(c, (c.range * state) >> 8, bit);
118 state = zero_one_state[(uint(bit) << 8) + state];118 state = zero_one_state[(uint(bit) << 8) + state];
119}119}
120 120
@@ -126,21 +126,7 @@ void put_rac(inout RangeCoder c, uint64_t state, bool bit) · 5 unmodified lines
126/* Equiprobable bit */126/* Equiprobable bit */
127void put_rac_equi(inout RangeCoder c, bool bit)127void put_rac_equi(inout RangeCoder c, bool bit)
128{128{
129 int range1 = c.range >> 1;129 put_rac_internal(c, c.range >> 1, bit);
130
131#ifdef DEBUG
132 if (range1 >= c.range)
133 debugPrintfEXT("Error: range1 >= c.range");
134 if (range1 <= 0)
135 debugPrintfEXT("Error: range1 <= 0");
136#endif
137
138 int diff = c.range - range1;
139 c.low += bit ? diff : 0;
140 c.range = bit ? range1 : diff;
141
142 if (expectEXT(c.range < 0x100, false))
143 renorm_encoder(c);
144}130}
145 131
146void put_rac_terminate(inout RangeCoder c)132void put_rac_terminate(inout RangeCoder c)
@@ -224,11 +210,9 @@ void refill(inout RangeCoder c) · 77 unmodified lines
224 }210 }
225}211}
226 212
227bool get_rac_direct(inout RangeCoder c, inout uint8_t state)213bool get_rac_internal(inout RangeCoder c, const int range1)
228{214{
229 int range1 = c.range * state >> 8;
230 int ranged = c.range - range1;215 int ranged = c.range - range1;
231
232 bool bit = c.low >= ranged;216 bool bit = c.low >= ranged;
233 c.low -= bit ? ranged : 0;217 c.low -= bit ? ranged : 0;
234 c.range = (bit ? 0 : ranged) + (bit ? range1 : 0);218 c.range = (bit ? 0 : ranged) + (bit ? range1 : 0);
@@ -236,6 +220,12 @@ bool get_rac_direct(inout RangeCoder c, inout uint8_t state) · 1 unmodified line
236 if (expectEXT(c.range < 0x100, false))220 if (expectEXT(c.range < 0x100, false))
237 refill(c);221 refill(c);
238 222
223 return bit;
224}
225
226bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
227{
228 bool bit = get_rac_internal(c, c.range * state >> 8);
239 state = zero_one_state[state + (bit ? 256 : 0)];229 state = zero_one_state[state + (bit ? 256 : 0)];
240 return bit;230 return bit;
241}231}
@@ -247,18 +237,5 @@ bool get_rac(inout RangeCoder c, uint64_t state) · 5 unmodified lines
247 237
248bool get_rac_equi(inout RangeCoder c)238bool get_rac_equi(inout RangeCoder c)
249{239{
250 int range1 = c.range >> 1;240 return get_rac_internal(c, c.range >> 1);
251
252 c.range -= range1;
253
254 bool bit = c.low >= c.range;
255 if (bit) {
256 c.low -= c.range;
257 c.range = range1;
258 }
259
260 if (expectEXT(c.range < 0x100, false))
261 refill(c);
262
263 return bit;
264}241}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t