Ejemplo n.º 1
0
def to_fxp_array(input, output, fractbit):
    if len(output) != 0:
        print("ERROR")
    for i in range(len(input) // 2):
        x1 = Fxp(input[2 * i], True, 16, fractbit)
        bdata1 = int(x1.hex(), 16).to_bytes(2, byteorder='big')
        x2 = Fxp(input[2 * i + 1], True, 16, fractbit)
        bdata2 = int(x2.hex(), 16).to_bytes(2, byteorder='big')
        bdata = bdata2 + bdata1
        idata = int.from_bytes(bdata, 'big')
        output.append(idata)
Ejemplo n.º 2
0
        channels = 3
    elif image.mode == "L":
        channels = 1
    else:
        print("Unknown mode: %s" % image.mode)
        return None
    pixel_values = numpy.array(pixel_values).reshape((width, height, channels))
    return pixel_values, width, height


image, x, y = get_image("empty-heart.jpg")

file1.write('v2.0 raw')
for j in range(y):
    for i in range(x):
        #print (image[i][j] >> 4)
        fxppixel = Fxp(image[j][i], 0, 24, 0)
        fxppixel = Fxp(fxppixel >> 4, 0, 4, 0)

        print(str(fxppixel.hex()).replace("0x", ""))

        tempstr = str(fxppixel.hex()).replace("0x", "")
        tempstr = tempstr.replace("'", "")
        tempstr = tempstr.replace("[", "")
        tempstr = tempstr.replace("]", "")
        tempstr = tempstr.replace(",", "")
        tempstr = tempstr.replace(" ", "")

        file1.write('\n' + tempstr)
        #file1.write('\n' + str(image[j][i] >> 4))
file1.close()
Ejemplo n.º 3
0
    i_f = float(val) / float(maxval) * (len(colors) - 1)
    i, f = int(i_f // 1), i_f % 1  # Split into whole & fractional parts.
    # Does it fall exactly on one of the color points?
    if f < EPSILON:
        return colors[i]
    else:  # Otherwise return a color within the range between them.
        (r1, g1, b1), (r2, g2, b2) = colors[i], colors[i + 1]
        return int(r1 + f * (r2 - r1)), int(g1 + f * (g2 - g1)), int(b1 + f *
                                                                     (b2 - b1))


maxval = 767
colors = [(0, 15, 15), (0, 0, 15), (15, 0, 15)]  # [Beginning, Middle , End]
print('  Val       R    G    B')
file1.write('v2.0 raw')
for i in range(maxval + 1):
    r, g, b = convert_to_rgb(maxval, i, colors)
    fxpred = (Fxp(r, 0, 16, 0))
    fxpgreen = (Fxp(g, 0, 16, 0))
    fxpblue = (Fxp(b, 0, 16, 0))
    const = (Fxp(1, 0, 16, 0))

    fxpword = Fxp(None, 0, 16, 0)
    fxpword.equal(((const & 0x0001) << 15) | ((fxpred & 0x001f) << 10)
                  | ((fxpgreen & 0x001f) << 5) | ((fxpblue & 0x001f)))

    print('{:3d} -> ({:3d}, {:3d}, {:3d})'.format(i, r, g, b))

    file1.write('\n' + str(fxpword.hex()).replace("0x", ""))

file1.close()
Ejemplo n.º 4
0
for ty in range(0, Noy // Toy):
    for tx in range(0, Nox // Tox):
        with open(
                "Tile/fmi_tile/fmi_tile_" + str((ty * (Nox // Tox)) + tx) +
                ".txt", "w") as fifi:
            for f in range(0, Nif):
                for y in range(0, Tiy):
                    for x in range(0, Tix):
                        if ((ty * Toy + y == 0) | (ty * Toy + y > Niy) |
                            (tx * Tox + x == 0) | (tx * Tox + x > Nix)):
                            stri = Fxp(0, True, BW_px, fr_px, overflow='wrap')
                        else:
                            stri = fmi[f][ty * Toy + y - 1][tx * Tox + x - 1]
                        stri = ('0' *
                                (8 - len(stri.hex()[2:]))) + stri.hex()[2:]
                        stri = stri + " : " + str(f * Tix * Tiy + y * Tiy + x)
                        fifi.write(stri + "\n")

# Create Kex and the Tile (Npar)

with open("kex.txt", "w") as fifi:
    for f in range(0, Nif * t):
        for y in range(0, Ngr):
            for x in range(0, Nnp):
                stri1 = kex_wg[f][y][x]
                stri2 = kex_pos[f][y][x]
                stri = ('0' * (4 - len(stri2.hex()[2:]))) + stri2.hex()[2:] + (
                    '0' * (4 - len(stri1.hex()[2:]))) + stri1.hex()[2:]
                fifi.write(stri + "\n")