SyntaxElementCounter.cpp 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "SyntaxElementCounter.h"
  7. #include <AK/Format.h>
  8. namespace Video::VP9 {
  9. SyntaxElementCounter::SyntaxElementCounter()
  10. {
  11. __builtin_memset(m_counts_intra_mode, 0, sizeof(m_counts_intra_mode));
  12. __builtin_memset(m_counts_uv_mode, 0, sizeof(m_counts_uv_mode));
  13. __builtin_memset(m_counts_partition, 0, sizeof(m_counts_partition));
  14. __builtin_memset(m_counts_interp_filter, 0, sizeof(m_counts_interp_filter));
  15. __builtin_memset(m_counts_inter_mode, 0, sizeof(m_counts_inter_mode));
  16. __builtin_memset(m_counts_tx_size, 0, sizeof(m_counts_tx_size));
  17. __builtin_memset(m_counts_is_inter, 0, sizeof(m_counts_is_inter));
  18. __builtin_memset(m_counts_comp_mode, 0, sizeof(m_counts_comp_mode));
  19. __builtin_memset(m_counts_single_ref, 0, sizeof(m_counts_single_ref));
  20. __builtin_memset(m_counts_comp_ref, 0, sizeof(m_counts_comp_ref));
  21. __builtin_memset(m_counts_skip, 0, sizeof(m_counts_skip));
  22. __builtin_memset(m_counts_mv_joint, 0, sizeof(m_counts_mv_joint));
  23. __builtin_memset(m_counts_mv_sign, 0, sizeof(m_counts_mv_sign));
  24. __builtin_memset(m_counts_mv_class, 0, sizeof(m_counts_mv_class));
  25. __builtin_memset(m_counts_mv_class0_bit, 0, sizeof(m_counts_mv_class0_bit));
  26. __builtin_memset(m_counts_mv_class0_fr, 0, sizeof(m_counts_mv_class0_fr));
  27. __builtin_memset(m_counts_mv_class0_hp, 0, sizeof(m_counts_mv_class0_hp));
  28. __builtin_memset(m_counts_mv_bits, 0, sizeof(m_counts_mv_bits));
  29. __builtin_memset(m_counts_mv_fr, 0, sizeof(m_counts_mv_fr));
  30. __builtin_memset(m_counts_mv_hp, 0, sizeof(m_counts_mv_hp));
  31. __builtin_memset(m_counts_token, 0, sizeof(m_counts_token));
  32. __builtin_memset(m_counts_more_coefs, 0, sizeof(m_counts_more_coefs));
  33. }
  34. template<typename T, size_t size>
  35. static void sum_arrays(T (&destination)[size], const T (&left)[size], const T (&right)[size])
  36. {
  37. for (size_t i = 0; i < size; i++) {
  38. destination[i] = left[i] + right[i];
  39. }
  40. }
  41. template<typename T, size_t size, size_t size_2>
  42. static void sum_arrays(T (&destination)[size][size_2], const T (&left)[size][size_2], const T (&right)[size][size_2])
  43. {
  44. for (size_t i = 0; i < size; i++) {
  45. sum_arrays(destination[i], left[i], right[i]);
  46. }
  47. }
  48. SyntaxElementCounter SyntaxElementCounter::operator+(SyntaxElementCounter const& other) const
  49. {
  50. SyntaxElementCounter result;
  51. sum_arrays(result.m_counts_intra_mode, this->m_counts_intra_mode, other.m_counts_intra_mode);
  52. sum_arrays(result.m_counts_uv_mode, this->m_counts_uv_mode, other.m_counts_uv_mode);
  53. sum_arrays(result.m_counts_partition, this->m_counts_partition, other.m_counts_partition);
  54. sum_arrays(result.m_counts_interp_filter, this->m_counts_interp_filter, other.m_counts_interp_filter);
  55. sum_arrays(result.m_counts_inter_mode, this->m_counts_inter_mode, other.m_counts_inter_mode);
  56. sum_arrays(result.m_counts_tx_size, this->m_counts_tx_size, other.m_counts_tx_size);
  57. sum_arrays(result.m_counts_is_inter, this->m_counts_is_inter, other.m_counts_is_inter);
  58. sum_arrays(result.m_counts_comp_mode, this->m_counts_comp_mode, other.m_counts_comp_mode);
  59. sum_arrays(result.m_counts_single_ref, this->m_counts_single_ref, other.m_counts_single_ref);
  60. sum_arrays(result.m_counts_comp_ref, this->m_counts_comp_ref, other.m_counts_comp_ref);
  61. sum_arrays(result.m_counts_skip, this->m_counts_skip, other.m_counts_skip);
  62. sum_arrays(result.m_counts_mv_joint, this->m_counts_mv_joint, other.m_counts_mv_joint);
  63. sum_arrays(result.m_counts_mv_sign, this->m_counts_mv_sign, other.m_counts_mv_sign);
  64. sum_arrays(result.m_counts_mv_class, this->m_counts_mv_class, other.m_counts_mv_class);
  65. sum_arrays(result.m_counts_mv_class0_bit, this->m_counts_mv_class0_bit, other.m_counts_mv_class0_bit);
  66. sum_arrays(result.m_counts_mv_class0_fr, this->m_counts_mv_class0_fr, other.m_counts_mv_class0_fr);
  67. sum_arrays(result.m_counts_mv_class0_hp, this->m_counts_mv_class0_hp, other.m_counts_mv_class0_hp);
  68. sum_arrays(result.m_counts_mv_bits, this->m_counts_mv_bits, other.m_counts_mv_bits);
  69. sum_arrays(result.m_counts_mv_fr, this->m_counts_mv_fr, other.m_counts_mv_fr);
  70. sum_arrays(result.m_counts_mv_hp, this->m_counts_mv_hp, other.m_counts_mv_hp);
  71. sum_arrays(result.m_counts_token, this->m_counts_token, other.m_counts_token);
  72. sum_arrays(result.m_counts_more_coefs, this->m_counts_more_coefs, other.m_counts_more_coefs);
  73. return result;
  74. }
  75. SyntaxElementCounter& SyntaxElementCounter::operator+=(SyntaxElementCounter const& other)
  76. {
  77. *this = *this + other;
  78. return *this;
  79. }
  80. }