summaryrefslogtreecommitdiff
path: root/vp8/encoder/sad_c.c
diff options
context:
space:
mode:
authorJohann <johannkoenig@google.com>2012-01-27 11:44:01 -0800
committerJohann <johannkoenig@google.com>2012-02-16 15:17:44 -0800
commit6b151d436d490dee423a38b42b7bab8832bd60fa (patch)
treea5d550e058a90311329294fe5849ec9e4dde5811 /vp8/encoder/sad_c.c
parent3653fb473a66258c74d3a550e66c8c1e8f95368c (diff)
downloadlibvpx-6b151d436d490dee423a38b42b7bab8832bd60fa.tar
libvpx-6b151d436d490dee423a38b42b7bab8832bd60fa.tar.gz
libvpx-6b151d436d490dee423a38b42b7bab8832bd60fa.tar.bz2
libvpx-6b151d436d490dee423a38b42b7bab8832bd60fa.zip
Clarify 'max_sad' usage
Depending on implementation the optimized SAD functions may return early when the calculated SAD exceeds max_sad. Change-Id: I05ce5b2d34e6d45fb3ec2a450aa99c4f3343bf3a
Diffstat (limited to 'vp8/encoder/sad_c.c')
-rw-r--r--vp8/encoder/sad_c.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/vp8/encoder/sad_c.c b/vp8/encoder/sad_c.c
index 3b6e26c4e..f745bbd3d 100644
--- a/vp8/encoder/sad_c.c
+++ b/vp8/encoder/sad_c.c
@@ -13,24 +13,30 @@
#include "vpx_config.h"
#include "vpx/vpx_integer.h"
-unsigned int vp8_sad16x16_c(
+static __inline
+unsigned int sad_mx_n_c(
const unsigned char *src_ptr,
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int max_sad)
+ int max_sad,
+ int m,
+ int n)
{
int r, c;
unsigned int sad = 0;
- for (r = 0; r < 16; r++)
+ for (r = 0; r < n; r++)
{
- for (c = 0; c < 16; c++)
+ for (c = 0; c < m; c++)
{
sad += abs(src_ptr[c] - ref_ptr[c]);
}
+ if (sad > max_sad)
+ break;
+
src_ptr += src_stride;
ref_ptr += ref_stride;
}
@@ -38,32 +44,19 @@ unsigned int vp8_sad16x16_c(
return sad;
}
+/* max_sad is provided as an optional optimization point. Alternative
+ * implementations of these functions are not required to check it.
+ */
-static __inline
-unsigned int sad_mx_n_c(
+unsigned int vp8_sad16x16_c(
const unsigned char *src_ptr,
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int m,
- int n)
+ int max_sad)
{
- int r, c;
- unsigned int sad = 0;
-
- for (r = 0; r < n; r++)
- {
- for (c = 0; c < m; c++)
- {
- sad += abs(src_ptr[c] - ref_ptr[c]);
- }
-
- src_ptr += src_stride;
- ref_ptr += ref_stride;
- }
-
- return sad;
+ return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, max_sad, 16, 16);
}
@@ -72,10 +65,10 @@ unsigned int vp8_sad8x8_c(
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int max_sad)
+ int max_sad)
{
- return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 8, 8);
+ return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, max_sad, 8, 8);
}
@@ -84,10 +77,10 @@ unsigned int vp8_sad16x8_c(
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int max_sad)
+ int max_sad)
{
- return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 16, 8);
+ return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, max_sad, 16, 8);
}
@@ -97,10 +90,10 @@ unsigned int vp8_sad8x16_c(
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int max_sad)
+ int max_sad)
{
- return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 8, 16);
+ return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, max_sad, 8, 16);
}
@@ -109,10 +102,10 @@ unsigned int vp8_sad4x4_c(
int src_stride,
const unsigned char *ref_ptr,
int ref_stride,
- int max_sad)
+ int max_sad)
{
- return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, 4, 4);
+ return sad_mx_n_c(src_ptr, src_stride, ref_ptr, ref_stride, max_sad, 4, 4);
}
void vp8_sad16x16x3_c(