def swizzle(pixels, width, height, blockW=4, blockH=4):
    """Swizzle pixels into format used by game.

    pixels: buffer of pixels, which should be an np.array of
        at least 2 dimensions.
    width, height: size of buffer.
    blockW, blockH: swizzle block size, which depends on pixel format.

    Returns a list (1-dimensional) of pixels in swizzled order.
    """
    pixelsOut = []
    for y in range(0, height, blockH):
        for x in range(0, width, blockW):
            for by in range(blockH):
                for bx in range(blockW):
                    #idx  = ((y+by)*width) + (x+bx)
                    try: p = pixels[x+bx, y+by]
                    #except IndexError: p = pixels[0, 0]
                    except IndexError: continue
                    pixelsOut.append(p)
    return pixelsOut