mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-09 16:57:30 +09:00
Update aom to v1.0.0
Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0.
This commit is contained in:
parent
bb61121b44
commit
48f6d2e034
1087 changed files with 154333 additions and 265310 deletions
70
third_party/aom/av1/encoder/k_means_template.h
vendored
70
third_party/aom/av1/encoder/k_means_template.h
vendored
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue