summaryrefslogtreecommitdiff
path: root/gtk/tools
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-10-18 08:40:00 -0500
committerMatthias Clasen <mclasen@redhat.com>2019-10-18 08:53:23 -0500
commit416b2cd18da72afb5f4e2844bf375b4765d5748c (patch)
treea4d21cf584ba1b79e552a1c5f24362cc43032071 /gtk/tools
parent15dffb47dc46565101b28e53e9f3ded9377142e1 (diff)
downloadgtk+-416b2cd18da72afb5f4e2844bf375b4765d5748c.tar.gz
Move symbolic pixbuf recoloring code
This function is better off next to the other symbolic png code in gdkpixbufutils.c.
Diffstat (limited to 'gtk/tools')
-rw-r--r--gtk/tools/gdkpixbufutils.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/gtk/tools/gdkpixbufutils.c b/gtk/tools/gdkpixbufutils.c
index ae2684adb2..7d206f05a4 100644
--- a/gtk/tools/gdkpixbufutils.c
+++ b/gtk/tools/gdkpixbufutils.c
@@ -285,6 +285,99 @@ load_symbolic_svg (const char *escaped_file_data,
}
static void
+rgba_to_pixel (const GdkRGBA *rgba,
+ guint8 pixel[4])
+{
+ pixel[0] = rgba->red * 255;
+ pixel[1] = rgba->green * 255;
+ pixel[2] = rgba->blue * 255;
+ pixel[3] = 255;
+}
+
+GdkPixbuf *
+gtk_color_symbolic_pixbuf (GdkPixbuf *symbolic,
+ const GdkRGBA *fg_color,
+ const GdkRGBA *success_color,
+ const GdkRGBA *warning_color,
+ const GdkRGBA *error_color)
+{
+ int width, height, x, y, src_stride, dst_stride;
+ guchar *src_data, *dst_data;
+ guchar *src_row, *dst_row;
+ int alpha;
+ GdkPixbuf *colored;
+ guint8 fg_pixel[4], success_pixel[4], warning_pixel[4], error_pixel[4];
+
+ alpha = fg_color->alpha * 255;
+
+ rgba_to_pixel (fg_color, fg_pixel);
+ rgba_to_pixel (success_color, success_pixel);
+ rgba_to_pixel (warning_color, warning_pixel);
+ rgba_to_pixel (error_color, error_pixel);
+
+ width = gdk_pixbuf_get_width (symbolic);
+ height = gdk_pixbuf_get_height (symbolic);
+
+ colored = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+
+ src_stride = gdk_pixbuf_get_rowstride (symbolic);
+ src_data = gdk_pixbuf_get_pixels (symbolic);
+
+ dst_data = gdk_pixbuf_get_pixels (colored);
+ dst_stride = gdk_pixbuf_get_rowstride (colored);
+ for (y = 0; y < height; y++)
+ {
+ src_row = src_data + src_stride * y;
+ dst_row = dst_data + dst_stride * y;
+ for (x = 0; x < width; x++)
+ {
+ guint r, g, b, a;
+ int c1, c2, c3, c4;
+
+ a = src_row[3];
+ dst_row[3] = a * alpha / 255;
+
+ if (a == 0)
+ {
+ dst_row[0] = 0;
+ dst_row[1] = 0;
+ dst_row[2] = 0;
+ }
+ else
+ {
+ c2 = src_row[0];
+ c3 = src_row[1];
+ c4 = src_row[2];
+
+ if (c2 == 0 && c3 == 0 && c4 == 0)
+ {
+ dst_row[0] = fg_pixel[0];
+ dst_row[1] = fg_pixel[1];
+ dst_row[2] = fg_pixel[2];
+ }
+ else
+ {
+ c1 = 255 - c2 - c3 - c4;
+
+ r = fg_pixel[0] * c1 + success_pixel[0] * c2 + warning_pixel[0] * c3 + error_pixel[0] * c4;
+ g = fg_pixel[1] * c1 + success_pixel[1] * c2 + warning_pixel[1] * c3 + error_pixel[1] * c4;
+ b = fg_pixel[2] * c1 + success_pixel[2] * c2 + warning_pixel[2] * c3 + error_pixel[2] * c4;
+
+ dst_row[0] = r / 255;
+ dst_row[1] = g / 255;
+ dst_row[2] = b / 255;
+ }
+ }
+
+ src_row += 4;
+ dst_row += 4;
+ }
+ }
+
+ return colored;
+}
+
+static void
extract_plane (GdkPixbuf *src,
GdkPixbuf *dst,
int from_plane,