1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 13:27:35 +00:00
serenity/Userland/Libraries/LibVideo/VP9/Utilities.h
Zaggy1024 1514004cd5 LibVideo: Implement VP9 intra-predicted frame decoding
The first keyframe of the test video can be decoded with these changes.

Raw memory allocations in the Parser have been replaced with Vector or
Array to avoid memory leaks and OOBs.
2022-10-09 20:32:40 -06:00

45 lines
857 B
C++

/*
* Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
namespace Video::VP9 {
// FIXME: Once everything is working, replace this with plain clamp
// since parameter order is different
template<typename T>
T clip_3(T x, T y, T z)
{
return clamp(z, x, y);
}
template<typename T>
u16 clip_1(u8 bit_depth, T x)
{
if (x < 0) {
return 0u;
}
const T max = (1u << bit_depth) - 1u;
if (x > max)
return max;
return x;
}
template<typename T, typename C>
inline T brev(C bit_count, T 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;
}
}