[gnome-software/wip/hughsie/recolor-app-tile] Recolor the GsAppTile with a symbolic icon
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/recolor-app-tile] Recolor the GsAppTile with a symbolic icon
- Date: Tue, 5 Apr 2016 18:28:23 +0000 (UTC)
commit fd91615e59fbdf284e3916d442d6b613d5ee2a1c
Author: Richard Hughes <richard hughsie com>
Date: Tue Apr 5 19:27:57 2016 +0100
Recolor the GsAppTile with a symbolic icon
data/tile-symbolic.svg | 85 +++++++++++++++++++++++++++
src/gs-self-test.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gtk-style.css | 5 +-
3 files changed, 239 insertions(+), 2 deletions(-)
---
diff --git a/data/tile-symbolic.svg b/data/tile-symbolic.svg
new file mode 100644
index 0000000..1cf790f
--- /dev/null
+++ b/data/tile-symbolic.svg
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="64mm"
+ height="64mm"
+ viewBox="0 0 226.77165 226.77165"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.91 r13725"
+ sodipodi:docname="test-symbolic.svg">
+ <metadata
+ id="metadata11">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="932"
+ inkscape:window-height="480"
+ id="namedview9"
+ showgrid="false"
+ inkscape:zoom="1.0406944"
+ inkscape:cx="113.38583"
+ inkscape:cy="113.38583"
+ inkscape:window-x="0"
+ inkscape:window-y="27"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="layer1" />
+ <defs
+ id="defs4" />
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-825.59055)">
+ <rect
+ class="error"
+ style="display:inline;fill:#cc0000;fill-opacity:1;stroke:none"
+ id="rect4136"
+ width="207.14285"
+ height="67.044342"
+ x="11.428572"
+ y="970.8399"
+ ry="16.611755" />
+ <rect
+ class="success"
+
style="opacity:1;fill:#00ff00;fill-opacity:1;stroke:none;stroke-width:17.71653557;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect4155"
+ width="207.14285"
+ height="67.044342"
+ x="11.428572"
+ y="903.79553"
+ ry="16.611755" />
+ <rect
+ class="warning"
+
style="opacity:1;fill:#ff1c1c;fill-opacity:1;stroke:none;stroke-width:17.71653557;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect4136-2"
+ width="207.14285"
+ height="67.044342"
+ x="12.142859"
+ y="835.93365"
+ ry="16.611755" />
+ </g>
+</svg>
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index a246c94..95fef8f 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -638,6 +638,155 @@ gs_plugin_loader_webapps_func (void)
g_unlink (path);
}
+typedef struct {
+ gdouble R;
+ gdouble G;
+ gdouble B;
+} CdColorRGB;
+
+typedef struct {
+ CdColorRGB color;
+ guint cnt;
+} GsColorBin;
+
+static gint
+gs_color_bin_sort_cb (gconstpointer a, gconstpointer b)
+{
+ GsColorBin *s1 = (GsColorBin *) a;
+ GsColorBin *s2 = (GsColorBin *) b;
+ if (s1->cnt < s2->cnt)
+ return 1;
+ if (s1->cnt > s2->cnt)
+ return -1;
+ return 0;
+}
+
+static GPtrArray *
+gs_color_get_key_colors (const gchar *filename, guint number, GError **error)
+{
+ GdkPixbuf *pb;
+ GList *l;
+ GPtrArray *key_colors = NULL;
+ gboolean ret;
+ gint rowstride, n_channels;
+ gint x, y;
+ guchar *pixels, *p;
+ guint bin_size = 200;
+ guint number_of_bins;
+ g_autoptr(AsImage) im = NULL;
+
+ /* load icon */
+ im = as_image_new ();
+ ret = as_image_load_filename_full (im, filename, 16, 16, AS_IMAGE_LOAD_FLAG_NONE, error);
+ if (!ret)
+ return NULL;
+
+ /* go through each pixel */
+ pb = as_image_get_pixbuf (im);
+ n_channels = gdk_pixbuf_get_n_channels (pb);
+ rowstride = gdk_pixbuf_get_rowstride (pb);
+ pixels = gdk_pixbuf_get_pixels (pb);
+ for (bin_size = 250; bin_size > 5; bin_size--) {
+ g_autoptr(GHashTable) hash = NULL;
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ for (y = 0; y < gdk_pixbuf_get_height (pb); y++) {
+ for (x = 0; x < gdk_pixbuf_get_width (pb); x++) {
+ GsColorBin *s;
+ g_autofree gchar *key = NULL;
+
+ /* disregard any with alpha */
+ p = pixels + y * rowstride + x * n_channels;
+ if (p[3] != 255)
+ continue;
+
+ /* find in cache */
+ key = g_strdup_printf ("%i,%i,%i",
+ p[0] / bin_size,
+ p[1] / bin_size,
+ p[2] / bin_size);
+ s = g_hash_table_lookup (hash, key);
+ if (s != NULL) {
+ s->color.R += p[0];
+ s->color.G += p[1];
+ s->color.B += p[2];
+ s->cnt++;
+ continue;
+ }
+
+ /* add to hash table */
+ s = g_new0 (GsColorBin, 1);
+ s->color.R = p[0];
+ s->color.G = p[1];
+ s->color.B = p[2];
+ s->cnt = 1;
+ g_hash_table_insert (hash, g_strdup (key), s);
+ }
+ }
+
+ number_of_bins = g_hash_table_size (hash);
+ g_print ("Number of elements: %i\n", number_of_bins);
+ if (number_of_bins >= number) {
+ g_autoptr(GList) values = NULL;
+
+ /* order by most popular */
+ key_colors = g_ptr_array_new_with_free_func (g_free);
+ values = g_hash_table_get_values (hash);
+ values = g_list_sort (values, gs_color_bin_sort_cb);
+ for (l = values; l != NULL; l = l->next) {
+ GsColorBin *s = l->data;
+ CdColorRGB *color = g_new0 (CdColorRGB, 1);
+ color->R = s->color.R / s->cnt;
+ color->G = s->color.G / s->cnt;
+ color->B = s->color.B / s->cnt;
+ g_ptr_array_add (key_colors, color);
+ }
+ break;
+ }
+ }
+g_assert (key_colors != NULL);
+
+ return key_colors;
+}
+
+static void
+gs_color_func (void)
+{
+ CdColorRGB *color;
+ gboolean ret;
+ gint x = 0;
+ guchar *pixels;
+ guint i;
+ g_autoptr(GPtrArray) key_colors = NULL;
+ g_autoptr(GdkPixbuf) pb = NULL;
+ g_autoptr(GError) error = NULL;
+
+ //key_colors = gs_color_get_key_colors
("/usr/share/icons/hicolor/16x16/apps/goa-account-facebook.png", 3, &error);
+ //key_colors = gs_color_get_key_colors ("/usr/share/icons/hicolor/16x16/apps/gnome-boxes.png", 10,
&error);
+ //key_colors = gs_color_get_key_colors
("/usr/share/icons/hicolor/64x64/apps/gnome-color-manager.png", 10, &error);
+ key_colors = gs_color_get_key_colors ("/usr/share/icons/hicolor/32x32/apps/inkscape.png", 10, &error);
+ g_assert_no_error (error);
+
+ /* dump to file */
+ for (i = 0; i < key_colors->len; i++) {
+ color = g_ptr_array_index (key_colors, i);
+ g_print ("%.0f,%.0f,%.0f\n", color->R, color->G, color->B);
+ }
+
+ /* print colors to a file */
+ pb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, key_colors->len, 1);
+ g_assert (pb != NULL);
+ pixels = gdk_pixbuf_get_pixels (pb);
+ for (i = 0; i < key_colors->len; i++) {
+ color = g_ptr_array_index (key_colors, i);
+ pixels[x++] = color->R;
+ pixels[x++] = color->G;
+ pixels[x++] = color->B;
+ }
+ ret = gdk_pixbuf_save (pb, "/tmp/ff.png", "png", &error, NULL);
+ g_assert_no_error (error);
+ g_assert (ret);
+}
+
int
main (int argc, char **argv)
{
@@ -649,6 +798,8 @@ main (int argc, char **argv)
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+gs_color_func();
+
/* tests go here */
g_test_add_func ("/gnome-software/markdown", gs_markdown_func);
g_test_add_func ("/gnome-software/plugin-loader{refine}", gs_plugin_loader_refine_func);
diff --git a/src/gtk-style.css b/src/gtk-style.css
index be67204..915aaee 100644
--- a/src/gtk-style.css
+++ b/src/gtk-style.css
@@ -75,8 +75,9 @@
padding: 0;
box-shadow: inset 0 1px @theme_base_color, 0 1px 1px alpha(black,0.4);
border: 1px solid mix(@theme_base_color,@theme_fg_color,0.3);
- background-image: none;
- background-color: mix(@theme_base_color,@theme_bg_color,0.3);
+ background:
-gtk-recolor(url("file:///home/hughsie/Code/gnome3/gnome-software/data/tile-symbolic.svg"), error
rgb(0,255,0), warning rgb(255,0,0), success rgb(0,0,255));
+ background-size: 100% 100%;
+ background-repeat: no-repeat;
}
.view.tile:hover {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]