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,7 +19,7 @@
# 1. It's free, we don't have to do any math on the board, just adjusting # 1. It's free, we don't have to do any math on the board, just adjusting
# an existing process. # an existing process.
# 2. We can go more granular that n-bits of color. This means that the gamma # 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. # control/quantify them.
@ -27,10 +27,10 @@
from math import pow from math import pow
def _gammavec(vals: [float], g: float) -> [float]: 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. """Computes the equivalent linear value for each bit of n_bits.
That is, the list contains scalar values that are doubling as they progress, That is, the list contains scalar values that are doubling as they progress,
@ -40,8 +40,23 @@ def _nbit_scale(f, nbits:int) -> [float]:
return [base * pow(2.0, x) for x in range(nbits)] 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. """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) linear_values = _nbit_scale(1.0, nbits)
gamma_values = _gammavec(linear_values, gamma) 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] bclk_ratio = max_clocks / gamma_values[-1]
result = [round(bclk_ratio * x) for x in gamma_values] result = [round(bclk_ratio * x) for x in gamma_values]
return result return result

View file

@ -30,3 +30,8 @@ def test_bbox():
assert not b.contains(Coord(0,0)) assert not b.contains(Coord(0,0))
# TODO: test .intersect(other) # 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))