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

Colir blender will not work correctly in terminal #541

Closed
aslpavel opened this Issue Jun 6, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@aslpavel
Contributor

aslpavel commented Jun 6, 2016

The problem is that built-in color-name-to-rgb methods is trying to map color to available color space which is 256 colors in best case.

ELISP> (apply 'color-rgb-to-hex (color-name-to-rgb "#ff8040"))
"#ff875f"

So color is already distorted before blending. One solution might be just manually parse colors if they start with # and fall back to color-name-to-rgb otherwise.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jun 6, 2016

I don't see the problem with my theme (eclipse-theme). I don't use Emacs in the terminal at all, but checking just now, the colors are indeed slightly off from the graphical variant, but actually are the closest within the palette.

Can you describe your problem in more detail, maybe propose a solution?

@aslpavel

This comment has been minimized.

Contributor

aslpavel commented Jun 6, 2016

Sure. The problem is that with my color when I use terminal, active line not that visible as it should be.
It is especially noticeable as I use 24-bit terminal and emacs. I think good solution at least from my point of view would be just use custom function to convert string to rgb if it starts with # symbol. This function is easy to implement. I had the same issue with my custom theme and color blending and I worked around this problem with something like this.

(defun palette-color-blend (base-color mix-color mix-alpha)
  "Blends BASE-COLOR under MIX-COLOR with MIX-ALPHA."
  (let* ((blend (lambda (base mix) (+ (* mix mix-alpha) (* base (- 1 mix-alpha)))))
         ;; color-name-to-rgb (breaks color in terminal)
         (hex-to-rgb (lambda (hex)
                       (if (and (eq 7 (length hex))
                                (equal "#" (substring hex 0 1)))
                           (mapcar (lambda (c) (/ (string-to-number c 16) (float 255)))
                                   (list (substring hex 1 3)
                                         (substring hex 3 5)
                                         (substring hex 5 7)))
                         )))
         (rgb-to-hex (lambda (rgb) (apply 'format "#%02x%02x%02x"
                                     (mapcar (lambda (c) (* c 255)) rgb))))
         (base-rgb (funcall hex-to-rgb base-color))
         (mix-rgb  (funcall hex-to-rgb mix-color)))
    (if (and base-rgb mix-rgb)
        (funcall rgb-to-hex
                 (list (funcall blend (nth 0 base-rgb) (nth 0 mix-rgb))
                       (funcall blend (nth 1 base-rgb) (nth 1 mix-rgb))
                       (funcall blend (nth 2 base-rgb) (nth 2 mix-rgb)))))
    ))

The thing is for whatever reason emacs built-in functions are mapping colors to available color space of 256, while it should actually map it only when it displays it.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jun 6, 2016

Could you please PR with your change? The new function could be another setting for colir-compose-method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment