summaryrefslogtreecommitdiffstats
path: root/platform
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-13 11:24:43 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-13 11:24:43 +0200
commitd9b7075ba6464f62d942a78b8030ad6a534cdf05 (patch)
treeece0151f07983d1e56c3f1fd248a0818a2d3af2c /platform
parent9050ee1542f4e071188e8e4f868f3507bb31b3dc (diff)
downloadredot-engine-d9b7075ba6464f62d942a78b8030ad6a534cdf05.tar.gz
[macOS] Fix color picker on HDR screens.
Diffstat (limited to 'platform')
-rw-r--r--platform/macos/display_server_macos.mm21
1 files changed, 13 insertions, 8 deletions
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index ad8afaf46b..7bcb6df18d 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -2736,6 +2736,7 @@ Color DisplayServerMacOS::screen_get_pixel(const Point2i &p_position) const {
position += _get_screens_origin();
position /= screen_get_max_scale();
+ Color color;
for (NSScreen *screen in [NSScreen screens]) {
NSRect frame = [screen frame];
if (NSMouseInRect(NSMakePoint(position.x, position.y), frame, NO)) {
@@ -2743,18 +2744,22 @@ Color DisplayServerMacOS::screen_get_pixel(const Point2i &p_position) const {
CGDirectDisplayID display_id = [[screenDescription objectForKey:@"NSScreenNumber"] unsignedIntValue];
CGImageRef image = CGDisplayCreateImageForRect(display_id, CGRectMake(position.x - frame.origin.x, frame.size.height - (position.y - frame.origin.y), 1, 1));
if (image) {
- NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image];
- CGImageRelease(image);
- NSColor *color = [bitmap colorAtX:0 y:0];
- if (color) {
- CGFloat components[4];
- [color getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
- return Color(components[0], components[1], components[2], components[3]);
+ CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
+ if (color_space) {
+ uint8_t img_data[4];
+ CGContextRef context = CGBitmapContextCreate(img_data, 1, 1, 8, 4, color_space, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
+ if (context) {
+ CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), image);
+ color = Color(img_data[0] / 255.0f, img_data[1] / 255.0f, img_data[2] / 255.0f, img_data[3] / 255.0f);
+ CGContextRelease(context);
+ }
+ CGColorSpaceRelease(color_space);
}
+ CGImageRelease(image);
}
}
}
- return Color();
+ return color;
}
Ref<Image> DisplayServerMacOS::screen_get_image(int p_screen) const {