Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_TEST_MD5_HELPER_H_ |
| 13 | #define AOM_TEST_MD5_HELPER_H_ |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom/aom_decoder.h" |
Tom Finegan | dd3e2a5 | 2018-05-23 14:33:09 -0700 | [diff] [blame] | 16 | #include "common/md5_utils.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 17 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | namespace libaom_test { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 19 | class MD5 { |
| 20 | public: |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 21 | MD5() { MD5Init(&md5_); } |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 22 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | void Add(const aom_image_t *img) { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 24 | for (int plane = 0; plane < 3; ++plane) { |
Jim Bankoski | af13fbb | 2013-08-26 14:26:38 -0700 | [diff] [blame] | 25 | 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 Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 30 | const int bytes_per_sample = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 32 | 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. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 39 | |
| 40 | for (int y = 0; y < h; ++y) { |
| 41 | MD5Update(&md5_, buf, w); |
| 42 | buf += img->stride[plane]; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
James Zern | 0d2f348 | 2015-05-11 19:36:59 -0700 | [diff] [blame] | 47 | void Add(const uint8_t *data, size_t size) { |
James Zern | 3373f0e | 2015-05-17 11:21:22 -0700 | [diff] [blame] | 48 | MD5Update(&md5_, data, static_cast<uint32_t>(size)); |
James Zern | 0d2f348 | 2015-05-11 19:36:59 -0700 | [diff] [blame] | 49 | } |
| 50 | |
James Zern | 0d6308f | 2022-08-31 15:55:17 -0700 | [diff] [blame] | 51 | const char *Get() { |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 52 | 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 61 | res_[i * 2 + 0] = hex[tmp[i] >> 4]; |
| 62 | res_[i * 2 + 1] = hex[tmp[i] & 0xf]; |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 63 | } |
| 64 | res_[32] = 0; |
| 65 | |
| 66 | return res_; |
| 67 | } |
| 68 | |
| 69 | protected: |
| 70 | char res_[33]; |
| 71 | MD5Context md5_; |
| 72 | }; |
| 73 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | } // namespace libaom_test |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 75 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 76 | #endif // AOM_TEST_MD5_HELPER_H_ |