def test12_blend(): src = Struct() src.append('a', Struct.Type.Float32) src.append('b', Struct.Type.Float32) target = Struct() target.append('v', Struct.Type.Float32) target.field('v').blend = [(3.0, 'a'), (4.0, 'b')] s = StructConverter( src, target ) check_conversion(s, '@ff', '@f', (1.0, 2.0), (3.0 + 8.0,)) src = Struct() src.append('a', Struct.Type.UInt8, Struct.Flags.Normalized) src.append('b', Struct.Type.UInt8, Struct.Flags.Normalized) target = Struct() target.append('v', Struct.Type.Float32) target.field('v').blend = [(3.0, 'a'), (4.0, 'b')] s = StructConverter( src, target ) check_conversion(s, '@BB', '@f', (255, 127), (3.0 + 4.0 * (127.0 / 255.0),))
def test13_blend_gamma(): def to_srgb(value): if value <= 0.0031308: return 12.92 * value return 1.055 * (value**(1.0 / 2.4)) - 0.055 def from_srgb(value): if value <= 0.04045: return value * 1.0 / 12.92 return ((value + 0.055) * (1.0 / 1.055))**2.4 src = Struct() src.append('a', Struct.Type.UInt8, Struct.Flags.Normalized | Struct.Flags.Gamma) src.append('b', Struct.Type.UInt8, Struct.Flags.Normalized | Struct.Flags.Gamma) target = Struct() target.append('v', Struct.Type.UInt8, Struct.Flags.Normalized | Struct.Flags.Gamma) target.field('v').blend = [(1, 'a'), (1, 'b')] s = StructConverter(src, target) ref = int( np.round( to_srgb(from_srgb(100 / 255.0) + from_srgb(200 / 255.0)) * 255)) check_conversion(s, '@BB', '@B', (100, 200), (ref, ))