Skip to content

Commit

Permalink
Adjust TTY color, Remove colorio dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dofuuz committed Mar 22, 2023
1 parent c20b1b4 commit b9a6ec6
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 125 deletions.
87 changes: 87 additions & 0 deletions color/color_oklab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 5 17:33:26 2022
Oklab, Oklch color space conversion
Oklab: https://bottosson.github.io/posts/oklab/
@author: dof
"""

import numpy as np


FLT_MAX = np.finfo(np.float32).max


def linear_srgb_to_oklab(c):
if type(c) is not np.ndarray:
c = np.asarray(c, dtype=np.float32)

r = c[..., 0]
g = c[..., 1]
b = c[..., 2]

l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b
m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b
s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b

l_ = np.cbrt(l)
m_ = np.cbrt(m)
s_ = np.cbrt(s)

return np.stack([
0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_,
1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_,
0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_,
], axis=-1)


def oklab_to_linear_srgb(c):
if type(c) is not np.ndarray:
c = np.asarray(c, dtype=np.float32)

L = c[..., 0]
a = c[..., 1]
b = c[..., 2]

l_ = L + 0.3963377774 * a + 0.2158037573 * b
m_ = L - 0.1055613458 * a - 0.0638541728 * b
s_ = L - 0.0894841775 * a - 1.2914855480 * b

l = l_ * l_ * l_
m = m_ * m_ * m_
s = s_ * s_ * s_

return np.stack([
+4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,
], axis=-1)


def rgb_to_oklch(rgb):
lab = linear_srgb_to_oklab(rgb)
L = lab[..., 0]
a = lab[..., 1]
b = lab[..., 2]

C = np.hypot(a, b)
h = np.degrees(np.arctan2(b, a)) % 360

return np.stack([L, C, h], axis=-1)


def oklch_to_rgb(c):
if type(c) is not np.ndarray:
c = np.asarray(c, dtype=np.float32)

L = c[..., 0]
C = c[..., 1]
h = c[..., 2]

h_ = np.radians(h)
Lab = np.stack([L, C * np.cos(h_), C * np.sin(h_)], axis=-1)

return oklab_to_linear_srgb(Lab)
30 changes: 15 additions & 15 deletions color/mintty-dof
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
ForegroundColour = 213,213,213
ForegroundColour = 214,214,214
BackgroundColour = 24,24,24
CursorColour = 65,226,86
CursorColour = 79,220,83
Black = 0,0,0
BoldBlack = 127,127,127
Red = 218,90,107
BoldRed = 255,85,83
Green = 120,192,72
BoldGreen = 65,226,86
Yellow = 237,168,53
BoldYellow = 255,195,0
Blue = 13,121,230
BoldBlue = 85,136,255
Magenta = 188,108,222
BoldMagenta = 234,97,244
Cyan = 0,200,200
BoldCyan = 0,224,244
White = 213,213,213
Red = 214,62,71
BoldRed = 238,68,60
Green = 96,190,59
BoldGreen = 79,220,83
Yellow = 255,163,62
BoldYellow = 255,192,65
Blue = 26,89,236
BoldBlue = 66,120,255
Magenta = 172,78,227
BoldMagenta = 214,80,224
Cyan = 59,200,199
BoldCyan = 65,220,245
White = 214,214,214
BoldWhite = 241,241,241
30 changes: 15 additions & 15 deletions color/putty.reg
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
"Colour0"="213,213,213"
"Colour0"="214,214,214"
"Colour1"="241,241,241"
"Colour2"="24,24,24"
"Colour3"="127,127,127"
"Colour4"="24,24,24"
"Colour5"="65,226,86"
"Colour5"="79,220,83"
"Colour6"="0,0,0"
"Colour7"="127,127,127"
"Colour8"="218,90,107"
"Colour9"="255,85,83"
"Colour10"="120,192,72"
"Colour11"="65,226,86"
"Colour12"="237,168,53"
"Colour13"="255,195,0"
"Colour14"="13,121,230"
"Colour15"="85,136,255"
"Colour16"="188,108,222"
"Colour17"="234,97,244"
"Colour18"="0,200,200"
"Colour19"="0,224,244"
"Colour20"="213,213,213"
"Colour8"="214,62,71"
"Colour9"="238,68,60"
"Colour10"="96,190,59"
"Colour11"="79,220,83"
"Colour12"="255,163,62"
"Colour13"="255,192,65"
"Colour14"="26,89,236"
"Colour15"="66,120,255"
"Colour16"="172,78,227"
"Colour17"="214,80,224"
"Colour18"="59,200,199"
"Colour19"="65,220,245"
"Colour20"="214,214,214"
"Colour21"="241,241,241"
Loading

0 comments on commit b9a6ec6

Please sign in to comment.