@@ -35,6 +35,9 @@ template <class T> class Array2DRef final {
3535 Array1DRef<T> data;
3636 int _pitch;
3737
38+ int _width;
39+ int _height;
40+
3841 friend Array2DRef<const T>; // We need to be able to convert to const version.
3942
4043 // We need to be able to convert to std::byte.
@@ -49,8 +52,8 @@ template <class T> class Array2DRef final {
4952 using value_type = T;
5053 using cvless_value_type = std::remove_cv_t <value_type>;
5154
52- int width;
53- int height;
55+ [[nodiscard]] int RAWSPEED_READONLY width () const ;
56+ [[nodiscard]] int RAWSPEED_READONLY height () const ;
5457
5558 Array2DRef () = delete ;
5659
@@ -75,8 +78,8 @@ template <class T> class Array2DRef final {
7578 requires (!std::is_const_v<T2> && std::is_const_v<T> &&
7679 std::is_same_v<std::remove_const_t <T>, std::remove_const_t <T2>>)
7780 Array2DRef (Array2DRef<T2> RHS) // NOLINT google-explicit-constructor
78- : data(RHS.data), _pitch(RHS._pitch), width (RHS.width),
79- height (RHS.height) {}
81+ : data(RHS.data), _pitch(RHS._pitch), _width (RHS.width() ),
82+ _height (RHS.height() ) {}
8083
8184 // Const-preserving conversion from Array2DRef<T> to Array2DRef<std::byte>.
8285 template <typename T2>
@@ -86,7 +89,7 @@ template <class T> class Array2DRef final {
8689 std::is_same_v<std::remove_const_t<T>, std::byte>)
8790 Array2DRef(Array2DRef<T2> RHS) // NOLINT google-explicit-constructor
8891 : data(RHS.data), _pitch(sizeof (T2) * RHS._pitch),
89- width (sizeof (T2) * RHS.width), height (RHS.height) {}
92+ _width (sizeof (T2) * RHS.width()), _height (RHS.height() ) {}
9093
9194 template <typename AllocatorType =
9295 typename std::vector<cvless_value_type>::allocator_type>
@@ -121,19 +124,19 @@ explicit Array2DRef(T* data, int width, int height) -> Array2DRef<T>;
121124template <class T >
122125inline void Array2DRef<T>::establishClassInvariants() const noexcept {
123126 data.establishClassInvariants ();
124- invariant (width >= 0 );
125- invariant (height >= 0 );
127+ invariant (_width >= 0 );
128+ invariant (_height >= 0 );
126129 invariant (_pitch != 0 );
127130 invariant (_pitch >= 0 );
128- invariant (_pitch >= width );
129- invariant ((width == 0 ) == (height == 0 ));
130- invariant (data.size () == _pitch * height );
131+ invariant (_pitch >= _width );
132+ invariant ((_width == 0 ) == (_height == 0 ));
133+ invariant (data.size () == _pitch * _height );
131134}
132135
133136template <class T >
134137Array2DRef<T>::Array2DRef(Array1DRef<T> data_, const int width_,
135138 const int height_, const int pitch_)
136- : data(data_), _pitch(pitch_), width (width_), height (height_) {
139+ : data(data_), _pitch(pitch_), _width (width_), _height (height_) {
137140 establishClassInvariants ();
138141}
139142
@@ -150,28 +153,38 @@ Array2DRef<T>::Array2DRef(T* data_, const int width_, const int height_)
150153 establishClassInvariants ();
151154}
152155
156+ template <class T > inline int Array2DRef<T>::width() const {
157+ establishClassInvariants ();
158+ return _width;
159+ }
160+
161+ template <class T > inline int Array2DRef<T>::height() const {
162+ establishClassInvariants ();
163+ return _height;
164+ }
165+
153166template <class T >
154167[[nodiscard]] inline Optional<Array1DRef<T>>
155168Array2DRef<T>::getAsArray1DRef() const {
156169 establishClassInvariants ();
157- if (height == 1 || _pitch == width)
158- return data.getCrop (/* offset=*/ 0 , width * height).getAsArray1DRef ();
170+ if (height () == 1 || _pitch == width () )
171+ return data.getCrop (/* offset=*/ 0 , width () * height () ).getAsArray1DRef ();
159172 return std::nullopt ;
160173}
161174
162175template <class T >
163176inline Array1DRef<T> Array2DRef<T>::operator [](const int row) const {
164177 establishClassInvariants ();
165178 invariant (row >= 0 );
166- invariant (row < height);
167- return data.getCrop (row * _pitch, width).getAsArray1DRef ();
179+ invariant (row < height () );
180+ return data.getCrop (row * _pitch, width () ).getAsArray1DRef ();
168181}
169182
170183template <class T >
171184inline T& Array2DRef<T>::operator ()(const int row, const int col) const {
172185 establishClassInvariants ();
173186 invariant (col >= 0 );
174- invariant (col < width);
187+ invariant (col < width () );
175188 return (operator [](row))(col);
176189}
177190
0 commit comments