Don't convert to float before storing...

...in GeglColor. Just use the "u8" format.
This commit is contained in:
Alx Sa 2024-04-06 01:34:05 +00:00
parent cc74d40769
commit f726efba76
4 changed files with 33 additions and 33 deletions

View File

@ -185,7 +185,7 @@ gimp_pick_button_pick (GimpPickButton *button,
GdkScreen *screen = gdk_event_get_screen (event); GdkScreen *screen = gdk_event_get_screen (event);
GimpColorProfile *monitor_profile; GimpColorProfile *monitor_profile;
GdkMonitor *monitor; GdkMonitor *monitor;
GeglColor *rgb = gegl_color_new ("none"); GeglColor *rgb = gegl_color_new ("black");
const Babl *space = NULL; const Babl *space = NULL;
gint x_root; gint x_root;
gint y_root; gint y_root;
@ -212,6 +212,7 @@ gimp_pick_button_pick (GimpPickButton *button,
HDC hdc; HDC hdc;
RECT rect; RECT rect;
COLORREF win32_color; COLORREF win32_color;
guchar temp_rgb[3];
/* For MS Windows, use native GDI functions to get the pixel, as /* For MS Windows, use native GDI functions to get the pixel, as
* cairo does not handle the case where you have multiple monitors * cairo does not handle the case where you have multiple monitors
@ -225,12 +226,12 @@ gimp_pick_button_pick (GimpPickButton *button,
win32_color = GetPixel (hdc, x_root + rect.left, y_root + rect.top); win32_color = GetPixel (hdc, x_root + rect.left, y_root + rect.top);
ReleaseDC (HWND_DESKTOP, hdc); ReleaseDC (HWND_DESKTOP, hdc);
gegl_color_set_rgba_with_space (rgb, temp_rgb[0] = GetRValue (win32_color);
GetRValue (win32_color) / 255.0, temp_rgb[1] = GetGValue (win32_color);
GetGValue (win32_color) / 255.0, temp_rgb[2] = GetBValue (win32_color);
GetBValue (win32_color) / 255.0,
1.0, gegl_color_set_pixel (rgb, babl_format_with_space ("R'G'B' u8", space),
space); temp_rgb);
} }
#else #else
@ -273,12 +274,8 @@ gimp_pick_button_pick (GimpPickButton *button,
cairo_surface_destroy (image); cairo_surface_destroy (image);
gegl_color_set_rgba_with_space (rgb, gegl_color_set_pixel (rgb, babl_format_with_space ("R'G'B' u8", space),
color[0] / 255.0, color);
color[1] / 255.0,
color[2] / 255.0,
1.0,
space);
} }
#endif #endif

View File

@ -82,17 +82,19 @@ _gimp_pick_button_kwin_pick (GimpPickButton *button)
-1, NULL, &error); -1, NULL, &error);
if (retval) if (retval)
{ {
GeglColor *rgb = gegl_color_new ("none"); GeglColor *rgb = gegl_color_new ("black");
guint32 color; guint32 color;
guchar temp_rgba[4];
g_variant_get (retval, "((u))", &color); g_variant_get (retval, "((u))", &color);
g_variant_unref (retval); g_variant_unref (retval);
/* Returned value is ARGB stored in uint32. */ /* Returned value is ARGB stored in uint32. */
gegl_color_set_rgba (rgb, temp_rgba[0] = (color >> 16) & 0xff; /* Red */
((color >> 16) & 0xff) / 255.0, /* Red */ temp_rgba[1] = (color >> 8) & 0xff; /* Green */
((color >> 8) & 0xff) / 255.0, /* Green */ temp_rgba[2] = color & 0xff; /* Blue: least significant byte. */
(color & 0xff) / 255.0, /* Blue: least significant byte. */ temp_rgba[3] = (color >> 24) & 0xff; /* Alpha: most significant byte. */
((color >> 24) & 0xff) / 255.0); /* Alpha: most significant byte. */
gegl_color_set_pixel (rgb, babl_format ("R'G'B'A u8"), temp_rgba);
g_signal_emit_by_name (button, "color-picked", rgb); g_signal_emit_by_name (button, "color-picked", rgb);
g_object_unref (rgb); g_object_unref (rgb);

View File

@ -156,7 +156,8 @@
CGImageRef root_image_ref; CGImageRef root_image_ref;
CFDataRef pixel_data; CFDataRef pixel_data;
const guchar *data; const guchar *data;
GeglColor *rgb = gegl_color_new ("none"); GeglColor *rgb = gegl_color_new ("black");
guchar temp_rgb[3];
const Babl *space = NULL; const Babl *space = NULL;
NSPoint point; NSPoint point;
GimpColorProfile *profile = NULL; GimpColorProfile *profile = NULL;
@ -212,12 +213,11 @@
g_object_unref (profile); g_object_unref (profile);
} }
gegl_color_set_rgba_with_space (rgb, for (gint i = 0; i < 3; i++)
data[2] / 255.0, temp_rgb[i] = data[2 - i];
data[1] / 255.0,
data[0] / 255.0, gegl_color_set_pixel (rgb, babl_format_with_space ("R'G'B' u8", space),
1.0, temp_rgb);
space);
CGImageRelease (root_image_ref); CGImageRelease (root_image_ref);
CFRelease (pixel_data); CFRelease (pixel_data);

View File

@ -1072,9 +1072,10 @@ remove_screen_tracking (void)
static GeglColor * static GeglColor *
pick_color_with_gdi (POINT physical_point) pick_color_with_gdi (POINT physical_point)
{ {
GeglColor *rgb = gegl_color_new ("none"); GeglColor *rgb = gegl_color_new ("black");
COLORREF color; COLORREF color;
HDC hdc; HDC hdc;
guchar temp_rgb[3];
hdc = GetDC (HWND_DESKTOP); hdc = GetDC (HWND_DESKTOP);
@ -1083,11 +1084,11 @@ pick_color_with_gdi (POINT physical_point)
color = GetPixel (hdc, physical_point.x, physical_point.y); color = GetPixel (hdc, physical_point.x, physical_point.y);
gegl_color_set_rgba (rgb, temp_rgb[0] = GetRValue (color);
GetRValue (color) / 255.0, temp_rgb[1] = GetGValue (color);
GetGValue (color) / 255.0, temp_rgb[2] = GetBValue (color);
GetBValue (color) / 255.0,
1.0); gegl_color_set_pixel (rgb, babl_format ("R'G'B' u8"), temp_rgb);
ReleaseDC (HWND_DESKTOP, hdc); ReleaseDC (HWND_DESKTOP, hdc);
@ -1099,7 +1100,7 @@ user_picked (MonitorData *monitor,
POINT physical_point) POINT physical_point)
{ {
GeglColor *rgb; GeglColor *rgb;
GList *l; GList *l;
/* Currently unused */ /* Currently unused */
(void) monitor; (void) monitor;