diff options
| author | Alan Third | 2020-09-25 17:12:51 +0100 |
|---|---|---|
| committer | Alan Third | 2020-09-25 17:19:00 +0100 |
| commit | 3a3226716b84c29c7eee9e19054ffe7618bd334c (patch) | |
| tree | b542b3a6a21615fb5ee8c47f8e1b73612317d279 /src | |
| parent | dd6876d6e2c57c003edbfe2fb4b12b3dd3e253b8 (diff) | |
| download | emacs-3a3226716b84c29c7eee9e19054ffe7618bd334c.tar.gz emacs-3a3226716b84c29c7eee9e19054ffe7618bd334c.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsimage.m | 12 | ||||
| -rw-r--r-- | src/nsterm.h | 13 | ||||
| -rw-r--r-- | src/nsterm.m | 39 |
3 files changed, 30 insertions, 34 deletions
diff --git a/src/nsimage.m b/src/nsimage.m index 966e7044f12..da6f01cf6a3 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -36,6 +36,14 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) | |||
| 36 | #include "coding.h" | 36 | #include "coding.h" |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | #if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MAX_ALLOWED < 1070 | ||
| 40 | # define COLORSPACE_NAME NSCalibratedRGBColorSpace | ||
| 41 | #else | ||
| 42 | # define COLORSPACE_NAME \ | ||
| 43 | ((ns_use_srgb_colorspace && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) \ | ||
| 44 | ? NSDeviceRGBColorSpace : NSCalibratedRGBColorSpace) | ||
| 45 | #endif | ||
| 46 | |||
| 39 | 47 | ||
| 40 | /* ========================================================================== | 48 | /* ========================================================================== |
| 41 | 49 | ||
| @@ -295,7 +303,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 295 | pixelsWide: w pixelsHigh: h | 303 | pixelsWide: w pixelsHigh: h |
| 296 | bitsPerSample: 8 samplesPerPixel: 4 | 304 | bitsPerSample: 8 samplesPerPixel: 4 |
| 297 | hasAlpha: YES isPlanar: YES | 305 | hasAlpha: YES isPlanar: YES |
| 298 | colorSpaceName: NSCalibratedRGBColorSpace | 306 | colorSpaceName: COLORSPACE_NAME |
| 299 | bytesPerRow: w bitsPerPixel: 0]; | 307 | bytesPerRow: w bitsPerPixel: 0]; |
| 300 | 308 | ||
| 301 | [bmRep getBitmapDataPlanes: planes]; | 309 | [bmRep getBitmapDataPlanes: planes]; |
| @@ -415,7 +423,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 415 | /* keep things simple for now */ | 423 | /* keep things simple for now */ |
| 416 | bitsPerSample: 8 samplesPerPixel: 4 /*RGB+A*/ | 424 | bitsPerSample: 8 samplesPerPixel: 4 /*RGB+A*/ |
| 417 | hasAlpha: YES isPlanar: YES | 425 | hasAlpha: YES isPlanar: YES |
| 418 | colorSpaceName: NSCalibratedRGBColorSpace | 426 | colorSpaceName: COLORSPACE_NAME |
| 419 | bytesPerRow: width bitsPerPixel: 0]; | 427 | bytesPerRow: width bitsPerPixel: 0]; |
| 420 | 428 | ||
| 421 | [bmRep getBitmapDataPlanes: pixmapData]; | 429 | [bmRep getBitmapDataPlanes: pixmapData]; |
diff --git a/src/nsterm.h b/src/nsterm.h index 0bdb78e4436..f292993d8f7 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -1254,6 +1254,19 @@ extern char gnustep_base_version[]; /* version tracking */ | |||
| 1254 | ? (min) : (((x)>(max)) ? (max) : (x))) | 1254 | ? (min) : (((x)>(max)) ? (max) : (x))) |
| 1255 | #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) | 1255 | #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) |
| 1256 | 1256 | ||
| 1257 | |||
| 1258 | #ifdef NS_IMPL_COCOA | ||
| 1259 | /* Add some required AppKit version numbers if they're not defined. */ | ||
| 1260 | #ifndef NSAppKitVersionNumber10_7 | ||
| 1261 | #define NSAppKitVersionNumber10_7 1138 | ||
| 1262 | #endif | ||
| 1263 | |||
| 1264 | #ifndef NSAppKitVersionNumber10_10 | ||
| 1265 | #define NSAppKitVersionNumber10_10 1343 | ||
| 1266 | #endif | ||
| 1267 | #endif /* NS_IMPL_COCOA */ | ||
| 1268 | |||
| 1269 | |||
| 1257 | /* macOS 10.7 introduces some new constants. */ | 1270 | /* macOS 10.7 introduces some new constants. */ |
| 1258 | #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7) | 1271 | #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7) |
| 1259 | #define NSFullScreenWindowMask (1 << 14) | 1272 | #define NSFullScreenWindowMask (1 << 14) |
diff --git a/src/nsterm.m b/src/nsterm.m index ec96be3d2f6..fdcd677d144 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -140,14 +140,9 @@ char const * nstrace_fullscreen_type_name (int fs_type) | |||
| 140 | + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green | 140 | + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green |
| 141 | blue:(CGFloat)blue alpha:(CGFloat)alpha | 141 | blue:(CGFloat)blue alpha:(CGFloat)alpha |
| 142 | { | 142 | { |
| 143 | #if defined (NS_IMPL_COCOA) \ | 143 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 |
| 144 | && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 | ||
| 145 | if (ns_use_srgb_colorspace | 144 | if (ns_use_srgb_colorspace |
| 146 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | 145 | && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) |
| 147 | && [NSColor respondsToSelector: | ||
| 148 | @selector(colorWithSRGBRed:green:blue:alpha:)] | ||
| 149 | #endif | ||
| 150 | ) | ||
| 151 | return [NSColor colorWithSRGBRed: red | 146 | return [NSColor colorWithSRGBRed: red |
| 152 | green: green | 147 | green: green |
| 153 | blue: blue | 148 | blue: blue |
| @@ -161,28 +156,12 @@ char const * nstrace_fullscreen_type_name (int fs_type) | |||
| 161 | 156 | ||
| 162 | - (NSColor *)colorUsingDefaultColorSpace | 157 | - (NSColor *)colorUsingDefaultColorSpace |
| 163 | { | 158 | { |
| 164 | /* FIXME: We're checking for colorWithSRGBRed here so this will only | 159 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 |
| 165 | work in the same place as in the method above. It should really | 160 | if (ns_use_srgb_colorspace |
| 166 | be a check whether we're on macOS 10.7 or above. */ | 161 | && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) |
| 167 | #if defined (NS_IMPL_COCOA) \ | 162 | return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; |
| 168 | && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 | ||
| 169 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | ||
| 170 | if ([NSColor respondsToSelector: | ||
| 171 | @selector(colorWithSRGBRed:green:blue:alpha:)]) | ||
| 172 | #endif | ||
| 173 | { | ||
| 174 | if (ns_use_srgb_colorspace) | ||
| 175 | return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; | ||
| 176 | else | ||
| 177 | return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; | ||
| 178 | } | ||
| 179 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | ||
| 180 | else | ||
| 181 | #endif | ||
| 182 | #endif /* NS_IMPL_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ | ||
| 183 | #if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | ||
| 184 | return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | ||
| 185 | #endif | 163 | #endif |
| 164 | return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; | ||
| 186 | } | 165 | } |
| 187 | 166 | ||
| 188 | @end | 167 | @end |
| @@ -2209,10 +2188,6 @@ ns_set_appearance (struct frame *f, Lisp_Object new_value, Lisp_Object old_value | |||
| 2209 | 2188 | ||
| 2210 | NSTRACE ("ns_set_appearance"); | 2189 | NSTRACE ("ns_set_appearance"); |
| 2211 | 2190 | ||
| 2212 | #ifndef NSAppKitVersionNumber10_10 | ||
| 2213 | #define NSAppKitVersionNumber10_10 1343 | ||
| 2214 | #endif | ||
| 2215 | |||
| 2216 | if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10) | 2191 | if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10) |
| 2217 | return; | 2192 | return; |
| 2218 | 2193 | ||