diff options
author | trav90 <travawine@palemoon.org> | 2018-10-19 21:52:15 -0500 |
---|---|---|
committer | trav90 <travawine@palemoon.org> | 2018-10-19 21:52:20 -0500 |
commit | bbcc64772580c8a979288791afa02d30bc476d2e (patch) | |
tree | 437ce94c3fdd7497508e5b55de06c6d011678597 /third_party/aom/av1/encoder/k_means_template.h | |
parent | 14805f6ddbfb173c327768fff9f81f40ce5e81b0 (diff) | |
download | UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.gz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.lz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.xz UXP-bbcc64772580c8a979288791afa02d30bc476d2e.zip |
Update aom to v1.0.0
Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0.
Diffstat (limited to 'third_party/aom/av1/encoder/k_means_template.h')
-rw-r--r-- | third_party/aom/av1/encoder/k_means_template.h | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/third_party/aom/av1/encoder/k_means_template.h b/third_party/aom/av1/encoder/k_means_template.h index 3a433d9b5..9e526b88b 100644 --- a/third_party/aom/av1/encoder/k_means_template.h +++ b/third_party/aom/av1/encoder/k_means_template.h @@ -23,25 +23,23 @@ #define RENAME_(x, y) AV1_K_MEANS_RENAME(x, y) #define RENAME(x) RENAME_(x, AV1_K_MEANS_DIM) -static float RENAME(calc_dist)(const float *p1, const float *p2) { - float dist = 0; - int i; - for (i = 0; i < AV1_K_MEANS_DIM; ++i) { - const float diff = p1[i] - p2[i]; +static int RENAME(calc_dist)(const int *p1, const int *p2) { + int dist = 0; + for (int i = 0; i < AV1_K_MEANS_DIM; ++i) { + const int diff = p1[i] - p2[i]; dist += diff * diff; } return dist; } -void RENAME(av1_calc_indices)(const float *data, const float *centroids, +void RENAME(av1_calc_indices)(const int *data, const int *centroids, uint8_t *indices, int n, int k) { - int i, j; - for (i = 0; i < n; ++i) { - float min_dist = RENAME(calc_dist)(data + i * AV1_K_MEANS_DIM, centroids); + for (int i = 0; i < n; ++i) { + int min_dist = RENAME(calc_dist)(data + i * AV1_K_MEANS_DIM, centroids); indices[i] = 0; - for (j = 1; j < k; ++j) { - const float this_dist = RENAME(calc_dist)( - data + i * AV1_K_MEANS_DIM, centroids + j * AV1_K_MEANS_DIM); + for (int j = 1; j < k; ++j) { + const int this_dist = RENAME(calc_dist)(data + i * AV1_K_MEANS_DIM, + centroids + j * AV1_K_MEANS_DIM); if (this_dist < min_dist) { min_dist = this_dist; indices[i] = j; @@ -50,19 +48,16 @@ void RENAME(av1_calc_indices)(const float *data, const float *centroids, } } -static void RENAME(calc_centroids)(const float *data, float *centroids, +static void RENAME(calc_centroids)(const int *data, int *centroids, const uint8_t *indices, int n, int k) { - int i, j, index; - int count[PALETTE_MAX_SIZE]; + int i, j; + int count[PALETTE_MAX_SIZE] = { 0 }; unsigned int rand_state = (unsigned int)data[0]; - assert(n <= 32768); - - memset(count, 0, sizeof(count[0]) * k); memset(centroids, 0, sizeof(centroids[0]) * k * AV1_K_MEANS_DIM); for (i = 0; i < n; ++i) { - index = indices[i]; + const int index = indices[i]; assert(index < k); ++count[index]; for (j = 0; j < AV1_K_MEANS_DIM; ++j) { @@ -76,43 +71,35 @@ static void RENAME(calc_centroids)(const float *data, float *centroids, data + (lcg_rand16(&rand_state) % n) * AV1_K_MEANS_DIM, sizeof(centroids[0]) * AV1_K_MEANS_DIM); } else { - const float norm = 1.0f / count[i]; - for (j = 0; j < AV1_K_MEANS_DIM; ++j) - centroids[i * AV1_K_MEANS_DIM + j] *= norm; + for (j = 0; j < AV1_K_MEANS_DIM; ++j) { + centroids[i * AV1_K_MEANS_DIM + j] = + DIVIDE_AND_ROUND(centroids[i * AV1_K_MEANS_DIM + j], count[i]); + } } } - - // Round to nearest integers. - for (i = 0; i < k * AV1_K_MEANS_DIM; ++i) { - centroids[i] = roundf(centroids[i]); - } } -static float RENAME(calc_total_dist)(const float *data, const float *centroids, - const uint8_t *indices, int n, int k) { - float dist = 0; - int i; +static int64_t RENAME(calc_total_dist)(const int *data, const int *centroids, + const uint8_t *indices, int n, int k) { + int64_t dist = 0; (void)k; - - for (i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) { dist += RENAME(calc_dist)(data + i * AV1_K_MEANS_DIM, centroids + indices[i] * AV1_K_MEANS_DIM); - + } return dist; } -void RENAME(av1_k_means)(const float *data, float *centroids, uint8_t *indices, +void RENAME(av1_k_means)(const int *data, int *centroids, uint8_t *indices, int n, int k, int max_itr) { - int i; - float this_dist; - float pre_centroids[2 * PALETTE_MAX_SIZE]; + int pre_centroids[2 * PALETTE_MAX_SIZE]; uint8_t pre_indices[MAX_SB_SQUARE]; RENAME(av1_calc_indices)(data, centroids, indices, n, k); - this_dist = RENAME(calc_total_dist)(data, centroids, indices, n, k); + int64_t this_dist = RENAME(calc_total_dist)(data, centroids, indices, n, k); - for (i = 0; i < max_itr; ++i) { - const float pre_dist = this_dist; + for (int i = 0; i < max_itr; ++i) { + const int64_t pre_dist = this_dist; memcpy(pre_centroids, centroids, sizeof(pre_centroids[0]) * k * AV1_K_MEANS_DIM); memcpy(pre_indices, indices, sizeof(pre_indices[0]) * n); @@ -132,6 +119,5 @@ void RENAME(av1_k_means)(const float *data, float *centroids, uint8_t *indices, break; } } - #undef RENAME_ #undef RENAME |