Niiiice glitch art...
This commit is contained in:
parent
18fd12e916
commit
ec0233f756
5 changed files with 35 additions and 44 deletions
|
|
@ -22,38 +22,21 @@ def render_text(text):
|
|||
assert unifont
|
||||
fb = bdf.framebuffer_render_text(bytes(str(text), 'UTF-8'), unifont)
|
||||
fbd = fb.contents
|
||||
print('FB STRUCT: w {} h {} memory location {:x}'.format(fbd.w, fbd.h, addressof(fbd.data.contents)))
|
||||
print("TYPE:", type(fbd.data))
|
||||
casted = cast(fbd.data, POINTER(c_uint8))
|
||||
print("CASTED TYPE:" , type(casted))
|
||||
buf = np.ctypeslib.as_array(cast(fbd.data, POINTER(c_uint8)), shape=(fbd.h, fbd.w, 4))
|
||||
print('RAW DATA:')
|
||||
alen = fbd.h*fbd.w
|
||||
# for i in range(alen):
|
||||
# c = fbd.data[i]
|
||||
# print('{:x}'.format(addressof(c)), c.r, c.g, c.b)
|
||||
print('BUF', buf.shape, buf.dtype)
|
||||
# for x, y, z in product(range(fbd.h), range(fbd.w), range(4)):
|
||||
# print(buf[x][y][z])
|
||||
|
||||
# Set data pointer to NULL before freeing framebuffer struct to prevent free_framebuffer from also freeing the data
|
||||
# buffer that is now used by numpy
|
||||
bdf.console_render_buffer(fb)
|
||||
fbd.data = cast(c_void_p(), POINTER(COLOR))
|
||||
bdf.free_framebuffer(fb)
|
||||
print('Rendered {} chars into a buffer of w {} h {} numpy buf {}'.format(len(text), fbd.w, fbd.h, buf.shape))
|
||||
return buf
|
||||
|
||||
def printframe(fb):
|
||||
h,w,_ = fb.shape
|
||||
bdf.console_render_buffer(fb.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)), w, h)
|
||||
|
||||
if __name__ == '__main__':
|
||||
fb = render_text('foobarbaz');
|
||||
print('buffer shape {} dtype {}'.format(fb.shape, fb.dtype))
|
||||
# import colorsys
|
||||
# h, w, _ = fb.shape
|
||||
# for x, y in product(range(w), range(h)):
|
||||
# r,g,b = colorsys.hsv_to_rgb(x*0.03+y*0.05, 1, 1)
|
||||
# fb[x][y] = (r,g,b,0)
|
||||
# print(fb)
|
||||
sendframe(fb)
|
||||
#printframe(fb)
|
||||
# printframe(fb)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue