add bbox construction tests, gamma docstring
Some checks failed
Verilator Unit Tests / Test (push) Failing after 3m33s

This commit is contained in:
Saji 2024-09-21 10:04:54 -05:00
parent dd47014029
commit 5820d80db2
2 changed files with 26 additions and 7 deletions

View file

@ -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

View file

@ -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))