def scale_quantum_to_int8(quantum):
    if quantum <= 0:
        return 0
    table = {8: 1, 16: 257.0, 32: 16843009.0, 64: 72340172838076673.0}
    v = quantum / table[QUANTUM_DEPTH]
    if v >= 255:
        return 255
    return int(v + 0.5)
Straightforward port of :c:func:`ScaleQuantumToChar()` inline
dataset/ETHPy150Open dahlia/wand/wand/color.py/scale_quantum_to_int8