mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:37:36 +00:00
LibVideo/VP9: Create Vector2DView to limit writable ranges of contexts
This commit is contained in:
parent
9da432f4d6
commit
448a8b8efb
1 changed files with 61 additions and 1 deletions
|
@ -42,6 +42,59 @@ struct Pair {
|
||||||
typedef Pair<ReferenceFrameType> ReferenceFramePair;
|
typedef Pair<ReferenceFrameType> ReferenceFramePair;
|
||||||
typedef Pair<MotionVector> MotionVectorPair;
|
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>
|
template<typename T>
|
||||||
class Vector2D {
|
class Vector2D {
|
||||||
public:
|
public:
|
||||||
|
@ -126,6 +179,13 @@ public:
|
||||||
m_storage[i] = T();
|
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:
|
private:
|
||||||
u32 m_height { 0 };
|
u32 m_height { 0 };
|
||||||
u32 m_width { 0 };
|
u32 m_width { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue