mirror of
https://github.com/yshui/picom.git
synced 2024-11-03 04:33:49 -05:00
Remove compton-convgen.py
We have better blur configuration built into the compositor by now. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
f227e6c8c7
commit
cdcdda8ed8
3 changed files with 2 additions and 164 deletions
|
@ -1,161 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
import math
|
||||
import argparse
|
||||
|
||||
|
||||
class CGError(Exception):
|
||||
'''An error in the convolution kernel generator.'''
|
||||
def __init__(self, desc):
|
||||
super().__init__(desc)
|
||||
|
||||
|
||||
class CGBadArg(CGError):
|
||||
'''An exception indicating an invalid argument has been passed to the
|
||||
convolution kernel generator.'''
|
||||
pass
|
||||
|
||||
|
||||
def mbuild(width, height):
|
||||
"""Build a NxN matrix filled with 0."""
|
||||
result = list()
|
||||
for i in range(height):
|
||||
result.append(list())
|
||||
for j in range(width):
|
||||
result[i].append(0.0)
|
||||
return result
|
||||
|
||||
|
||||
def mdump(matrix):
|
||||
"""Dump a matrix in natural format."""
|
||||
for col in matrix:
|
||||
print("[ ", end='')
|
||||
for ele in col:
|
||||
print(format(ele, "13.6g") + ", ", end=" ")
|
||||
print("],")
|
||||
|
||||
|
||||
def mdumpcompton(matrix):
|
||||
"""Dump a matrix in compton's format."""
|
||||
width = len(matrix[0])
|
||||
height = len(matrix)
|
||||
print("{},{},".format(width, height), end='')
|
||||
for i in range(height):
|
||||
for j in range(width):
|
||||
if int(height / 2) == i and int(width / 2) == j:
|
||||
continue
|
||||
print(format(matrix[i][j], ".6f"), end=",")
|
||||
print()
|
||||
|
||||
|
||||
def mnormalize(matrix):
|
||||
"""Scale a matrix according to the value in the center."""
|
||||
width = len(matrix[0])
|
||||
height = len(matrix)
|
||||
factor = 1.0 / matrix[int(height / 2)][int(width / 2)]
|
||||
if 1.0 == factor:
|
||||
return matrix
|
||||
for i in range(height):
|
||||
for j in range(width):
|
||||
matrix[i][j] *= factor
|
||||
return matrix
|
||||
|
||||
|
||||
def mmirror4(matrix):
|
||||
"""Do a 4-way mirroring on a matrix from top-left corner."""
|
||||
width = len(matrix[0])
|
||||
height = len(matrix)
|
||||
for i in range(height):
|
||||
for j in range(width):
|
||||
x = min(i, height - 1 - i)
|
||||
y = min(j, width - 1 - j)
|
||||
matrix[i][j] = matrix[x][y]
|
||||
return matrix
|
||||
|
||||
|
||||
def gen_gaussian(width, height, factors):
|
||||
"""Build a Gaussian blur kernel."""
|
||||
|
||||
if width != height:
|
||||
raise CGBadArg("Cannot build an uneven Gaussian blur kernel.")
|
||||
|
||||
size = width
|
||||
sigma = float(factors.get('sigma', 0.84089642))
|
||||
|
||||
result = mbuild(size, size)
|
||||
for i in range(int(size / 2) + 1):
|
||||
for j in range(int(size / 2) + 1):
|
||||
diffx = i - int(size / 2)
|
||||
diffy = j - int(size / 2)
|
||||
result[i][j] = 1.0 / (2 * math.pi * sigma) \
|
||||
* pow(math.e, - (diffx * diffx + diffy * diffy) \
|
||||
/ (2 * sigma * sigma))
|
||||
mnormalize(result)
|
||||
mmirror4(result)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def gen_box(width, height, factors):
|
||||
"""Build a box blur kernel."""
|
||||
result = mbuild(width, height)
|
||||
for i in range(height):
|
||||
for j in range(width):
|
||||
result[i][j] = 1.0
|
||||
return result
|
||||
|
||||
|
||||
def _gen_invalid(width, height, factors):
|
||||
'''Handle a convolution kernel generation request of an unrecognized type.'''
|
||||
raise CGBadArg("Unknown kernel type.")
|
||||
|
||||
|
||||
def _args_readfactors(lst):
|
||||
"""Parse the factor arguments."""
|
||||
factors = dict()
|
||||
if lst:
|
||||
for s in lst:
|
||||
res = s.partition('=')
|
||||
if not res[0]:
|
||||
raise CGBadArg("Factor has no key.")
|
||||
if not res[2]:
|
||||
raise CGBadArg("Factor has no value.")
|
||||
factors[res[0]] = float(res[2])
|
||||
return factors
|
||||
|
||||
|
||||
def _parse_args():
|
||||
'''Parse the command-line arguments.'''
|
||||
|
||||
parser = argparse.ArgumentParser(description='Build a convolution kernel.')
|
||||
parser.add_argument('type', help='Type of convolution kernel. May be "gaussian" (factor sigma = 0.84089642) or "box".')
|
||||
parser.add_argument('width', type=int, help='Width of convolution kernel. Must be an odd number.')
|
||||
parser.add_argument('height', nargs='?', type=int, help='Height of convolution kernel. Must be an odd number. Equals to width if omitted.')
|
||||
parser.add_argument('-f', '--factor', nargs='+', help='Factors of the convolution kernel, in name=value format.')
|
||||
parser.add_argument('--dump-compton', action='store_true', help='Dump in compton format.')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _main():
|
||||
args = _parse_args()
|
||||
|
||||
width = args.width
|
||||
height = args.height
|
||||
if not height:
|
||||
height = width
|
||||
if not (width > 0 and height > 0):
|
||||
raise CGBadArg("Invalid width/height.")
|
||||
factors = _args_readfactors(args.factor)
|
||||
|
||||
funcs = dict(gaussian=gen_gaussian, box=gen_box)
|
||||
matrix = (funcs.get(args.type, _gen_invalid))(width, height, factors)
|
||||
if args.dump_compton:
|
||||
mdumpcompton(matrix)
|
||||
else:
|
||||
mdump(matrix)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
_main()
|
|
@ -200,7 +200,7 @@ A 7x7 Gaussian blur kernel (sigma = 0.84089642) looks like:
|
|||
--blur-kern '7,7,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000102,0.003494,0.029143,0.059106,0.029143,0.003494,0.000102,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000102,0.003494,0.029143,0.059106,0.029143,0.003494,0.000102,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003'
|
||||
----
|
||||
+
|
||||
May also be one of the predefined kernels: `3x3box` (default), `5x5box`, `7x7box`, `3x3gaussian`, `5x5gaussian`, `7x7gaussian`, `9x9gaussian`, `11x11gaussian`. All Gaussian kernels are generated with sigma = 0.84089642 . You may use the accompanied `compton-convgen.py` to generate blur kernels.
|
||||
May also be one of the predefined kernels: `3x3box` (default), `5x5box`, `7x7box`, `3x3gaussian`, `5x5gaussian`, `7x7gaussian`, `9x9gaussian`, `11x11gaussian`. All Gaussian kernels are generated with sigma = 0.84089642 . If you find yourself needing to generate custom blur kernels, you might want to try the new blur configuration supported by the experimental backends (See *BLUR* and *--experimental-backends*).
|
||||
|
||||
*--blur-background-exclude* 'CONDITION'::
|
||||
Exclude conditions for background blur.
|
||||
|
|
|
@ -69,8 +69,7 @@ test_h_dep = subproject('test.h').get_variable('test_h_dep')
|
|||
subdir('src')
|
||||
subdir('man')
|
||||
|
||||
install_data(['bin/compton-convgen.py', 'bin/compton-trans'],
|
||||
install_dir: get_option('bindir'))
|
||||
install_data('bin/compton-trans', install_dir: get_option('bindir'))
|
||||
install_data('compton.desktop', install_dir: 'share/applications')
|
||||
install_data('media/icons/48x48/compton.png',
|
||||
install_dir: 'share/icons/hicolor/48x48/apps')
|
||||
|
|
Loading…
Reference in a new issue