[gnome-software/1290-dummy-plugin-s-key-colors-test-unreliable: 17/18] 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: 17/18] gs-key-colors: Ensure all color clusters are covered
- Date: Mon, 25 Oct 2021 07:42:22 +0000 (UTC)
commit a995a7ad50504d7e4efab58facdf72e060071739
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 | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-key-colors.c b/lib/gs-key-colors.c
index ef2d6d01c..b82af9057 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;
@@ -181,6 +183,7 @@ k_means (GArray *colors,
pixels_end = &pixels[height * width];
memset (cluster_centres, 0, sizeof (cluster_centres));
+ memset (used_clusters, 0, sizeof (used_clusters));
/* Initialise the clusters using the Random Partition method: randomly
* assign a starting cluster to each pixel.
@@ -193,8 +196,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]