Last active
June 19, 2018 16:34
-
-
Save purcell/3858136 to your computer and use it in GitHub Desktop.
Make Emacs on OSX treat all RGB colors as being within the sRGB color space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 3b63b2c6e9e93adab09eace60750ed981a8e528f | |
Author: Steve Purcell <[email protected]> | |
Date: Sat Dec 21 11:44:12 2013 +0000 | |
Treat hex colors as sRGB (see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8402) | |
diff --git a/src/nsterm.m b/src/nsterm.m | |
index 733c05a..0c79186 100644 | |
--- a/src/nsterm.m | |
+++ b/src/nsterm.m | |
@@ -1373,6 +1373,13 @@ ns_fullscreen_hook (struct frame *f) | |
Color management | |
========================================================================== */ | |
+#if defined(NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+#define NS_COLOR_FROM_RGB(r, g, b) [NSColor colorWithSRGBRed: r green: g blue: b alpha: 1.0] | |
+#define NS_COLOR_AS_RGB(c) [c colorUsingColorSpace: [NSColorSpace sRGBColorSpace]] | |
+#else | |
+#define NS_COLOR_FROM_RGB(r, g, b) [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0] | |
+#define NS_COLOR_AS_RGB(c) [c colorUsingColorSpaceName: NSCalibratedRGBColorSpace] | |
+#endif | |
NSColor * | |
@@ -1551,7 +1558,7 @@ ns_get_color (const char *name, NSColor **col) | |
if (r >= 0.0F) | |
{ | |
- *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0]; | |
+ *col = NS_COLOR_FROM_RGB(r, g, b); | |
unblock_input (); | |
return 0; | |
} | |
@@ -1583,7 +1590,7 @@ ns_get_color (const char *name, NSColor **col) | |
} | |
if (new) | |
- *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | |
+ *col = NS_COLOR_AS_RGB(new); | |
unblock_input (); | |
return new ? 0 : 1; | |
} | |
@@ -1624,7 +1631,7 @@ ns_color_to_lisp (NSColor *col) | |
return build_string ((char *)str); | |
} | |
- [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace] | |
+ [NS_COLOR_AS_RGB(col) | |
getRed: &red green: &green blue: &blue alpha: &alpha]; | |
if (red ==green && red ==blue) | |
{ | |
@@ -4252,10 +4259,9 @@ ns_term_init (Lisp_Object display_name) | |
name = SSDATA (XCAR (color)); | |
c = XINT (XCDR (color)); | |
[cl setColor: | |
- [NSColor colorWithCalibratedRed: RED_FROM_ULONG (c) / 255.0 | |
- green: GREEN_FROM_ULONG (c) / 255.0 | |
- blue: BLUE_FROM_ULONG (c) / 255.0 | |
- alpha: 1.0] | |
+ NS_COLOR_FROM_RGB(RED_FROM_ULONG (c) / 255.0, | |
+ GREEN_FROM_ULONG (c) / 255.0, | |
+ BLUE_FROM_ULONG (c) / 255.0) | |
forKey: [NSString stringWithUTF8String: name]]; | |
} | |
[cl writeToFile: nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An alternative formulation in this patch is now in Emacs trunk, and should be part of the Emacs 24.4 release.