-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NSCalibratedRGBColorSpace
support.
#4202
Conversation
**Problems** Ghostty is using sRGB by default, optionally Display P3 color space. However neither color space matches to the color space that the regular macOS apps are using. That is `NSCalibratedRGBColorSpace`, seems called "Generic RGB" from initializer API name. Because of this, colors has same hex value are slightly darker on Ghostty compare to Terminal.app, for example. **Solution** Add `generic-rgb` to `WindowColorspace`, therefore users can set `window-colorspace` to `generic-rgb` in config to have similar colors with the other macOS apps.
e1ef552
to
ed5b692
Compare
(I am not part of Ghostty development but let me leave a comment since I worked on alacritty/alacritty#6602 before, which is cited in the corresponding Ghostty PR #376)
Are we sure about this? Assuming we are talking about "how apps should render specified RGB tuple such as Choosing anything other than sRGB makes colorschemes look different from other places, notably on web browsers and I guess for I would consider this option as a "temporary hack" to make it look the same as other apps in specific situations without modifying colorscheme / color code. If anyone just wants to use "more vivid colors than sRGB can express", they should use P3 color space, which should look the same across displays. In an ideal world we should not neither use P3 as global config as well though. Each color should optionally specify color space such as P3 like we can do for the web (cf. https://webkit.org/blog/10042/wide-gamut-color-in-css-with-display-p3/) |
I found more relevant discussions so linking here for a reference:
|
I think the root problem is RGB color space is device dependent and each RGB values may have different result on each system depends on how the values are interrpted by the application and the system, unlike, for example, the image file that contains a profile describes how to interrupt their RGB values to reproduce colors or other device independnt color values such as CIE L*a*b. I certianly agree that, in general, color schema and many RGB values avilable on the internet are created and assumed to be used in sRGB color space and implicity asked applications to interrupt these RGB values in sRGB, and current Ghostty implementation is reasonable to do so by default, and also allow uses to use Display P3, if users knows their RGB values are in Display P3 optionally, which is good. My point is, however, many other native macOS applications made with AppKit using RGB values, for example some text editor app that let users to pick colors for the syntax highlighting using system color picker and display the RGB values in their user interface, in the implementation, uses Ideally, I think, all RGB color values in the wild are associated with a color space information, but that wound unlikly be happening... |
@naruaway oops, I sent my last comment before reading your last comment, please forgive me if I said something that is coflicting with it. |
No conflict! Thanks for the additional comment 🙏
I am little bit skeptical about the need for this ("similar behavior") though. For "user picks up colors using system color picker to choose colors to be shown" case, there is no GUI colorpicker so this is not applicable. The only way to specify colors in Ghostty right now is via text config file or via 3rd party web based tools such as https://ghostty.zerebos.com/settings/colors. For the former, I think people will assume sRGB and for the latter, the color in the web UI is shown in sRGB. For "Therefore, if users copied and pasted such RGB values into the config file for Ghostty", I think we can convert them into sRGB before copy-pasting them. This is actually good thing by itself since now the colorscheme will be display-independent. Changing Ghostty global config just to allow direct copy-pasting does not sound a good trade-off since this config will affect colors from escape sequences as well. In any way, I think we should clarify (in Ghostty documentation?) that specifying |
I don’t disagree with this, probably rare case for sure... but I did, then found this.
Certainly, when Ghostty has for example an GUI to let users to pick colors visually then sure the RGB value will be stored in sRGB color space. And in that mean, actually, this can be “temporary hack.” I agree with having a doumentation (and with a brief color space expranation) would help a lot for users to do what thay want to do. |
I would like to reproduce the problem so I tried but I somehow could not... @niw Do you have reproduction steps? I am using MacBook Air (M2, 2022) and macOS version is 15.2 (24C101). First, I opened Terminal.app and created a new profile, changed regular green color via color picker with "RGB Sliders" by specifying RGB hex ( Interestingly, using Digital Color Meter, this green is actually So somehow in my environment, everything here is in sRGB... |
@naruaway Ooh, I found this Color Space option in color palette! Now I am feeling this patch is really not right thing to do, instead as you mentioned, use this to convert color to sRGB and use it in Ghostty instead of adding ability to Ghostty to use Generic RGB instead. I think on your color palette, sRGB is selected instead. |
Note that for people who wants to convert hex values in "Generic RGB" already stored in some place, you can use the following Swift code: // Save this as "generic-rgb-to-srgb.swift" and run it with "swift generic-rgb-to-srgb.swift" on macOS
import Cocoa
func genericRgbToSrgb(hex: Int) -> String {
let red = CGFloat((hex >> 16) & 0xFF) / 255.0
let green = CGFloat((hex >> 8) & 0xFF) / 255.0
let blue = CGFloat(hex & 0xFF) / 255.0
let genericRGBColor = NSColor(calibratedRed: red, green: green, blue: blue, alpha: 1.0)
guard let sRGBColor = genericRGBColor.usingColorSpace(.sRGB) else {
fatalError("Failed to convert color to sRGB")
}
let sRGBRed = Int(round(sRGBColor.redComponent * 255.0))
let sRGBGreen = Int(round(sRGBColor.greenComponent * 255.0))
let sRGBBlue = Int(round(sRGBColor.blueComponent * 255.0))
return String(format: "#%02X%02X%02X", sRGBRed, sRGBGreen, sRGBBlue)
}
print(genericRgbToSrgb(hex: 0x39934E)) I verified that this prints |
Okay since there is enough info and findings about color and color space for using it on Ghostty config on this thread, and I am now feeling this patch is not necessary, also and the successor would be implementing GUI config interface that can accept colors with atribtrary color space e.g. General RGB and can convert it to application color space, likely sRGB (or if not, then use Display P3, for example.) I am going to close this pull request. |
Problem
Ghostty is using sRGB by default, optionally Display P3 color space. However neither color space matches to the color space that the regular macOS apps are using.
That is
NSCalibratedRGBColorSpace
, seems called "Generic RGB" from initializer API name.Because of this, colors has same hex value are slightly stronger on Ghostty compare to Terminal.app, for example.
Solution
Add
generic-rgb
toWindowColorspace
, therefore users can setwindow-colorspace
togeneric-rgb
in config to have similar colors with the other macOS apps.