[gnome-software/1290-dummy-plugin-s-key-colors-test-unreliable: 192/193] gs-key-colors: Ensure all color clusters are covered
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1290-dummy-plugin-s-key-colors-test-unreliable: 192/193] gs-key-colors: Ensure all color clusters are covered
- Date: Thu, 29 Jul 2021 12:55:53 +0000 (UTC)
commit f1bac10fd9582b07404ee7e52aca6fe8bcdfc21c
Author: Milan Crha <mcrha redhat com>
Date: Thu Jul 29 14:43:13 2021 +0200
gs-key-colors: Ensure all color clusters are covered
It helps to calculate the colors.
lib/gs-key-colors.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-key-colors.c b/lib/gs-key-colors.c
index 95cf53b15..5286bce36 100644
--- a/lib/gs-key-colors.c
+++ b/lib/gs-key-colors.c
@@ -161,6 +161,8 @@ k_means (GArray *colors,
const ClusterPixel8 *pixels_end;
Pixel8 cluster_centres[n_clusters];
CentroidAccumulator cluster_accumulators[n_clusters];
+ gboolean used_clusters[n_clusters];
+ guint covered_clusters = 0;
guint n_assignments_changed;
guint n_iterations = 0;
guint assignments_termination_limit;
@@ -180,6 +182,8 @@ k_means (GArray *colors,
pixels = (ClusterPixel8 *) raw_pixels;
pixels_end = &pixels[height * width];
+ memset (used_clusters, 0, sizeof (used_clusters));
+
/* Initialise the clusters using the Random Partition method: randomly
* assign a starting cluster to each pixel.
*
@@ -191,8 +195,17 @@ k_means (GArray *colors,
for (ClusterPixel8 *p = pixels; p < pixels_end; p++) {
if (p->alpha < minimum_alpha)
p->cluster = G_N_ELEMENTS (cluster_centres);
- else
+ else {
p->cluster = g_random_int_range (0, G_N_ELEMENTS (cluster_centres));
+
+ if (covered_clusters < n_clusters) {
+ while (used_clusters[p->cluster])
+ p->cluster = (p->cluster + 1) % n_clusters;
+
+ used_clusters[p->cluster] = TRUE;
+ covered_clusters++;
+ }
+ }
}
/* Iterate until every cluster is relatively settled. This is determined
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]