Skip to content

Commit

Permalink
Fix image colors on MacOS (#141)
Browse files Browse the repository at this point in the history
Fixes #54.

Adds a custom option 'powerline-image-apple-rgb', which should be set
to 't' to enable the workaround. When the option is set, powerline's
XPM images are generated using equivalent Apple RGB colors, instead of
the regular sRGB colors.

This is not needed on the Emacs-mac port, or when Apple RGB colors are
used by setting 'ns-use-srgb-colorspace' to nil.
  • Loading branch information
anuragm authored and milkypostman committed Jul 8, 2017
1 parent 67538e4 commit 8a24690
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion powerline-separators.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,25 @@ COLOR1 and COLOR2 must be supplied as hex strings with a leading #."
(blue (/ (+ (nth 2 c1) (nth 2 c2)) 2)))
(color-rgb-to-hex red green blue)))

(defun pl/color-xyz-to-apple-rgb (X Y Z)
"Convert CIE X Y Z colors to Apple RGB color space."
(let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z)))
(g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z)))
(b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z))))
(list (expt r (/ 1.8)) (expt g (/ 1.8)) (expt b (/ 1.8)))))

(defun pl/color-srgb-to-apple-rgb (red green blue)
"Convert RED GREEN BLUE colors from sRGB color space to Apple RGB.
RED, GREEN and BLUE should be between 0.0 and 1.0, inclusive."
(apply 'pl/color-xyz-to-apple-rgb (color-srgb-to-xyz red green blue)))

(defun pl/hex-color (color)
"Get the hexadecimal value of COLOR."
(when color
(apply 'color-rgb-to-hex (color-name-to-rgb color))))
(let ((srgb-color (color-name-to-rgb color)))
(if powerline-image-apple-rgb
(apply 'color-rgb-to-hex (apply 'pl/color-srgb-to-apple-rgb srgb-color))
(apply 'color-rgb-to-hex srgb-color)))))

(defun pl/pattern (lst)
"Turn LST into an infinite pattern."
Expand Down
9 changes: 9 additions & 0 deletions powerline.el
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ This is needed to make sure that text is properly aligned."
:group 'powerline
:type 'boolean)

(defcustom powerline-image-apple-rgb nil
"When t, Use Apple RGB colors for image generation.
On MacOS, sRGB colors are used for all GUI elements, except for image generation
which uses Apple RGB color space. When this option is set, theme colors are
converted to equivalent Apple RGB colors before image generation."
:group 'powerline
:type 'boolean)

(defcustom powerline-gui-use-vcs-glyph nil
"Display a unicode character to represent a version control system. Not always supported in GUI."
:group 'powerline
Expand Down

0 comments on commit 8a24690

Please sign in to comment.