autoencoding WIP

This commit is contained in:
chrys 2017-07-09 23:27:54 +02:00
parent 69bc01c017
commit 85717371d6
2 changed files with 82 additions and 3 deletions

View File

@ -5,7 +5,7 @@
#https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py #https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py
#blink = 5 if attr & 1 else 0 #blink = 5 if attr & 1 else 0
#bold = 1 if attr & 16 else 0 #bold = 1 if attr & 16 else 0
from fcntl import ioctl import fcntl
from array import array from array import array
import struct import struct
import errno import errno
@ -23,7 +23,7 @@ cols = int(head[1])
GIO_UNIMAP = 0x4B66 GIO_UNIMAP = 0x4B66
VT_GETHIFONTMASK = 0x560D VT_GETHIFONTMASK = 0x560D
himask = array("H", (0,)) himask = array("H", (0,))
ioctl(tty, VT_GETHIFONTMASK, himask) fcntl.ioctl(tty, VT_GETHIFONTMASK, himask)
hichar, = struct.unpack_from("@H", himask) hichar, = struct.unpack_from("@H", himask)
sz = 512 sz = 512
@ -32,7 +32,7 @@ while True:
try: try:
unipairs = array("H", [0]*(2*sz)) unipairs = array("H", [0]*(2*sz))
unimapdesc = array("B", struct.pack("@HP", sz, unipairs.buffer_info()[0])) unimapdesc = array("B", struct.pack("@HP", sz, unipairs.buffer_info()[0]))
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc) fcntl.ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
break break
except IOError as e: except IOError as e:
if e.errno != errno.ENOMEM: if e.errno != errno.ENOMEM:

View File

@ -3,6 +3,13 @@
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
#attrib:
#http://rampex.ihep.su/Linux/linux_howto/html/tutorials/mini/Colour-ls-6.html
#0 = black, 1 = blue, 2 = green, 3 = cyan, 4 = red, 5 = purple, 6 = brown/yellow, 7 = white.
#https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py
#blink = 5 if attr & 1 else 0
#bold = 1 if attr & 16 else 0
import difflib import difflib
import re import re
@ -13,10 +20,82 @@ import termios
import time import time
import select import select
import dbus import dbus
import fcntl
from array import array
import struct
import errno
import sys
from core import debug from core import debug
from core.eventData import fenrirEventType from core.eventData import fenrirEventType
from utils import screen_utils from utils import screen_utils
'''
ttyno = 4
tty = open('/dev/tty%d' % ttyno, 'rb')
vcs = open('/dev/vcsa%d' % ttyno, 'rb')
head = vcs.read(4)
rows = int(head[0])
cols = int(head[1])
GIO_UNIMAP = 0x4B66
VT_GETHIFONTMASK = 0x560D
himask = array("H", (0,))
fcntl.ioctl(tty, VT_GETHIFONTMASK, himask)
hichar, = struct.unpack_from("@H", himask)
sz = 512
line = ''
while True:
try:
unipairs = array("H", [0]*(2*sz))
unimapdesc = array("B", struct.pack("@HP", sz, unipairs.buffer_info()[0]))
fcntl.ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
break
except IOError as e:
if e.errno != errno.ENOMEM:
raise
sz *= 2
tty.close()
ncodes, = struct.unpack_from("@H", unimapdesc)
utable = struct.unpack_from("@%dH" % (2*ncodes), unipairs)
charmap = {}
for u, b in zip(utable[::2], utable[1::2]):
if charmap.get(b) is None:
charmap[b] = u
allText = []
allAttrib = []
for y in range(rows):
lineText = ''
lineAttrib = []
for x in range(cols):
data = vcs.read(2)
(sh,) = struct.unpack("=H", data)
attr = (sh >> 8) & 0xFF
ch = sh & 0xFF
if hichar == 0x100:
attr >>= 1
lineAttrib.append(attr)
ink = attr & 0x0F
paper = (attr>>4) & 0x0F
if (ink != 7) or (paper != 0):
print(ink,paper)
if sh & hichar:
ch |= 0x100
lineText += chr(charmap.get(ch, u'?'))
allText.append(lineText)
allAttrib.append(lineAttrib)
print(allText)
print(allAttrib)
'''
class driver(): class driver():
def __init__(self): def __init__(self):
self.vcsaDevicePath = '/dev/vcsa' self.vcsaDevicePath = '/dev/vcsa'