aboutsummaryrefslogtreecommitdiff
path: root/test/md5_helper.h
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 01:00:21 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 01:00:21 +0000
commitcb5526c7a09d1331121c4744f2b16a96bb6b94fe (patch)
tree07ff61be1997ddb98e63873efbd5cf4ebc49b564 /test/md5_helper.h
parentbc32b2800abbc7d1c48ae1935dc29d9bea4f7a59 (diff)
parentb7a44fbd3115e10226e7f10d3ceee7b8b53f3d2a (diff)
downloadlibvpx-cb5526c7a09d1331121c4744f2b16a96bb6b94fe.tar.gz
Snap for 10447354 from b7a44fbd3115e10226e7f10d3ceee7b8b53f3d2a to mainline-cellbroadcast-releaseaml_cbr_341311010aml_cbr_341110000aml_cbr_341011000aml_cbr_340914000
Change-Id: Id4326f426a551e151b125673d642ed4bb9730273
Diffstat (limited to 'test/md5_helper.h')
-rw-r--r--test/md5_helper.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/md5_helper.h b/test/md5_helper.h
new file mode 100644
index 000000000..9095d96a8
--- /dev/null
+++ b/test/md5_helper.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_TEST_MD5_HELPER_H_
+#define VPX_TEST_MD5_HELPER_H_
+
+#include "./md5_utils.h"
+#include "vpx/vpx_decoder.h"
+
+namespace libvpx_test {
+class MD5 {
+ public:
+ MD5() { MD5Init(&md5_); }
+
+ void Add(const vpx_image_t *img) {
+ for (int plane = 0; plane < 3; ++plane) {
+ const uint8_t *buf = img->planes[plane];
+ // Calculate the width and height to do the md5 check. For the chroma
+ // plane, we never want to round down and thus skip a pixel so if
+ // we are shifting by 1 (chroma_shift) we add 1 before doing the shift.
+ // This works only for chroma_shift of 0 and 1.
+ const int bytes_per_sample =
+ (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
+ const int h =
+ plane ? (img->d_h + img->y_chroma_shift) >> img->y_chroma_shift
+ : img->d_h;
+ const int w =
+ (plane ? (img->d_w + img->x_chroma_shift) >> img->x_chroma_shift
+ : img->d_w) *
+ bytes_per_sample;
+
+ for (int y = 0; y < h; ++y) {
+ MD5Update(&md5_, buf, w);
+ buf += img->stride[plane];
+ }
+ }
+ }
+
+ void Add(const uint8_t *data, size_t size) {
+ MD5Update(&md5_, data, static_cast<uint32_t>(size));
+ }
+
+ const char *Get() {
+ static const char hex[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
+ };
+ uint8_t tmp[16];
+ MD5Context ctx_tmp = md5_;
+
+ MD5Final(tmp, &ctx_tmp);
+ for (int i = 0; i < 16; i++) {
+ res_[i * 2 + 0] = hex[tmp[i] >> 4];
+ res_[i * 2 + 1] = hex[tmp[i] & 0xf];
+ }
+ res_[32] = 0;
+
+ return res_;
+ }
+
+ protected:
+ char res_[33];
+ MD5Context md5_;
+};
+
+} // namespace libvpx_test
+
+#endif // VPX_TEST_MD5_HELPER_H_