blob: c3e98b8f097c4cdd26e8da3b6c83cef26a8480c2 [file] [log] [blame]
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -08001/*
James Zernb7c05bd2024-06-11 19:15:10 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -08003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080010 */
11
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_TEST_MD5_HELPER_H_
13#define AOM_TEST_MD5_HELPER_H_
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080014
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "aom/aom_decoder.h"
Tom Finegandd3e2a52018-05-23 14:33:09 -070016#include "common/md5_utils.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080017
Yaowu Xuc27fc142016-08-22 16:08:15 -070018namespace libaom_test {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080019class MD5 {
20 public:
clang-format3a826f12016-08-11 17:46:05 -070021 MD5() { MD5Init(&md5_); }
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080022
Yaowu Xuf883b422016-08-30 14:01:10 -070023 void Add(const aom_image_t *img) {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080024 for (int plane = 0; plane < 3; ++plane) {
Jim Bankoskiaf13fbb2013-08-26 14:26:38 -070025 const uint8_t *buf = img->planes[plane];
26 // Calculate the width and height to do the md5 check. For the chroma
27 // plane, we never want to round down and thus skip a pixel so if
28 // we are shifting by 1 (chroma_shift) we add 1 before doing the shift.
29 // This works only for chroma_shift of 0 and 1.
Deb Mukherjee5acfafb2014-08-26 12:35:15 -070030 const int bytes_per_sample =
Yaowu Xuf883b422016-08-30 14:01:10 -070031 (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1;
clang-format3a826f12016-08-11 17:46:05 -070032 const int h =
33 plane ? (img->d_h + img->y_chroma_shift) >> img->y_chroma_shift
34 : img->d_h;
35 const int w =
36 (plane ? (img->d_w + img->x_chroma_shift) >> img->x_chroma_shift
37 : img->d_w) *
38 bytes_per_sample;
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080039
40 for (int y = 0; y < h; ++y) {
41 MD5Update(&md5_, buf, w);
42 buf += img->stride[plane];
43 }
44 }
45 }
46
James Zern0d2f3482015-05-11 19:36:59 -070047 void Add(const uint8_t *data, size_t size) {
James Zern3373f0e2015-05-17 11:21:22 -070048 MD5Update(&md5_, data, static_cast<uint32_t>(size));
James Zern0d2f3482015-05-11 19:36:59 -070049 }
50
James Zern0d6308f2022-08-31 15:55:17 -070051 const char *Get() {
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080052 static const char hex[16] = {
53 '0', '1', '2', '3', '4', '5', '6', '7',
54 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
55 };
56 uint8_t tmp[16];
57 MD5Context ctx_tmp = md5_;
58
59 MD5Final(tmp, &ctx_tmp);
60 for (int i = 0; i < 16; i++) {
clang-format3a826f12016-08-11 17:46:05 -070061 res_[i * 2 + 0] = hex[tmp[i] >> 4];
62 res_[i * 2 + 1] = hex[tmp[i] & 0xf];
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080063 }
64 res_[32] = 0;
65
66 return res_;
67 }
68
69 protected:
70 char res_[33];
71 MD5Context md5_;
72};
73
Yaowu Xuc27fc142016-08-22 16:08:15 -070074} // namespace libaom_test
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080075
James Zerne1cbb132018-08-22 14:10:36 -070076#endif // AOM_TEST_MD5_HELPER_H_