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
9595 }
9696 #endif
9797
98−void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
98+void put_rac_internal(inout RangeCoder c, const int range1, bool bit)
9999 {
100− int range1 = uint16_t((c.range * state) >> 8);
101−
102100 #ifdef DEBUG
103− if (state == 0)
104− debugPrintfEXT("Error: state is zero");
105101 if (range1 >= c.range)
106102 debugPrintfEXT("Error: range1 >= c.range");
107103 if (range1 <= 0)
108104 debugPrintfEXT("Error: range1 <= 0");
109105 #endif
110106
111− int diff = c.range - range1;
112− c.low += bit ? diff : 0;
113− c.range = bit ? range1 : diff;
107+ int ranged = c.range - range1;
108+ c.low += bit ? ranged : 0;
109+ c.range = bit ? range1 : ranged;
114110
115111 if (expectEXT(c.range < 0x100, false))
116112 renorm_encoder(c);
113+}
117114
115+void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
116+{
117+ put_rac_internal(c, (c.range * state) >> 8, bit);
118118 state = zero_one_state[(uint(bit) << 8) + state];
119119 }
120120
@@ -126,21 +126,7 @@ void put_rac(inout RangeCoder c, uint64_t state, bool bit) · 5 unmodified lines
126126 /* Equiprobable bit */
127127 void put_rac_equi(inout RangeCoder c, bool bit)
128128 {
129− int range1 = c.range >> 1;
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);
129+ put_rac_internal(c, c.range >> 1, bit);
144130 }
145131
146132 void put_rac_terminate(inout RangeCoder c)
@@ -224,11 +210,9 @@ void refill(inout RangeCoder c) · 77 unmodified lines
224210 }
225211 }
226212
227−bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
213+bool get_rac_internal(inout RangeCoder c, const int range1)
228214 {
229− int range1 = c.range * state >> 8;
230215 int ranged = c.range - range1;
231−
232216 bool bit = c.low >= ranged;
233217 c.low -= bit ? ranged : 0;
234218 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
236220 if (expectEXT(c.range < 0x100, false))
237221 refill(c);
238222
223+ return bit;
224+}
225+
226+bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
227+{
228+ bool bit = get_rac_internal(c, c.range * state >> 8);
239229 state = zero_one_state[state + (bit ? 256 : 0)];
240230 return bit;
241231 }
@@ -247,18 +237,5 @@ bool get_rac(inout RangeCoder c, uint64_t state) · 5 unmodified lines
247237
248238 bool get_rac_equi(inout RangeCoder c)
249239 {
250− int range1 = 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;
240+ return get_rac_internal(c, c.range >> 1);
264241 }

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