[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master a868705 23/31: colir.el: Add two additional blend algorith
From: |
Oleh Krehel |
Subject: |
[elpa] master a868705 23/31: colir.el: Add two additional blend algorithms |
Date: |
Fri, 01 May 2015 14:29:01 +0000 |
branch: master
commit a868705fcae46304cbe3be120e644a1bfdc3226c
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
colir.el: Add two additional blend algorithms
* colir.el (colir-join): Remove.
(color): Require.
(colir-compose-method): New defcustom.
(colir-compose-soft-light): New defun.
(colir-compose-overlay): New defun.
(colir-compose-alpha): New defun.
(colir-blend): Update.
(colir-blend-face-background): Update.
---
colir.el | 55 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/colir.el b/colir.el
index 734f902..c9a0ada 100644
--- a/colir.el
+++ b/colir.el
@@ -24,28 +24,45 @@
;; This package solves the problem of adding a face with a background
;; to text which may already have a background. In all conflicting
;; areas, instead of choosing either the original or the new
-;; background face, their alpha blended sum is used.
+;; background face, their blended sum is used.
+;;
+;; The blend mode functions are taken from
http://en.wikipedia.org/wiki/Blend_modes.
;;; Code:
-(defun colir-join (r g b)
- "Build a color from R G B.
-Inverse of `color-values'."
- (format "#%02x%02x%02x"
- (ash r -8)
- (ash g -8)
- (ash b -8)))
-
-(defun colir-blend (c1 c2 &optional alpha)
- "Blend the two colors C1 and C2 with ALPHA.
-C1 and C2 are in the format of `color-values'.
-ALPHA is a number between 0.0 and 1.0 which corresponds to the
-influence of C1 on the result."
+(require 'color)
+
+(defcustom colir-compose-method 'colir-compose-overlay
+ "Select a method to compose two color channels."
+ :type '(choice
+ (const colir-compose-alpha)
+ (const colir-compose-overlay)
+ (const colir-compose-soft-light))
+ :group 'ivy)
+
+(defun colir-compose-soft-light (a b)
+ "Compose A and B channels."
+ (if (< b 0.5)
+ (+ (* 2 a b) (* a a (- 1 b b)))
+ (+ (* 2 a (- 1 b)) (* (sqrt a) (- (* 2 b) 1)))))
+
+(defun colir-compose-overlay (a b)
+ "Compose A and B channels."
+ (if (< a 0.5)
+ (* 2 a b)
+ (- 1 (* 2 (- 1 a) (- 1 b)))))
+
+(defun colir-compose-alpha (a b &optional alpha)
+ "Compose A and B channels."
(setq alpha (or alpha 0.5))
- (apply #'colir-join
+ (+ (* a alpha) (* b (- 1 alpha))))
+
+(defun colir-blend (c1 c2)
+ "Blend the two colors C1 and C2 using `colir-compose-method'.
+C1 and C2 are triples of floats in [0.0 1.0] range."
+ (apply #'color-rgb-to-hex
(cl-mapcar
- (lambda (x y)
- (round (+ (* x alpha) (* y (- 1 alpha)))))
+ colir-compose-method
c1 c2)))
(defun colir-blend-face-background (start end face &optional object)
@@ -66,8 +83,8 @@ See also `font-lock-append-text-property'."
(if background-prev
(cons `(background-color
. ,(colir-blend
- (color-values background-prev)
- (color-values (face-background face nil t))))
+ (color-name-to-rgb background-prev)
+ (color-name-to-rgb (face-background face nil
t))))
prev)
(list face prev))
object)))
- [elpa] master 57de44c 14/31: Makefile: Update, (continued)
- [elpa] master 57de44c 14/31: Makefile: Update, Oleh Krehel, 2015/05/01
- [elpa] master 56d7802 15/31: Add an option for multi-tier regex matching, Oleh Krehel, 2015/05/01
- [elpa] master 7299950 16/31: ivy.el: Fixup docstrings, Oleh Krehel, 2015/05/01
- [elpa] master aa9d4a7 17/31: ivy.el (ivy-re-builders-alist): Improve doc, Oleh Krehel, 2015/05/01
- [elpa] master 0f141f5 18/31: counsel.el (counsel-git-grep): Add optional initial-input, Oleh Krehel, 2015/05/01
- [elpa] master 23ffa25 19/31: Bind "TAB" to do partial completion, Oleh Krehel, 2015/05/01
- [elpa] master ae2fd1a 21/31: Improve hidden buffer completion further, Oleh Krehel, 2015/05/01
- [elpa] master 5dc26fb 20/31: Improve the completion of hidden buffers, Oleh Krehel, 2015/05/01
- [elpa] master 1332b19 22/31: ivy.el (ivy--exhibit): Fixup last commit, Oleh Krehel, 2015/05/01
- [elpa] master 6b2e95a 24/31: Add gamma-correction to alpha-blending, Oleh Krehel, 2015/05/01
- [elpa] master a868705 23/31: colir.el: Add two additional blend algorithms,
Oleh Krehel <=
- [elpa] master 7bd6003 25/31: Update and improve faces, Oleh Krehel, 2015/05/01
- [elpa] master 94b6a83 26/31: Don't error on bad regex, Oleh Krehel, 2015/05/01
- [elpa] master 0dd6c5a 27/31: ivy.el (ivy--regex): Fixup, Oleh Krehel, 2015/05/01
- [elpa] master fc84e0d 28/31: ivy.el (ivy-read): Reset `ivy-text' earlier, Oleh Krehel, 2015/05/01
- [elpa] master 5a1bd78 29/31: Improve TRAMP completion for ivy-mode, Oleh Krehel, 2015/05/01
- [elpa] master 5a2e0fd 30/31: Allow for "/ssh:user@" as well as for "/ssh:", Oleh Krehel, 2015/05/01
- [elpa] master 4137447 31/31: Merge commit '5a2e0fd355fea83e3c172402b965a1aa826fcc0c' from swiper, Oleh Krehel, 2015/05/01