MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / kmeans_update

Function kmeans_update

Source/astcenc_find_best_partitioning.cpp:210–243  ·  view source on GitHub ↗

* @brief Compute new cluster centers based on their center of gravity. * * @param blk The image block color data to compress. * @param texel_count The number of texels in the block. * @param partition_count The number of partitions in the block. * @param[out] cluster_centers The new cluster center colors. * @param partition_of_texe

Source from the content-addressed store, hash-verified

208 * @param partition_of_texel The partition assigned for each texel.
209 */
210static void kmeans_update(
211 const image_block& blk,
212 unsigned int texel_count,
213 unsigned int partition_count,
214 vfloat4 cluster_centers[BLOCK_MAX_PARTITIONS],
215 const uint8_t partition_of_texel[BLOCK_MAX_TEXELS]
216) {
217 promise(texel_count > 0);
218 promise(partition_count > 0);
219
220 vfloat4 color_sum[BLOCK_MAX_PARTITIONS] {
221 vfloat4::zero(),
222 vfloat4::zero(),
223 vfloat4::zero(),
224 vfloat4::zero()
225 };
226
227 uint8_t partition_texel_count[BLOCK_MAX_PARTITIONS] { 0 };
228
229 // Find the center of gravity in each cluster
230 for (unsigned int i = 0; i < texel_count; i++)
231 {
232 uint8_t partition = partition_of_texel[i];
233 color_sum[partition] += blk.texel(i);
234 partition_texel_count[partition]++;
235 }
236
237 // Set the center of gravity to be the new cluster center
238 for (unsigned int i = 0; i < partition_count; i++)
239 {
240 float scale = 1.0f / static_cast<float>(partition_texel_count[i]);
241 cluster_centers[i] = color_sum[i] * scale;
242 }
243}
244
245/**
246 * @brief Compute bit-mismatch for partitioning in 2-partition mode.

Callers 1

Calls 1

texelMethod · 0.80

Tested by

no test coverage detected