Customize ns-use-srgb-colorspace on OSX >= 10.7 to use sRGB.
authorJan Djärv <jan.h.d@swipnet.se>
Sat, 21 Dec 2013 16:11:55 +0000 (17:11 +0100)
committerJan Djärv <jan.h.d@swipnet.se>
Sat, 21 Dec 2013 16:11:55 +0000 (17:11 +0100)
* etc/NEWS: Mention ns-use-srgb-colorspace.

* lisp/cus-start.el (all): Add ns-use-srgb-colorspace.

* src/nsfns.m (Fxw_color_values): Use colorUsingDefaultColorSpace.

* src/nsterm.h: Declare EmacsColor category.

* src/nsterm.m (NSColor): Implement EmacsColor category.
(ns_get_color): Use colorUsingDefaultColorSpace.
(ns_get_color, ns_term_init): Use colorForEmacsRed.

etc/ChangeLog
etc/NEWS
lisp/ChangeLog
lisp/cus-start.el
src/nsfns.m
src/nsterm.h
src/nsterm.m

index 2a9ffcd..012e2e9 100644 (file)
@@ -1,3 +1,7 @@
+2013-12-21  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * NEWS: Mention ns-use-srgb-colorspace.
+
 2013-12-21  Chong Yidong  <cyd@gnu.org>
 
        * themes/tango-dark-theme.el: Minor color tweak.
index 5d9b84f..8ad8ad4 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1174,6 +1174,10 @@ Both native (>= OSX 10.7) and "old style" fullscreen are supported.
 Customize `ns-use-native-fullscreen' to change style.  For >= 10.7
 native is the default.
 
+** OSX >= 10.7 can use sRGB colorspace.
+Customize `ns-use-srgb-colorspace' to change style.  nil is the default.
+Note: This does not apply to images.
+
 \f
 * Installation Changes in Emacs 24.3
 
index c81dbf2..53cd243 100644 (file)
@@ -1,3 +1,7 @@
+2013-12-21  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * cus-start.el (all): Add ns-use-srgb-colorspace.
+
 2013-12-21  Chong Yidong  <cyd@gnu.org>
 
        * custom.el (custom-theme-recalc-face): Do nothing if the face is
index 32013b7..099485f 100644 (file)
@@ -402,6 +402,7 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of
             (ns-antialias-text ns boolean "23.1")
             (ns-auto-hide-menu-bar ns boolean "24.0")
             (ns-use-native-fullscreen ns boolean "24.4")
+            (ns-use-srgb-colorspace ns boolean "24.4")
             ;; process.c
             (delete-exited-processes processes-basics boolean)
             ;; syntax.c
index 8f14915..e90e01b 100644 (file)
@@ -2289,7 +2289,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
   if (ns_lisp_to_color (color, &col))
     return Qnil;
 
-  [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
+  [[col colorUsingDefaultColorSpace]
         getRed: &red green: &green blue: &blue alpha: &alpha];
   return list3i (lrint (red * 65280), lrint (green * 65280),
                 lrint (blue * 65280));
index b861224..2ca8385 100644 (file)
@@ -76,6 +76,18 @@ typedef CGFloat EmacsCGFloat;
 typedef float EmacsCGFloat;
 #endif
 
+/* ==========================================================================
+
+   NSColor, EmacsColor category.
+
+   ========================================================================== */
+@interface NSColor (EmacsColor)
++ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
+                         blue:(CGFloat)blue alpha:(CGFloat)alpha;
+- (NSColor *)colorUsingDefaultColorSpace;
+
+@end
+
 /* ==========================================================================
 
    The Emacs application
index 10780b0..f2aef42 100644 (file)
@@ -103,6 +103,43 @@ int term_trace_num = 0;
 
 extern NSString *NSMenuDidBeginTrackingNotification;
 
+/* ==========================================================================
+
+   NSColor, EmacsColor category.
+
+   ========================================================================== */
+@implementation NSColor (EmacsColor)
++ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
+                         blue:(CGFloat)blue alpha:(CGFloat)alpha
+{
+#ifdef NS_IMPL_COCOA
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+  if (ns_use_srgb_colorspace)
+      return [NSColor colorWithSRGBRed: red
+                                 green: green
+                                  blue: blue
+                                 alpha: alpha];
+#endif
+#endif
+  return [NSColor colorWithCalibratedRed: red
+                                   green: green
+                                    blue: blue
+                                   alpha: alpha];
+}
+
+- (NSColor *)colorUsingDefaultColorSpace
+{
+#ifdef NS_IMPL_COCOA
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+  if (ns_use_srgb_colorspace)
+    return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
+#endif
+#endif
+  return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
+}
+
+@end
+
 /* ==========================================================================
 
     Local declarations
@@ -1509,7 +1546,7 @@ ns_get_color (const char *name, NSColor **col)
 #endif
       if ((new = [NSColor selectedTextBackgroundColor]) != nil)
         {
-          *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
+          *col = [new colorUsingDefaultColorSpace];
           unblock_input ();
           return 0;
         }
@@ -1525,7 +1562,7 @@ ns_get_color (const char *name, NSColor **col)
       */
       if ((new = [NSColor selectedTextColor]) != nil)
         {
-          *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
+          *col = [new colorUsingDefaultColorSpace];
           unblock_input ();
           return 0;
         }
@@ -1572,7 +1609,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 = [NSColor colorForEmacsRed: r green: g blue: b alpha: 1.0];
       unblock_input ();
       return 0;
     }
@@ -1604,7 +1641,7 @@ ns_get_color (const char *name, NSColor **col)
   }
 
   if (new)
-    *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
+    *col = [new colorUsingDefaultColorSpace];
   unblock_input ();
   return new ? 0 : 1;
 }
@@ -1645,9 +1682,9 @@ ns_color_to_lisp (NSColor *col)
           return build_string ((char *)str);
         }
 
-    [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
+    [[col colorUsingDefaultColorSpace]
         getRed: &red green: &green blue: &blue alpha: &alpha];
-  if (red ==green && red ==blue)
+  if (red == green && red == blue)
     {
       [[col colorUsingColorSpaceName: NSCalibratedWhiteColorSpace]
             getWhite: &gray alpha: &alpha];
@@ -4273,10 +4310,10 @@ 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]
+                  [NSColor colorForEmacsRed: RED_FROM_ULONG (c) / 255.0
+                                      green: GREEN_FROM_ULONG (c) / 255.0
+                                       blue: BLUE_FROM_ULONG (c) / 255.0
+                                      alpha: 1.0]
                   forKey: [NSString stringWithUTF8String: name]];
           }
         [cl writeToFile: nil];
@@ -7607,6 +7644,12 @@ Default is t for OSX >= 10.7, nil otherwise. */);
 #endif
   ns_last_use_native_fullscreen = ns_use_native_fullscreen;
 
+  DEFVAR_BOOL ("ns-use-srgb-colorspace", ns_use_srgb_colorspace,
+     doc: /*Non-nil means to use sRGB colorspace on OSX >= 10.7.
+Note that this does not apply to images.            
+This variable is ignored on OSX < 10.7 and GNUStep.  Default is nil. */);
+  ns_use_srgb_colorspace = NO;
+
   /* TODO: move to common code */
   DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
               doc: /* Which toolkit scroll bars Emacs uses, if any.