From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bozhidar Batsov Newsgroups: gmane.emacs.devel Subject: Re: sRGB color support in NS port [PATCH] Date: Sat, 21 Dec 2013 16:59:54 +0200 Message-ID: References: <23825B39C60F460E80B59C5ADF04F637@gmail.com> <83zjnv9yrp.fsf@gnu.org> <16B838CD-13DC-468E-94D1-108EBFE68F6D@swipnet.se> <7FA1C0353EC248D28B9E7242BA7BDFCC@gmail.com> <933E75DF-F665-46C0-8D82-111186A809B1@sanityinc.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0149cd5ebdbd4304ee0ca507 X-Trace: ger.gmane.org 1387637996 533 80.91.229.3 (21 Dec 2013 14:59:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 21 Dec 2013 14:59:56 +0000 (UTC) Cc: Eli Zaretskii , =?UTF-8?Q?Jan_Dj=C3=A4rv?= , emacs-devel To: Steve Purcell Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 21 16:00:02 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VuO26-0007BG-7P for ged-emacs-devel@m.gmane.org; Sat, 21 Dec 2013 16:00:02 +0100 Original-Received: from localhost ([::1]:54443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuO25-00014D-Uk for ged-emacs-devel@m.gmane.org; Sat, 21 Dec 2013 10:00:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuO22-000148-JN for emacs-devel@gnu.org; Sat, 21 Dec 2013 09:59:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VuO21-0002AJ-Ch for emacs-devel@gnu.org; Sat, 21 Dec 2013 09:59:58 -0500 Original-Received: from mail-ob0-x22f.google.com ([2607:f8b0:4003:c01::22f]:49194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuO1z-00029w-JM; Sat, 21 Dec 2013 09:59:55 -0500 Original-Received: by mail-ob0-f175.google.com with SMTP id uz6so3898131obc.6 for ; Sat, 21 Dec 2013 06:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=T5O2MkqfMjbkUwnt0A+COaUQjS2XCIFFAicF0sIpmjg=; b=g/0H+r5l1qXt7BF0S+ukE1x8wiZ2rkQ+jc5M6o5a5k5ddnr8s+lGewu4j7hfpg98ib ZjxGI+iPuhv31kUNh5avZ8KDu51kGF7tgPCBcH9Hd7PxYnoyIwaIqvS5NJFauMxQz2SR 8AMQ4ctNvsphJwOu+nPvgymmsBDFXI/9cweO/gIxr1XHYAqtlbIPCXif5oVNL1KBvGom eG/FuEi+J6NrN/lZp1nIs4MKDig8emUVv6WZk4XNOf1pVxoHHp2GF5C4IjwBaeOoiLUM 0nV7p4awmAFyWmLc2NN3/jcSMgN714f5sbks/J73pDY7tT86TLn4z1vOd4NZ4Z3e0Pgy qUtg== X-Received: by 10.182.144.136 with SMTP id sm8mr1708358obb.63.1387637994534; Sat, 21 Dec 2013 06:59:54 -0800 (PST) Original-Received: by 10.76.109.98 with HTTP; Sat, 21 Dec 2013 06:59:54 -0800 (PST) In-Reply-To: <933E75DF-F665-46C0-8D82-111186A809B1@sanityinc.com> X-Google-Sender-Auth: aWFE_dtHd4z5NqimrScylIxxMeI X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22f X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:166701 Archived-At: --089e0149cd5ebdbd4304ee0ca507 Content-Type: text/plain; charset=UTF-8 The patch looks good to me. Users of OS X 10.7+ will get proper colours and the rest (using older OS X or GNUStep) won't be affected by the change. On 21 December 2013 16:10, Steve Purcell wrote: > commit 3b63b2c6e9e93adab09eace60750ed981a8e528f > Author: Steve Purcell > Date: Sat Dec 21 11:44:12 2013 +0000 > > Treat hex colors as sRGB under OS X >= 10.7 > > 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]; > > --089e0149cd5ebdbd4304ee0ca507 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The patch looks good to me. Users of OS X 10.7+ will get p= roper colours and the rest (using older OS X or GNUStep) won't be affec= ted by the change.=C2=A0


On 21 December 2013 16:10, Steve Purcell <steve@sanityinc.com> wrote:
commit 3b63b2c6e9e93adab09eace60750ed981a8e528f
Author: Steve Purcell <steve@sani= tyinc.com>
Date: =C2=A0 Sat Dec 21 11:44:12 2013 +0000

=C2=A0 =C2=A0 Treat hex colors as sRGB under OS X >=3D 10.7

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)
=C2=A0 =C2=A0 =C2=A0Color management

=C2=A0 =C2=A0 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D */
+#if defined(NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >=3D= MAC_OS_X_VERSION_10_7
+#define NS_COLOR_FROM_RGB(r, g, b) [NSColor colorWithSRGBRed: r green: g b= lue: b alpha: 1.0]
+#define NS_COLOR_AS_RGB(c) [c colorUsingColorSpace: [NSColorSpace sRGBColo= rSpace]]
+#else
+#define NS_COLOR_FROM_RGB(r, g, b) [NSColor colorWithCalibratedRed: r gree= n: g blue: b alpha: 1.0]
+#define NS_COLOR_AS_RGB(c) [c colorUsingColorSpaceName: NSCalibratedRGBCol= orSpace]
+#endif


=C2=A0NSColor *
@@ -1551,7 +1558,7 @@ ns_get_color (const char *name, NSColor **col)

=C2=A0 =C2=A0if (r >=3D 0.0F)
=C2=A0 =C2=A0 =C2=A0{
- =C2=A0 =C2=A0 =C2=A0*col =3D [NSColor colorWithCalibratedRed: r green: g = blue: b alpha: 1.0];
+ =C2=A0 =C2=A0 =C2=A0*col =3D NS_COLOR_FROM_RGB(r, g, b);
=C2=A0 =C2=A0 =C2=A0 =C2=A0unblock_input ();
=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0 =C2=A0 =C2=A0}
@@ -1583,7 +1590,7 @@ ns_get_color (const char *name, NSColor **col)
=C2=A0 =C2=A0}

=C2=A0 =C2=A0if (new)
- =C2=A0 =C2=A0*col =3D [new colorUsingColorSpaceName: NSCalibratedRGBColor= Space];
+ =C2=A0 =C2=A0*col =3D NS_COLOR_AS_RGB(new);
=C2=A0 =C2=A0unblock_input ();
=C2=A0 =C2=A0return new ? 0 : 1;
=C2=A0}
@@ -1624,7 +1631,7 @@ ns_color_to_lisp (NSColor *col)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return build_string ((char *)str);=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}

- =C2=A0 =C2=A0[[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace] + =C2=A0 =C2=A0 =C2=A0[NS_COLOR_AS_RGB(col)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0getRed: &red green: &green blue: = &blue alpha: &alpha];
=C2=A0 =C2=A0if (red =3D=3Dgreen && red =3D=3Dblue)
=C2=A0 =C2=A0 =C2=A0{
@@ -4252,10 +4259,9 @@ ns_term_init (Lisp_Object display_name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name =3D SSDATA (XCAR (colo= r));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D XINT (XCDR (color));<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[cl setColor:
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[NSColor co= lorWithCalibratedRed: RED_FROM_ULONG (c) / 255.0
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0green: GREEN_FROM_ULONG (c) / 255.0
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 blue: BLUE_FROM_ULONG (c) / 255.0
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0alpha: 1.0]
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0NS_COLOR_FR= OM_RGB(RED_FROM_ULONG (c) / 255.0,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0GREEN_FROM_ULONG (c) / = 255.0,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0BLUE_FROM_ULONG (c) / 2= 55.0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0forKey= : [NSString stringWithUTF8String: name]];
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[cl writeToFile: nil];


--089e0149cd5ebdbd4304ee0ca507--