[gthumb] color picker: added other formats (rgb in % and hsl)
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] color picker: added other formats (rgb in % and hsl)
- Date: Sat, 19 Jun 2021 18:10:43 +0000 (UTC)
commit ccd62f36c89a3f82f56ec1c345db78b3a9f18933
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Jun 16 21:05:33 2021 +0200
color picker: added other formats (rgb in % and hsl)
.../file_tools/data/ui/color-picker-options.ui | 136 +++++++++++----------
extensions/file_tools/gth-file-tool-color-picker.c | 56 +++++++--
gthumb/color-utils.c | 36 ++++++
gthumb/color-utils.h | 7 ++
4 files changed, 162 insertions(+), 73 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/color-picker-options.ui
b/extensions/file_tools/data/ui/color-picker-options.ui
index 5c7e4b59..87268bfe 100644
--- a/extensions/file_tools/data/ui/color-picker-options.ui
+++ b/extensions/file_tools/data/ui/color-picker-options.ui
@@ -1,41 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkAdjustment" id="x_adjustment">
<property name="upper">10000</property>
- <property name="step_increment">1</property>
+ <property name="step-increment">1</property>
</object>
<object class="GtkAdjustment" id="y_adjustment">
<property name="upper">10000</property>
- <property name="step_increment">1</property>
+ <property name="step-increment">1</property>
</object>
<object class="GtkAlignment" id="options">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">12</property>
+ <property name="can-focus">False</property>
+ <property name="border-width">12</property>
<child>
<object class="GtkBox" id="vbox2">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkBox" id="vbox1">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Position</property>
<attributes>
@@ -51,52 +51,52 @@
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="n_rows">2</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">6</property>
- <property name="row_spacing">6</property>
+ <property name="can-focus">False</property>
+ <property name="n-rows">2</property>
+ <property name="n-columns">2</property>
+ <property name="column-spacing">6</property>
+ <property name="row-spacing">6</property>
<child>
<object class="GtkLabel" id="x_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">_X:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">x_spinbutton</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">x_spinbutton</property>
<property name="xalign">0</property>
</object>
<packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"/>
+ <property name="x-options">GTK_FILL</property>
+ <property name="y-options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="y_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">_Y:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">y_spinbutton</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">y_spinbutton</property>
<property name="xalign">0</property>
</object>
<packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"/>
+ <property name="top-attach">1</property>
+ <property name="bottom-attach">2</property>
+ <property name="x-options">GTK_FILL</property>
+ <property name="y-options"/>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox5">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<child>
<object class="GtkSpinButton" id="x_spinbutton">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">●</property>
+ <property name="can-focus">True</property>
+ <property name="invisible-char">●</property>
<property name="adjustment">x_adjustment</property>
- <property name="climb_rate">1</property>
+ <property name="climb-rate">1</property>
</object>
<packing>
<property name="expand">False</property>
@@ -106,23 +106,23 @@
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="left-attach">1</property>
+ <property name="right-attach">2</property>
+ <property name="x-options">GTK_FILL</property>
+ <property name="y-options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox6">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<child>
<object class="GtkSpinButton" id="y_spinbutton">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">●</property>
+ <property name="can-focus">True</property>
+ <property name="invisible-char">●</property>
<property name="adjustment">y_adjustment</property>
- <property name="climb_rate">1</property>
+ <property name="climb-rate">1</property>
</object>
<packing>
<property name="expand">False</property>
@@ -132,12 +132,12 @@
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="left-attach">1</property>
+ <property name="right-attach">2</property>
+ <property name="top-attach">1</property>
+ <property name="bottom-attach">2</property>
+ <property name="x-options">GTK_FILL</property>
+ <property name="y-options">GTK_FILL</property>
</packing>
</child>
</object>
@@ -164,13 +164,13 @@
<child>
<object class="GtkBox" id="color_section">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Color</property>
<attributes>
@@ -186,11 +186,11 @@
<child>
<object class="GtkColorButton" id="color_chooser">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_alpha">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="use-alpha">True</property>
<property name="title" translatable="yes"/>
- <property name="show_editor">True</property>
+ <property name="show-editor">True</property>
</object>
<packing>
<property name="expand">False</property>
@@ -201,9 +201,9 @@
<child>
<object class="GtkEntry" id="hex_color">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="secondary_icon_name">edit-copy-symbolic</property>
- <property name="secondary_icon_tooltip_text" translatable="yes">Copy</property>
+ <property name="can-focus">True</property>
+ <property name="secondary-icon-name">edit-copy-symbolic</property>
+ <property name="secondary-icon-tooltip-text" translatable="yes">Copy</property>
</object>
<packing>
<property name="expand">False</property>
@@ -214,9 +214,9 @@
<child>
<object class="GtkEntry" id="rgb_color">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="secondary_icon_name">edit-copy-symbolic</property>
- <property name="secondary_icon_tooltip_text" translatable="yes">Copy</property>
+ <property name="can-focus">True</property>
+ <property name="secondary-icon-name">edit-copy-symbolic</property>
+ <property name="secondary-icon-tooltip-text" translatable="yes">Copy</property>
</object>
<packing>
<property name="expand">False</property>
@@ -225,19 +225,31 @@
</packing>
</child>
<child>
- <placeholder/>
+ <object class="GtkEntry" id="rgb_100_color">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="secondary-icon-name">edit-copy-symbolic</property>
+ <property name="secondary-icon-tooltip-text" translatable="yes">Copy</property>
+ <property name="secondary-icon-tooltip-markup" translatable="yes">Copy</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
</child>
<child>
- <object class="GtkLabel" id="alpha_color">
+ <object class="GtkEntry" id="hsl_color">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="selectable">True</property>
+ <property name="can-focus">True</property>
+ <property name="secondary-icon-name">edit-copy-symbolic</property>
+ <property name="secondary-icon-tooltip-text" translatable="yes">Copy</property>
+ <property name="secondary-icon-tooltip-markup" translatable="yes">Copy</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">6</property>
+ <property name="position">5</property>
</packing>
</child>
</object>
diff --git a/extensions/file_tools/gth-file-tool-color-picker.c
b/extensions/file_tools/gth-file-tool-color-picker.c
index f3af51d0..8cd5a4de 100644
--- a/extensions/file_tools/gth-file-tool-color-picker.c
+++ b/extensions/file_tools/gth-file-tool-color-picker.c
@@ -50,6 +50,8 @@ _gth_file_tool_color_picker_show_color (GthFileToolColorPicker *self,
unsigned char *p_source;
int temp;
guchar r, g, b, a;
+ double h, s, l;
+ double r100, g100, b100;
GdkRGBA color;
char *description;
@@ -69,23 +71,55 @@ _gth_file_tool_color_picker_show_color (GthFileToolColorPicker *self,
color.blue = (double ) b / 255.0;
color.alpha = (double ) a / 255.0;
+ rgb_to_hsl (r, g, b, &h, &s, &l);
+ if (h < 0)
+ h = 255 + h;
+ h = round (h / 255.0 * 360.0);
+ s = round (s / 255.0 * 100.0);
+ l = round (l / 255.0 * 100.0);
+
+ r100 = round (color.red * 100.0);
+ g100 = round (color.green * 100.0);
+ b100 = round (color.blue * 100.0);
+
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (GET_WIDGET ("color_chooser")), &color);
- description = g_strdup_printf ("#%02x%02x%02x", r, g, b);
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hex_color")), description);
- g_free (description);
+ setlocale (LC_NUMERIC, "C"); // use always the dot as decimal separator
+ if (color.alpha == 1.0) {
+ description = g_strdup_printf ("#%02x%02x%02x", r, g, b);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hex_color")), description);
+ g_free (description);
+
+ description = g_strdup_printf ("rgb(%u, %u, %u)", r, g, b);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_color")), description);
+ g_free (description);
+
+ description = g_strdup_printf ("rgb(%.0f%%, %.0f%%, %.0f%%)", r100, g100, b100);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_100_color")), description);
+ g_free (description);
+
+ description = g_strdup_printf ("hsl(%.0f, %.0f%%, %.0f%%)", h, s, l);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hsl_color")), description);
+ g_free (description);
+ }
+ else {
+ description = g_strdup_printf ("#%02x%02x%02x%02x", r, g, b, a);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hex_color")), description);
+ g_free (description);
- description = g_strdup_printf ("rgb(%u, %u, %u)", r, g, b);
- gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_color")), description);
- g_free (description);
+ description = g_strdup_printf ("rgba(%u, %u, %u, %.2f)", r, g, b, color.alpha);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_color")), description);
+ g_free (description);
+
+ description = g_strdup_printf ("rgba(%.0f%%, %.0f%%, %.0f%%, %.2f)", r100, g100, b100,
color.alpha);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_100_color")), description);
+ g_free (description);
- if (color.alpha < 1.0) {
- description = g_strdup_printf ("alpha: %0.2f", color.alpha);
- gtk_label_set_text (GTK_LABEL (GET_WIDGET ("alpha_color")), description);
+ description = g_strdup_printf ("hsla(%.0f, %.0f%%, %.0f%%, %.2f)", h, s, l, color.alpha);
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hsl_color")), description);
g_free (description);
}
- else
- gtk_widget_hide (GET_WIDGET ("alpha_color"));
+ setlocale (LC_NUMERIC, "");
}
diff --git a/gthumb/color-utils.c b/gthumb/color-utils.c
index 2ff51eed..9fd9fb88 100644
--- a/gthumb/color-utils.c
+++ b/gthumb/color-utils.c
@@ -123,6 +123,42 @@ gimp_hsv_to_rgb (guchar hue,
/* RGB <-> HSL */
+void
+rgb_to_hsl (guchar red,
+ guchar green,
+ guchar blue,
+ double *hue,
+ double *sat,
+ double *lum)
+{
+ double min, max;
+
+ min = MIN3 (red, green, blue);
+ max = MAX3 (red, green, blue);
+
+ *lum = (max + min) / 2.0;
+
+ if (max == min) {
+ *hue = *sat = 0;
+ return;
+ }
+
+ if (*lum < 128)
+ *sat = 255.0 * (max - min) / (max + min);
+ else
+ *sat = 255.0 * (max - min) / (512.0 - max - min);
+
+ if (max == min)
+ *hue = 0;
+ else if (max == red)
+ *hue = 0.0 + 43.0 * (double) (green - blue) / (max - min);
+ else if (max == green)
+ *hue = 85.0 + 43.0 * (double) (blue - red) / (max - min);
+ else if (max == blue)
+ *hue = 171.0 + 43.0 * (double) (red - green) / (max - min);
+}
+
+
void
gimp_rgb_to_hsl (guchar red,
guchar green,
diff --git a/gthumb/color-utils.h b/gthumb/color-utils.h
index 5915e434..db7c4dc6 100644
--- a/gthumb/color-utils.h
+++ b/gthumb/color-utils.h
@@ -52,4 +52,11 @@ void gimp_hsl_to_rgb (guchar hue,
guchar *green,
guchar *blue);
+void rgb_to_hsl (guchar red,
+ guchar green,
+ guchar blue,
+ double *hue,
+ double *sat,
+ double *lum);
+
#endif /* COLOR_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]