diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.cpp b/Userland/Libraries/LibVideo/VP9/Decoder.cpp index a58526c0ae..1a88774f22 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.cpp +++ b/Userland/Libraries/LibVideo/VP9/Decoder.cpp @@ -1400,7 +1400,7 @@ inline DecoderErrorOr Decoder::inverse_discrete_cosine_transform_array_per // 1.2. T[ i ] is set equal to copyT[ brev( n, i ) ] for i = 0..((1<(i)]; return {}; } @@ -1432,7 +1432,7 @@ inline DecoderErrorOr Decoder::inverse_discrete_cosine_transform(Span(index), false); } // 2.7 If n is greater than or equal to 3: diff --git a/Userland/Libraries/LibVideo/VP9/Utilities.h b/Userland/Libraries/LibVideo/VP9/Utilities.h index ff79929fa9..726331e05b 100644 --- a/Userland/Libraries/LibVideo/VP9/Utilities.h +++ b/Userland/Libraries/LibVideo/VP9/Utilities.h @@ -34,15 +34,26 @@ u16 clip_1(u8 bit_depth, T x) return x; } -template -inline T brev(C bit_count, T value) +template +inline u8 brev(u8 value) { - T result = 0; - for (C i = 0; i < bit_count; i++) { - auto bit = (value >> i) & 1; - result |= bit << (bit_count - 1 - i); - } - return result; + static_assert(bits <= 8, "brev() expects an 8-bit value."); + + static constexpr auto lookup_table = [] { + constexpr size_t value_count = 1 << bits; + Array the_table; + for (u8 lookup_value = 0; lookup_value < value_count; lookup_value++) { + u8 reversed = 0; + for (u8 bit_index = 0; bit_index < bits; bit_index++) { + auto bit = (lookup_value >> bit_index) & 1; + reversed |= bit << (bits - 1 - bit_index); + } + the_table[lookup_value] = reversed; + } + return the_table; + }(); + + return lookup_table[value]; } inline BlockSubsize get_subsampled_block_size(BlockSubsize size, bool subsampling_x, bool subsampling_y)