-
-
Save dunielpls/caee90d2d975b1f6d1c9e28da52e7f1d to your computer and use it in GitHub Desktop.
Invert the luminosity of Wireshark packets (for dark themes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import fileinput | |
import re | |
from colorsys import * | |
def rgb_to_hsl(r, g, b): | |
return hsv_to_hsl(*rgb_to_hsv(r, g, b)) | |
def hsl_to_rgb(h, s, l): | |
return hsv_to_rgb(*hsl_to_hsv(h, s, l)) | |
def hsv_to_hsl(h, s, v): | |
l = v - v * s / 2 | |
s = 0 if l == 0 or l == 1 else (v - l) / min(l, 1 - l) | |
return h, s, l | |
def hsl_to_hsv(h, s, l): | |
v = l + s * min(l, 1 - l) | |
s = 0 if v == 0 else 2 - 2 * l / v | |
return h, s, v | |
def process(rgb): | |
rgb = [int(x) / 65535 for x in rgb] | |
hsl = [*rgb_to_hsl(*rgb)] | |
hsl[2] = 1 - hsl[2] | |
return [round(x * 65535) for x in hsl_to_rgb(*hsl)] | |
for line in fileinput.input(): | |
if len(line) == 0 or line[0] == '#': | |
continue | |
# line format: @name@filter@[0,0,0][65535,65535,65535] | |
colours = re.findall('\[(.*?)\]', line.split('@')[-1]) | |
bg, fg = [process(x.split(',')) for x in colours] | |
new_colours = '[%d,%d,%d][%d,%d,%d]' % (*bg, *fg) | |
print(re.sub('[^@]+$', new_colours, line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment