diff --git a/vp10/encoder/palette.c b/vp10/encoder/palette.c index 97cf14c882af8844c53bd4d75d2ab2dba55044d2..371d1b93bec40893db1ccef1108ab0f327f5f6df 100644 --- a/vp10/encoder/palette.c +++ b/vp10/encoder/palette.c @@ -16,7 +16,7 @@ static float calc_dist(const float *p1, const float *p2, int dim) { float dist = 0; int i; for (i = 0; i < dim; ++i) { - const float diff = p1[i] - roundf(p2[i]); + const float diff = p1[i] - p2[i]; dist += diff * diff; } return dist; @@ -74,6 +74,11 @@ static void calc_centroids(const float *data, float *centroids, for (j = 0; j < dim; ++j) centroids[i * dim + j] *= norm; } } + + // Round to nearest integers. + for (i = 0; i < k * dim; ++i) { + centroids[i] = roundf(centroids[i]); + } } static float calc_total_dist(const float *data, const float *centroids, @@ -127,9 +132,6 @@ int vp10_remove_duplicates(float *centroids, int num_centroids) { int num_unique; // number of unique centroids int i; qsort(centroids, num_centroids, sizeof(*centroids), float_comparer); - for (i = 0; i < num_centroids; ++i) { - centroids[i] = roundf(centroids[i]); - } // Remove duplicates. num_unique = 1; for (i = 1; i < num_centroids; ++i) { diff --git a/vp10/encoder/palette.h b/vp10/encoder/palette.h index d417085fc4f5ecf108fb0dca6705afc99ca97965..eb1a571448fd2e9fc9bc4d82a611ceae264128b6 100644 --- a/vp10/encoder/palette.h +++ b/vp10/encoder/palette.h @@ -19,11 +19,18 @@ extern "C" { void vp10_calc_indices(const float *data, const float *centroids, uint8_t *indices, int n, int k, int dim); + +// Given 'data' of size 'n' and initial guess of 'centroids' of size 'k x dim', +// runs up to 'max_itr' iterations of k-means algorithm to get updated +// 'centroids' and the centroid 'indices' for elements in 'data'. +// Note: the output centroids are rounded off to nearest integers. void vp10_k_means(const float *data, float *centroids, uint8_t *indices, int n, int k, int dim, int max_itr); // Given a list of centroids, returns the unique number of centroids 'k', and // puts these unique centroids in first 'k' indices of 'centroids' array. +// Ideally, the centroids should be rounded to integers before calling this +// method. int vp10_remove_duplicates(float *centroids, int num_centroids); int vp10_count_colors(const uint8_t *src, int stride, int rows, int cols); diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c index 8135c116979e716ac21c614e3ed564441d3b6cc7..bddbac59ed2ced43d2e44bdc12dfb8af1a62426b 100644 --- a/vp10/encoder/rdopt.c +++ b/vp10/encoder/rdopt.c @@ -3616,11 +3616,11 @@ static void rd_pick_palette_intra_sbuv( #if CONFIG_VP9_HIGHBITDEPTH if (cpi->common.use_highbitdepth) pmi->palette_colors[i * PALETTE_MAX_SIZE + j] = clip_pixel_highbd( - (int)lroundf(centroids[j * 2 + i - 1]), cpi->common.bit_depth); + (int)centroids[j * 2 + i - 1], cpi->common.bit_depth); else #endif // CONFIG_VP9_HIGHBITDEPTH pmi->palette_colors[i * PALETTE_MAX_SIZE + j] = - clip_pixel((int)lroundf(centroids[j * 2 + i - 1])); + clip_pixel((int)centroids[j * 2 + i - 1]); } }