def c2p():
    m0 = Word.Mask('00ff')
    m1 = Word.Mask('0f0f')

    print "=[ c2p 1x1 ham6 (blitter + mangled) ]=".center(48, '-')

    def MakeWord(c, color):
        # mangle: [ 0  0  0  0 r0 r1 r2 r3 g0 g1 g2 g3 b0 b1 b2 b3] =>
        #         [r0 g0 b0 b0 r1 g1 b1 b1 r2 g2 b2 b2 r3 g3 b3 b3]
        return Word([
            Bit.Var(c[0], 0, color),
            Bit.Var(c[1], 0, color),
            Bit.Var(c[2], 0, color),
            Bit.Var(c[3], 0, color),
            Bit.Var(c[0], 1, color),
            Bit.Var(c[1], 1, color),
            Bit.Var(c[2], 1, color),
            Bit.Var(c[3], 1, color),
            Bit.Var(c[0], 2, color),
            Bit.Var(c[1], 2, color),
            Bit.Var(c[2], 2, color),
            Bit.Var(c[3], 2, color),
            Bit.Var(c[0], 3, color),
            Bit.Var(c[1], 3, color),
            Bit.Var(c[2], 3, color),
            Bit.Var(c[3], 3, color)
        ])

    A = Array.Make(MakeWord)
    N = len(A)
    Array.Print("Data:", *A)

    B = Array.Zero(N, 16)
    Blit(lambda a, b: ((a >> 8) & m0) | (b & ~m0), N / 4, 2, Channel(A, 2, 2),
         Channel(A, 0, 2), Channel(B, 0, 2))
    Blit(lambda a, b: ((a << 8) & ~m0) | (b & m0), N / 4, 2, Channel(A, 0, 2),
         Channel(A, 2, 2), Channel(B, 2, 2))
    Array.Print("Swap 8x4:", *B)

    C = [Array.Zero(N / 4, 16) for i in range(4)]
    Blit(lambda a, b: ((a >> 4) & m1) | (b & ~m1), N / 4, 1, Channel(B, 1, 3),
         Channel(B, 0, 3), Channel(C[0]))
    Blit(lambda a, b: ((a >> 4) & m1) | (b & ~m1), N / 4, 1, Channel(B, 3, 3),
         Channel(B, 2, 3), Channel(C[2]))
    Blit(lambda a, b: ((a << 4) & ~m1) | (b & m1), N / 4, 1, Channel(B, 0, 3),
         Channel(B, 1, 3), Channel(C[1]))
    Blit(lambda a, b: ((a << 4) & ~m1) | (b & m1), N / 4, 1, Channel(B, 2, 3),
         Channel(B, 3, 3), Channel(C[3]))
    print("Bitplanes:")
    Array.Print("[0]:", *C[0])
    Array.Print("[1]:", *C[1])
    Array.Print("[2]:", *C[2])
    Array.Print("[3]:", *C[3])
def c2p(bitplane_output=True):
    m0 = Word.Mask('ff00')
    m1 = Word.Mask('f0f0')
    m2 = Word.Mask('cccc')

    print "=[ c2p 1x1 4bpl (blitter + mangled) ]=".center(48, '-')

    def MakeWord(c, color):
        return Word([
            Bit.Var(c[0], 0, color),
            Bit.Var(c[1], 0, color),
            Bit.Var(c[0], 2, color),
            Bit.Var(c[1], 2, color),
            Bit.Var(c[0], 1, color),
            Bit.Var(c[1], 1, color),
            Bit.Var(c[0], 3, color),
            Bit.Var(c[1], 3, color),
            Bit.Var(c[2], 0, color),
            Bit.Var(c[3], 0, color),
            Bit.Var(c[2], 2, color),
            Bit.Var(c[3], 2, color),
            Bit.Var(c[2], 1, color),
            Bit.Var(c[3], 1, color),
            Bit.Var(c[2], 3, color),
            Bit.Var(c[3], 3, color)
        ])

    A = Array.Make(MakeWord)
    N = len(A)
    Array.Print("Data:", *A)

    B = Array.Zero(N, 16)
    Blit(lambda a, b: (a & m0) | ((b >> 8) & ~m0), N / 4, 2, Channel(A, 0, 2),
         Channel(A, 2, 2), Channel(B, 0, 2))
    Blit(lambda a, b: ((a << 8) & m0) | (b & ~m0), N / 4, 2, Channel(A, 0, 2),
         Channel(A, 2, 2), Channel(B, 2, 2))
    Array.Print("Swap 8x4:", *B)

    C = Array.Zero(N, 16)
    Blit(lambda a, b: (a & m1) | ((b >> 4) & ~m1), N / 2, 1, Channel(B, 0, 1),
         Channel(B, 1, 1), Channel(C, 0, 1))
    Blit(lambda a, b: ((a << 4) & m1) | (b & ~m1), N / 2, 1, Channel(B, 0, 1),
         Channel(B, 1, 1), Channel(C, 1, 1))
    Array.Print("Swap 4x2:", *C)

    if bitplane_output:
        D = [Array.Zero(N / 4, 16) for i in range(4)]
        Blit(lambda a, b: (a & m2) | ((b >> 2) & ~m2), N / 4, 1,
             Channel(C, 0, 3), Channel(C, 2, 3), Channel(D[0], 0, 0))
        Blit(lambda a, b: (a & m2) | ((b >> 2) & ~m2), N / 4, 1,
             Channel(C, 1, 3), Channel(C, 3, 3), Channel(D[1], 0, 0))
        Blit(lambda a, b: ((a << 2) & m2) | (b & ~m2), N / 4, 1,
             Channel(C, 0, 3), Channel(C, 2, 3), Channel(D[2], 0, 0))
        Blit(lambda a, b: ((a << 2) & m2) | (b & ~m2), N / 4, 1,
             Channel(C, 1, 3), Channel(C, 3, 3), Channel(D[3], 0, 0))
        print("Bitplanes:")
        Array.Print("[0]:", *D[0])
        Array.Print("[1]:", *D[1])
        Array.Print("[2]:", *D[2])
        Array.Print("[3]:", *D[3])
    else:
        D = Array.Zero(N, 16)
        Blit(lambda a, b: ((a >> 2) & ~m2) | (b & m2), N / 4, 2,
             Channel(C, 2, 2), Channel(C, 0, 2), Channel(D, 0, 2))
        Blit(lambda a, b: ((a << 2) & m2) | (b & ~m2), N / 4, 2,
             Channel(C, 0, 2), Channel(C, 2, 2), Channel(D, 2, 2))
        Array.Print("Swap 2x2:", *D)
Exemplo n.º 3
0
def c2p(bitplane_output=True):
    m0 = Word.Mask('00ff')
    m1 = Word.Mask('0f0f')
    m2 = Word.Mask('5555')

    print "=[ c2p 2x1 4bpl (blitter + mangled) ]=".center(48, '-')

    # premangled pixels:
    # 1) [- - - - a b c d] => [a b - - c d - -]
    # 2) [- - - - e f g h] => [- - e f - - g h]
    def MakeWord(c, color):
        return Word([Bit.Var(c[0], 0, color),
                     Bit.Var(c[0], 1, color),
                     Bit.Var(c[1], 0, color),
                     Bit.Var(c[1], 1, color),
                     Bit.Var(c[0], 2, color),
                     Bit.Var(c[0], 3, color),
                     Bit.Var(c[1], 2, color),
                     Bit.Var(c[1], 3, color),
                     Bit.Var(c[2], 0, color),
                     Bit.Var(c[2], 1, color),
                     Bit.Var(c[3], 0, color),
                     Bit.Var(c[3], 1, color),
                     Bit.Var(c[2], 2, color),
                     Bit.Var(c[2], 3, color),
                     Bit.Var(c[3], 2, color),
                     Bit.Var(c[3], 3, color)])

    A = Array.Make(MakeWord)
    N = len(A)
    Array.Print("Data:", *A)

    B = Array.Zero(N, 16)
    Blit(lambda a, b: ((a >> 8) & m0) | (b & ~m0),
         N / 2, 1, Channel(A, 1, 1), Channel(A, 0, 1), Channel(B, 0, 1))
    Blit(lambda a, b: ((a << 8) & ~m0) | (b & m0),
         N / 2, 1, Channel(A, 0, 1), Channel(A, 1, 1), Channel(B, 1, 1))
    Array.Print("Swap 8x2:", *B)

    C = Array.Zero(N, 16)
    Blit(lambda a, b: ((a & ~m1) | ((b >> 4) & m1)),
         N / 2, 1, Channel(B, 0, 1), Channel(B, 1, 1), Channel(C, 0, 1))
    Blit(lambda a, b: (((a << 4) & ~m1) | (b & m1)),
         N / 2, 1, Channel(B, 0, 1), Channel(B, 1, 1), Channel(C, 1, 1))
    Array.Print("Swap 4x2:", *C)

    if bitplane_output:
        D = [Array.Zero(N / 2, 16) for i in range(4)]
        Blit(lambda a, b: (((a >> 1) & m2) | (b & ~m2)),
             N / 2, 1, Channel(C, 0, 1), Channel(C, 0, 1), Channel(D[0], 0, 0))
        Blit(lambda a, b: (((a >> 1) & m2) | (b & ~m2)),
             N / 2, 1, Channel(C, 1, 1), Channel(C, 1, 1), Channel(D[2], 0, 0))
        Blit(lambda a, b: (((a << 1) & ~m2) | (b & m2)),
             N / 2, 1, Channel(C, 0, 1), Channel(C, 0, 1), Channel(D[1], 0, 0))
        Blit(lambda a, b: (((a << 1) & ~m2) | (b & m2)),
             N / 2, 1, Channel(C, 1, 1), Channel(C, 1, 1), Channel(D[3], 0, 0))
        print("Bitplanes:")
        Array.Print("[0]:", *D[0])
        Array.Print("[1]:", *D[1])
        Array.Print("[2]:", *D[2])
        Array.Print("[3]:", *D[3])
    else:
        D = Array.Zero(N * 2, 16)
        Blit(lambda a, b: (((a >> 1) & m2) | (b & ~m2)),
             N, 1, Channel(C, 0, 0), Channel(C, 0, 0), Channel(D, 0, 1))
        Blit(lambda a, b: (((a << 1) & ~m2) | (b & m2)),
             N, 1, Channel(C, 0, 0), Channel(C, 0, 0), Channel(D, 1, 1))
        Array.Print("Expand 2x1:", *D)
def c2p(bitplane_output=True):
    print "=[ c2p 2x1 4bpl (blitter + mangled) ]=".center(48, '-')

    # premangled pixels:
    # 1) [- - - - a b c d] => [a b - - c d - -]
    # 2) [- - - - e f g h] => [- - e f - - g h]
    def MakeWord(c, color):
        return Word([
            Bit.Var(c[0], 0, color),
            Bit.Var(c[0], 1, color),
            Bit.Var(c[1], 0, color),
            Bit.Var(c[1], 1, color),
            Bit.Var(c[0], 2, color),
            Bit.Var(c[0], 3, color),
            Bit.Var(c[1], 2, color),
            Bit.Var(c[1], 3, color),
            Bit.Var(c[2], 0, color),
            Bit.Var(c[2], 1, color),
            Bit.Var(c[3], 0, color),
            Bit.Var(c[3], 1, color),
            Bit.Var(c[2], 2, color),
            Bit.Var(c[2], 3, color),
            Bit.Var(c[3], 2, color),
            Bit.Var(c[3], 3, color)
        ])

    # premangled pixel buffer: [AB CD EF GH] => [AB EF CD GH]
    def ArrayMake(fn):
        return [
            fn("abef", color="31m"),
            fn("cdgh", color="32m"),
            fn("ijmn", color="33m"),
            fn("klop", color="34m"),
            fn("qruv", color="35m"),
            fn("stwx", color="36m"),
            fn("ABEF", color="31;1m"),
            fn("CDGH", color="32;1m"),
            fn("IJMN", color="33;1m"),
            fn("KLOP", color="34;1m"),
            fn("QRUV", color="35;1m"),
            fn("STWX", color="36;1m")
        ]

    A = ArrayMake(MakeWord)
    N = len(A)
    Array.Print("Data:", *A)

    m0 = Word.Mask('f0f0')
    m1 = Word.Mask('aaaa')

    B = [Array.Zero(N / 2, 16) for i in range(2)]
    Blit(lambda a, b: (a & m0) | ((b >> 4) & ~m0), N / 2, 1, Channel(A, 0, 1),
         Channel(A, 1, 1), Channel(B[0]))
    Blit(lambda a, b: ((a << 4) & m0) | (b & ~m0), N / 2, 1, Channel(A, 0, 1),
         Channel(A, 1, 1), Channel(B[1]))
    print("Swap 4x2:")
    Array.Print("[0]:", *B[0])
    Array.Print("[1]:", *B[1])

    C = [Array.Zero(N / 2, 16) for i in range(4)]
    Blit(lambda a, b: (a & m1) | ((b >> 1) & ~m1), N / 2, 1, Channel(B[0]),
         Channel(B[0]), Channel(C[0]))
    Blit(lambda a, b: (a & m1) | ((b >> 1) & ~m1), N / 2, 1, Channel(B[1]),
         Channel(B[1]), Channel(C[2]))
    Blit(lambda a, b: ((a << 1) & m1) | (b & ~m1), N / 2, 1, Channel(B[0]),
         Channel(B[0]), Channel(C[1]))
    Blit(lambda a, b: ((a << 1) & m1) | (b & ~m1), N / 2, 1, Channel(B[1]),
         Channel(B[1]), Channel(C[3]))
    print("Expand 2x1:")
    Array.Print("[0]:", *C[0])
    Array.Print("[1]:", *C[1])
    Array.Print("[2]:", *C[2])
    Array.Print("[3]:", *C[3])
Exemplo n.º 5
0
def c2p(bitplane_output=True):
    m0 = Word.Mask('00ff')
    m1 = Word.Mask('0f0f')
    m2 = Word.Mask('3333')
    m3 = Word.Mask('5555')

    print "=[ c2p 1x1 4bpl (blitter) ]=".center(48, '-')

    def MakeWord(chars, color):
        bits = []
        for c in chars:
            for i in range(4):
                bits.append(Bit.Var(c, i, color))
        return Word(bits)

    A = Array.Make(MakeWord)
    N = len(A)
    Array.Print("Data:", *A)

    B = Array.Zero(N, 16)
    Blit(lambda a, b: ((a >> 8) & m0) | (b & ~m0), N / 4, 2, Channel(A, 2, 2),
         Channel(A, 0, 2), Channel(B, 0, 2))
    Blit(lambda a, b: ((a << 8) & ~m0) | (b & m0), N / 4, 2, Channel(A, 0, 2),
         Channel(A, 2, 2), Channel(B, 2, 2))
    Array.Print("Swap 8x4:", *B)

    C = Array.Zero(N, 16)
    Blit(lambda a, b: ((a >> 4) & m1) | (b & ~m1), N / 2, 1, Channel(B, 1, 1),
         Channel(B, 0, 1), Channel(C, 0, 1))
    Blit(lambda a, b: ((a << 4) & ~m1) | (b & m1), N / 2, 1, Channel(B, 0, 1),
         Channel(B, 1, 1), Channel(C, 1, 1))
    Array.Print("Swap 4x2:", *C)

    D = Array.Zero(N, 16)
    Blit(lambda a, b: ((a >> 2) & m2) | (b & ~m2), N / 4, 2, Channel(C, 2, 2),
         Channel(C, 0, 2), Channel(D, 0, 2))
    Blit(lambda a, b: ((a << 2) & ~m2) | (b & m2), N / 4, 2, Channel(C, 0, 2),
         Channel(C, 2, 2), Channel(D, 2, 2))
    Array.Print("Swap 2x2:", *D)

    if bitplane_output:
        E = [Array.Zero(N / 4, 16) for i in range(4)]
        Blit(lambda a, b: ((a >> 1) & m3) | (b & ~m3), N / 4, 1,
             Channel(D, 1, 3), Channel(D, 0, 3), Channel(E[0], 0, 0))
        Blit(lambda a, b: ((a >> 1) & m3) | (b & ~m3), N / 4, 1,
             Channel(D, 3, 3), Channel(D, 2, 3), Channel(E[2], 0, 0))
        Blit(lambda a, b: ((a << 1) & ~m3) | (b & m3), N / 4, 1,
             Channel(D, 0, 3), Channel(D, 1, 3), Channel(E[1], 0, 0))
        Blit(lambda a, b: ((a << 1) & ~m3) | (b & m3), N / 4, 1,
             Channel(D, 2, 3), Channel(D, 3, 3), Channel(E[3], 0, 0))
        print("Bitplanes:")
        Array.Print("[0]:", *E[0])
        Array.Print("[1]:", *E[1])
        Array.Print("[2]:", *E[2])
        Array.Print("[3]:", *E[3])
    else:
        E = Array.Zero(N, 16)
        Blit(lambda a, b: ((a >> 1) & m3) | (b & ~m3), N / 2, 1,
             Channel(D, 1, 1), Channel(D, 0, 1), Channel(E, 0, 1))
        Blit(lambda a, b: ((a << 1) & ~m3) | (b & m3), N / 2, 1,
             Channel(D, 0, 1), Channel(D, 1, 1), Channel(E, 1, 1))
        Array.Print("Swap 1x1:", *E)