ladybird/Userland/Libraries/LibMedia/Subsampling.h
Zaggy1024 40fe0cb9d5 LibMedia: Store YUV planes as byte arrays with no padding for 8-bit
This should halve the size of frames in memory for frames with 8-bit
color components, which is the majority of videos.

Calculation of the size of subsampled planes has also been consolidated
into a struct. There are likely some places that will still need to
change over to this, but it should prevent issues due to differing
handling of rounding/ceiling.
2024-06-24 12:41:32 -06:00

47 lines
859 B
C++

/*
* Copyright (c) 2024, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/Size.h>
namespace Media {
struct Subsampling {
public:
Subsampling(bool x, bool y)
: m_x(x)
, m_y(y)
{
}
Subsampling() = default;
bool x() const { return m_x; }
bool y() const { return m_y; }
static u32 subsampled_size(bool subsampled, u32 size)
{
u32 subsampled_as_int = static_cast<u32>(subsampled);
return (size + subsampled_as_int) >> subsampled_as_int;
}
template<Integral T>
Gfx::Size<T> subsampled_size(Gfx::Size<T> size) const
{
return {
subsampled_size(x(), size.width()),
subsampled_size(y(), size.height())
};
}
private:
bool m_x = false;
bool m_y = false;
};
}