compare_common.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2012 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "libyuv/basic_types.h"
  11. #include "libyuv/compare_row.h"
  12. #ifdef __cplusplus
  13. namespace libyuv {
  14. extern "C" {
  15. #endif
  16. uint32 SumSquareError_C(const uint8* src_a, const uint8* src_b, int count) {
  17. uint32 sse = 0u;
  18. int i;
  19. for (i = 0; i < count; ++i) {
  20. int diff = src_a[i] - src_b[i];
  21. sse += (uint32)(diff * diff);
  22. }
  23. return sse;
  24. }
  25. // hash seed of 5381 recommended.
  26. // Internal C version of HashDjb2 with int sized count for efficiency.
  27. uint32 HashDjb2_C(const uint8* src, int count, uint32 seed) {
  28. uint32 hash = seed;
  29. int i;
  30. for (i = 0; i < count; ++i) {
  31. hash += (hash << 5) + src[i];
  32. }
  33. return hash;
  34. }
  35. #ifdef __cplusplus
  36. } // extern "C"
  37. } // namespace libyuv
  38. #endif