mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibVideo/VP9: Create Vector2DView to limit writable ranges of contexts
This commit is contained in:
parent
9da432f4d6
commit
448a8b8efb
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/SerenityOS/serenity/commit/448a8b8efb Pull-request: https://github.com/SerenityOS/serenity/pull/16238
|
@ -42,6 +42,59 @@ struct Pair {
|
|||
typedef Pair<ReferenceFrameType> ReferenceFramePair;
|
||||
typedef Pair<MotionVector> MotionVectorPair;
|
||||
|
||||
template<typename T>
|
||||
class Vector2D;
|
||||
|
||||
template<typename T>
|
||||
class Vector2DView {
|
||||
public:
|
||||
u32 top() const { return m_top; }
|
||||
u32 left() const { return m_left; }
|
||||
u32 height() const { return m_height; }
|
||||
u32 width() const { return m_width; }
|
||||
|
||||
T const& operator[](size_t index) const { return m_storage[index]; }
|
||||
size_t size() const { return m_storage->size(); }
|
||||
|
||||
T& at(u32 relative_row, u32 relative_column)
|
||||
{
|
||||
VERIFY(relative_row < height());
|
||||
VERIFY(relative_column < width());
|
||||
return m_storage->at(top() + relative_row, left() + relative_column);
|
||||
}
|
||||
T const& at(u32 relative_row, u32 relative_column) const
|
||||
{
|
||||
VERIFY(relative_row < height());
|
||||
VERIFY(relative_column < width());
|
||||
return m_storage->at(top() + relative_row, left() + relative_column);
|
||||
}
|
||||
|
||||
Vector2DView<T> view(u32 top, u32 left, u32 height, u32 width)
|
||||
{
|
||||
VERIFY(top + height <= this->height());
|
||||
VERIFY(left + width <= this->width());
|
||||
return Vector2DView<T>(m_storage, this->top() + top, this->left() + left, height, width);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Vector2D<T>;
|
||||
|
||||
Vector2DView(Vector2D<T>* const storage, u32 top, u32 left, u32 height, u32 width)
|
||||
: m_storage(storage)
|
||||
, m_top(top)
|
||||
, m_left(left)
|
||||
, m_height(height)
|
||||
, m_width(width)
|
||||
{
|
||||
}
|
||||
|
||||
Vector2D<T>* const m_storage;
|
||||
u32 const m_top { 0 };
|
||||
u32 const m_left { 0 };
|
||||
u32 const m_height { 0 };
|
||||
u32 const m_width { 0 };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Vector2D {
|
||||
public:
|
||||
|
@ -72,7 +125,7 @@ public:
|
|||
|
||||
u32 height() const { return m_height; }
|
||||
u32 width() const { return m_width; }
|
||||
|
||||
|
||||
size_t index_at(u32 row, u32 column) const
|
||||
{
|
||||
VERIFY(row < height());
|
||||
|
@ -126,6 +179,13 @@ public:
|
|||
m_storage[i] = T();
|
||||
}
|
||||
|
||||
Vector2DView<T> view(u32 top, u32 left, u32 height, u32 width)
|
||||
{
|
||||
VERIFY(top + height <= this->height());
|
||||
VERIFY(left + width <= this->width());
|
||||
return Vector2DView<T>(this, top, left, height, width);
|
||||
}
|
||||
|
||||
private:
|
||||
u32 m_height { 0 };
|
||||
u32 m_width { 0 };
|
||||
|
|
Loading…
Reference in a new issue