コード例 #1
0
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),))
コード例 #2
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, ))
コード例 #3
0
def test01_basics():
    s = Struct()
    assert s.field_count() == 0
    assert s.alignment() == 1
    assert s.size() == 0

    s.append('float_val', Struct.Type.Float32)
    assert s.field_count() == 1
    assert s.alignment() == 4
    assert s.size() == 4

    s.append('byte_val', Struct.Type.UInt8)
    assert s.field_count() == 2
    assert s.alignment() == 4
    assert s.size() == 8

    s.append('half_val', Struct.Type.Float16)
    assert s.field_count() == 3
    assert s.alignment() == 4
    assert s.size() == 8

    assert len(s) == 3
    assert s[0].name == 'float_val'
    assert s[0].offset == 0
    assert s[0].size == 4
    assert s[0].type == Struct.Type.Float32

    assert s[1].name == 'byte_val'
    assert s[1].offset == 4
    assert s[1].size == 1
    assert s[1].type == Struct.Type.UInt8

    assert s[2].name == 'half_val'
    assert s[2].offset == 6
    assert s[2].size == 2
    assert s[2].type == Struct.Type.Float16