shithub: libvpx

Download patch

ref: 3e9e77008c631091c9b6ee51d03b414c334e6480
parent: 113f9721d144a1a143a77036db97549b73c66fe9
author: paulwilkins <[email protected]>
date: Thu Sep 1 06:01:33 EDT 2016

Casts to remove some warnings.

Added casts to remove warnings:
BUG=webm:1274

In regards to the safety of these casts they are of two types:-

- Normalized bits per (16x16) MB stored in a 32 bit int (This is safe as bits
per MB even with << 9 normalization cant overflow 32 bits. Even raw 12
bits hdr source even would only be  29 bits :- (4+4+12+9) and the encoder
imposes much stricter limits than this on max bit rate.

- Cast as part of variance calculations.  There is an internal cast up to 64 bit
for the Sum X Sum calculation, but after normalization dividing by the number
of points the result will always be <= the SSE value.

Change-Id: I4e700236ed83d6b2b1955e92e84c3b1978b9eaa0

--- a/vp9/encoder/vp9_aq_variance.c
+++ b/vp9/encoder/vp9_aq_variance.c
@@ -166,7 +166,7 @@
     aq_variance(x->plane[0].src.buf, x->plane[0].src.stride, vp9_64_zeros, 0,
                 bw, bh, &sse, &avg);
 #endif  // CONFIG_VP9_HIGHBITDEPTH
-    var = sse - (((int64_t)avg * avg) / (bw * bh));
+    var = sse - (unsigned int)(((int64_t)avg * avg) / (bw * bh));
     return (unsigned int)(((uint64_t)256 * var) / (bw * bh));
   } else {
 #if CONFIG_VP9_HIGHBITDEPTH
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1788,7 +1788,10 @@
           d32[i].sum += d16[j]->sum;
         }
 
-        d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10);
+        d32[i].var =
+            (unsigned int)(d32[i].sse -
+                           (unsigned int)(((int64_t)d32[i].sum * d32[i].sum) >>
+                                          10));
 
         index = coord_lookup[i * 4].row * mis + coord_lookup[i * 4].col;
         mi_8x8[index] = mi_upper_left + index;
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -1388,7 +1388,7 @@
     const double speed_term = 1.0 + 0.04 * oxcf->speed;
     double last_group_rate_err;
     const int target_norm_bits_per_mb =
-        ((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs;
+        (int)(((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs);
     int q;
     int is_svc_upper_layer = 0;
 
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -336,7 +336,7 @@
                  cpi->common.use_highbitdepth, bd,
 #endif
                  sse8x8, sum8x8, var8x8);
-  var = sse - (((int64_t)sum * sum) >> (bw + bh + 4));
+  var = sse - (unsigned int)(((int64_t)sum * sum) >> (bw + bh + 4));
 
   *var_y = var;
   *sse_y = sse;
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -529,7 +529,7 @@
   // Calculate required scaling factor based on target frame size and size of
   // frame produced using previous Q.
   target_bits_per_mb =
-      ((uint64_t)target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs;
+      (int)(((uint64_t)target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs);
 
   i = active_best_quality;
 
@@ -1253,8 +1253,8 @@
                                   rate_thresh_mult[rc->frame_size_selector]);
 
   // Target rate per SB64 (including partial SB64s.
-  rc->sb64_target_rate =
-      ((int64_t)rc->this_frame_target * 64 * 64) / (cm->width * cm->height);
+  rc->sb64_target_rate = (int)(((int64_t)rc->this_frame_target * 64 * 64) /
+                               (cm->width * cm->height));
 }
 
 static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
@@ -2322,7 +2322,8 @@
     cpi->rc.rc_1_frame = 0;
     cpi->rc.rc_2_frame = 0;
     // Adjust rate correction factor.
-    target_bits_per_mb = ((uint64_t)target_size << BPER_MB_NORMBITS) / cm->MBs;
+    target_bits_per_mb =
+        (int)(((uint64_t)target_size << BPER_MB_NORMBITS) / cm->MBs);
     // Rate correction factor based on target_bits_per_mb and qp (==max_QP).
     // This comes from the inverse computation of vp9_rc_bits_per_mb().
     q2 = vp9_convert_qindex_to_q(*q, cm->bit_depth);