Tidy up NS color handling

* src/nsimage.m (COLORSPACE_NAME): New macro to find the current
colorspace.
([EmacsImage initFromXBM:width:height:fg:bg:reverseBytes:]):
([EmacsImage initForXPMWithDepth:width:height:]): Use the current
colorspace.
* src/nsterm.h (NSAppKitVersionNumber10_7):
(NSAppKitVersionNumber10_10): Define for macOS version checks.
* src/nsterm.m ([NSColor colorForEmacsRed:green:blue:alpha:]): Tidy up
the version checking.
([NSColor colorUsingDefaultColorSpace]): Tidy the version checking and
use [NSColor colorUsingColorSpace:] with GNUstep.
This commit is contained in:
Alan Third 2020-09-25 17:12:51 +01:00
parent dd6876d6e2
commit 3a3226716b
3 changed files with 30 additions and 34 deletions

View file

@ -36,6 +36,14 @@ Updated by Christian Limpach (chris@nice.ch)
#include "coding.h"
#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MAX_ALLOWED < 1070
# define COLORSPACE_NAME NSCalibratedRGBColorSpace
#else
# define COLORSPACE_NAME \
((ns_use_srgb_colorspace && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) \
? NSDeviceRGBColorSpace : NSCalibratedRGBColorSpace)
#endif
/* ==========================================================================
@ -295,7 +303,7 @@ - (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
pixelsWide: w pixelsHigh: h
bitsPerSample: 8 samplesPerPixel: 4
hasAlpha: YES isPlanar: YES
colorSpaceName: NSCalibratedRGBColorSpace
colorSpaceName: COLORSPACE_NAME
bytesPerRow: w bitsPerPixel: 0];
[bmRep getBitmapDataPlanes: planes];
@ -415,7 +423,7 @@ - (instancetype)initForXPMWithDepth: (int)depth width: (int)width height: (int)h
/* keep things simple for now */
bitsPerSample: 8 samplesPerPixel: 4 /*RGB+A*/
hasAlpha: YES isPlanar: YES
colorSpaceName: NSCalibratedRGBColorSpace
colorSpaceName: COLORSPACE_NAME
bytesPerRow: width bitsPerPixel: 0];
[bmRep getBitmapDataPlanes: pixmapData];

View file

@ -1254,6 +1254,19 @@ extern char gnustep_base_version[]; /* version tracking */
? (min) : (((x)>(max)) ? (max) : (x)))
#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
#ifdef NS_IMPL_COCOA
/* Add some required AppKit version numbers if they're not defined. */
#ifndef NSAppKitVersionNumber10_7
#define NSAppKitVersionNumber10_7 1138
#endif
#ifndef NSAppKitVersionNumber10_10
#define NSAppKitVersionNumber10_10 1343
#endif
#endif /* NS_IMPL_COCOA */
/* macOS 10.7 introduces some new constants. */
#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
#define NSFullScreenWindowMask (1 << 14)

View file

@ -140,14 +140,9 @@ @implementation NSColor (EmacsColor)
+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
blue:(CGFloat)blue alpha:(CGFloat)alpha
{
#if defined (NS_IMPL_COCOA) \
&& MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (ns_use_srgb_colorspace
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
&& [NSColor respondsToSelector:
@selector(colorWithSRGBRed:green:blue:alpha:)]
#endif
)
&& NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
return [NSColor colorWithSRGBRed: red
green: green
blue: blue
@ -161,28 +156,12 @@ + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
- (NSColor *)colorUsingDefaultColorSpace
{
/* FIXME: We're checking for colorWithSRGBRed here so this will only
work in the same place as in the method above. It should really
be a check whether we're on macOS 10.7 or above. */
#if defined (NS_IMPL_COCOA) \
&& MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
if ([NSColor respondsToSelector:
@selector(colorWithSRGBRed:green:blue:alpha:)])
#endif
{
if (ns_use_srgb_colorspace)
return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
else
return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]];
}
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
else
#endif
#endif /* NS_IMPL_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MIN_REQUIRED < 1070
return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (ns_use_srgb_colorspace
&& NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
#endif
return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]];
}
@end
@ -2209,10 +2188,6 @@ so some key presses (TAB) are swallowed by the system. */
NSTRACE ("ns_set_appearance");
#ifndef NSAppKitVersionNumber10_10
#define NSAppKitVersionNumber10_10 1343
#endif
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10)
return;