shithub: libvpx

Download patch

ref: f08581c1d010ea95b8cfae686b5c0a64b32519f9
parent: de4cb716eea72a4daf6b0aff8c3ea51890a4afba
author: Johann <johannkoenig@google.com>
date: Tue Jun 6 08:58:15 EDT 2017

buffer.h: use size_t

Change-Id: Ieca3f1ef23cd1d7b844ea3ecb054007ed280b04f

--- a/test/buffer.h
+++ b/test/buffer.h
@@ -25,13 +25,13 @@
 template <typename T>
 class Buffer {
  public:
-  Buffer(int width, int height, int top_padding, int left_padding,
-         int right_padding, int bottom_padding)
+  Buffer(size_t width, size_t height, size_t top_padding, size_t left_padding,
+         size_t right_padding, size_t bottom_padding)
       : width_(width), height_(height), top_padding_(top_padding),
         left_padding_(left_padding), right_padding_(right_padding),
         bottom_padding_(bottom_padding), raw_buffer_(NULL) {}
 
-  Buffer(int width, int height, int padding)
+  Buffer(size_t width, size_t height, size_t padding)
       : width_(width), height_(height), top_padding_(padding),
         left_padding_(padding), right_padding_(padding),
         bottom_padding_(padding), raw_buffer_(NULL) {}
@@ -40,7 +40,7 @@
 
   T *TopLeftPixel() const;
 
-  int stride() const { return stride_; }
+  size_t stride() const { return stride_; }
 
   // Set the buffer (excluding padding) to 'value'.
   void Set(const T value);
@@ -72,12 +72,8 @@
   bool CheckValues(const Buffer<T> &a) const;
 
   bool Init() {
-    EXPECT_GT(width_, 0);
-    EXPECT_GT(height_, 0);
-    EXPECT_GE(top_padding_, 0);
-    EXPECT_GE(left_padding_, 0);
-    EXPECT_GE(right_padding_, 0);
-    EXPECT_GE(bottom_padding_, 0);
+    EXPECT_GT(width_, 0u);
+    EXPECT_GT(height_, 0u);
     stride_ = left_padding_ + width_ + right_padding_;
     raw_size_ = stride_ * (top_padding_ + height_ + bottom_padding_);
     raw_buffer_ = new (std::nothrow) T[raw_size_];
@@ -89,15 +85,15 @@
  private:
   bool BufferSizesMatch(const Buffer<T> &a) const;
 
-  const int width_;
-  const int height_;
-  const int top_padding_;
-  const int left_padding_;
-  const int right_padding_;
-  const int bottom_padding_;
+  const size_t width_;
+  const size_t height_;
+  const size_t top_padding_;
+  const size_t left_padding_;
+  const size_t right_padding_;
+  const size_t bottom_padding_;
   T padding_value_;
-  int stride_;
-  int raw_size_;
+  size_t stride_;
+  size_t raw_size_;
   T *raw_buffer_;
 };
 
@@ -111,8 +107,8 @@
 void Buffer<T>::Set(const T value) {
   if (!raw_buffer_) return;
   T *src = TopLeftPixel();
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       src[width] = value;
     }
     src += stride();
@@ -123,8 +119,8 @@
 void Buffer<T>::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) {
   if (!raw_buffer_) return;
   T *src = TopLeftPixel();
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       src[width] = (*rand_class.*rand_func)();
     }
     src += stride();
@@ -138,8 +134,8 @@
 
   T *a_src = a.TopLeftPixel();
   T *b_src = this->TopLeftPixel();
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       b_src[width] = a_src[width];
     }
     a_src += a.stride();
@@ -150,9 +146,9 @@
 template <typename T>
 void Buffer<T>::DumpBuffer() const {
   if (!raw_buffer_) return;
-  for (int height = 0; height < height_ + top_padding_ + bottom_padding_;
+  for (size_t height = 0; height < height_ + top_padding_ + bottom_padding_;
        ++height) {
-    for (int width = 0; width < stride(); ++width) {
+    for (size_t width = 0; width < stride(); ++width) {
       printf("%4d", raw_buffer_[height + width * stride()]);
     }
     printf("\n");
@@ -174,8 +170,8 @@
   T *b_src = TopLeftPixel();
 
   printf("This buffer:\n");
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       if (a_src[width] != b_src[width]) {
         printf("*%3d", b_src[width]);
       } else {
@@ -191,8 +187,8 @@
   b_src = TopLeftPixel();
 
   printf("Reference buffer:\n");
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       if (a_src[width] != b_src[width]) {
         printf("*%3d", a_src[width]);
       } else {
@@ -211,7 +207,7 @@
   padding_value_ = padding_value;
 
   T *src = raw_buffer_;
-  for (int i = 0; i < raw_size_; ++i) {
+  for (size_t i = 0; i < raw_size_; ++i) {
     src[i] = padding_value;
   }
 }
@@ -220,8 +216,8 @@
 bool Buffer<T>::CheckValues(const T value) const {
   if (!raw_buffer_) return false;
   T *src = TopLeftPixel();
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       if (value != src[width]) {
         return false;
       }
@@ -238,7 +234,7 @@
 
   // Top padding.
   T const *top = raw_buffer_;
-  for (int i = 0; i < stride() * top_padding_; ++i) {
+  for (size_t i = 0; i < stride() * top_padding_; ++i) {
     if (padding_value_ != top[i]) {
       return false;
     }
@@ -246,8 +242,8 @@
 
   // Left padding.
   T const *left = TopLeftPixel() - left_padding_;
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < left_padding_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < left_padding_; ++width) {
       if (padding_value_ != left[width]) {
         return false;
       }
@@ -257,8 +253,8 @@
 
   // Right padding.
   T const *right = TopLeftPixel() + width_;
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < right_padding_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < right_padding_; ++width) {
       if (padding_value_ != right[width]) {
         return false;
       }
@@ -268,7 +264,7 @@
 
   // Bottom padding
   T const *bottom = raw_buffer_ + (top_padding_ + height_) * stride();
-  for (int i = 0; i < stride() * bottom_padding_; ++i) {
+  for (size_t i = 0; i < stride() * bottom_padding_; ++i) {
     if (padding_value_ != bottom[i]) {
       return false;
     }
@@ -284,8 +280,8 @@
 
   T *a_src = a.TopLeftPixel();
   T *b_src = this->TopLeftPixel();
-  for (int height = 0; height < height_; ++height) {
-    for (int width = 0; width < width_; ++width) {
+  for (size_t height = 0; height < height_; ++height) {
+    for (size_t width = 0; width < width_; ++width) {
       if (a_src[width] != b_src[width]) {
         return false;
       }
@@ -301,8 +297,8 @@
   if (!raw_buffer_) return false;
   if (a.width_ != this->width_ || a.height_ != this->height_) {
     printf(
-        "Reference buffer of size %dx%d does not match this buffer which is "
-        "size %dx%d\n",
+        "Reference buffer of size %zux%zu does not match this buffer which is "
+        "size %zux%zu\n",
         a.width_, a.height_, this->width_, this->height_);
     return false;
   }