diff --git a/src/groovylight/gamma.py b/src/groovylight/gamma.py index f314678..362d9db 100644 --- a/src/groovylight/gamma.py +++ b/src/groovylight/gamma.py @@ -19,19 +19,19 @@ # 1. It's free, we don't have to do any math on the board, just adjusting # an existing process. # 2. We can go more granular that n-bits of color. This means that the gamma -# curve will be effective and accurate regardless of the color depth. +# curve will be effective and accurate at a lower color depth. # -# This file contains code to generate these timing adjustments and +# This file contains code to generate these timing adjustments and # control/quantify them. from math import pow - def _gammavec(vals: [float], g: float) -> [float]: - return [pow(x,g) for x in vals] + return [pow(x, g) for x in vals] -def _nbit_scale(f, nbits:int) -> [float]: + +def _nbit_scale(f, nbits: int) -> [float]: """Computes the equivalent linear value for each bit of n_bits. That is, the list contains scalar values that are doubling as they progress, [ x, 2x, 4x ] such that the sum(list) = 7x = f @@ -40,8 +40,23 @@ def _nbit_scale(f, nbits:int) -> [float]: return [base * pow(2.0, x) for x in range(nbits)] -def gamma_timings(gamma:float = 2.2, nbits:int = 8, max_clocks: int = 4096): +def gamma_timings(gamma: float = 2.2, nbits: int = 8, max_clocks: int = 8192): """Computes the clock cycle timings for a given gamma correction. + + Parameters + ---------- + gamma : float, optional + The gamma value of the resulting timings + nbits : int, optional + The number of available bit timings. This is used to determine the length of the + resulting array + max_clocks : int, optional + The longest number of clocks to use as a bit-timing. + + Returns + ------- + list of int + The per-bit exposure timings, in clock cycles. """ linear_values = _nbit_scale(1.0, nbits) gamma_values = _gammavec(linear_values, gamma) @@ -49,4 +64,3 @@ def gamma_timings(gamma:float = 2.2, nbits:int = 8, max_clocks: int = 4096): bclk_ratio = max_clocks / gamma_values[-1] result = [round(bclk_ratio * x) for x in gamma_values] return result - diff --git a/src/groovylight/tests/test_geom.py b/src/groovylight/tests/test_geom.py index 47b8a07..cc698dd 100644 --- a/src/groovylight/tests/test_geom.py +++ b/src/groovylight/tests/test_geom.py @@ -30,3 +30,8 @@ def test_bbox(): assert not b.contains(Coord(0,0)) # TODO: test .intersect(other) + + with pytest.raises(RuntimeError): + BBox(Coord(0,0), Coord(1,0)) + with pytest.raises(RuntimeError): + BBox(Coord(1,1), Coord(0,0))