Merge pull request #88274 from bruvzg/macos_hdr_picker
[macOS] Fix color picker on HDR screens.
This commit is contained in:
commit
c4869cf15a
|
@ -2817,6 +2817,7 @@ Color DisplayServerMacOS::screen_get_pixel(const Point2i &p_position) const {
|
||||||
position += _get_screens_origin();
|
position += _get_screens_origin();
|
||||||
position /= screen_get_max_scale();
|
position /= screen_get_max_scale();
|
||||||
|
|
||||||
|
Color color;
|
||||||
for (NSScreen *screen in [NSScreen screens]) {
|
for (NSScreen *screen in [NSScreen screens]) {
|
||||||
NSRect frame = [screen frame];
|
NSRect frame = [screen frame];
|
||||||
if (NSMouseInRect(NSMakePoint(position.x, position.y), frame, NO)) {
|
if (NSMouseInRect(NSMakePoint(position.x, position.y), frame, NO)) {
|
||||||
|
@ -2824,18 +2825,22 @@ Color DisplayServerMacOS::screen_get_pixel(const Point2i &p_position) const {
|
||||||
CGDirectDisplayID display_id = [[screenDescription objectForKey:@"NSScreenNumber"] unsignedIntValue];
|
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));
|
CGImageRef image = CGDisplayCreateImageForRect(display_id, CGRectMake(position.x - frame.origin.x, frame.size.height - (position.y - frame.origin.y), 1, 1));
|
||||||
if (image) {
|
if (image) {
|
||||||
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image];
|
CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
|
||||||
CGImageRelease(image);
|
if (color_space) {
|
||||||
NSColor *color = [bitmap colorAtX:0 y:0];
|
uint8_t img_data[4];
|
||||||
if (color) {
|
CGContextRef context = CGBitmapContextCreate(img_data, 1, 1, 8, 4, color_space, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
|
||||||
CGFloat components[4];
|
if (context) {
|
||||||
[color getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
|
CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), image);
|
||||||
return Color(components[0], components[1], components[2], components[3]);
|
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 {
|
Ref<Image> DisplayServerMacOS::screen_get_image(int p_screen) const {
|
||||||
|
|
Loading…
Reference in New Issue