diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-10-19 20:57:46 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-10-19 20:57:46 +0200 |
commit | d2158f2bdaa090b3a99cac606cbcd223c3c83dd3 (patch) | |
tree | 3bc9d92e6c652433aaf8b5719edaa9e4baf75382 | |
parent | m (diff) | |
download | scrotty-d2158f2bdaa090b3a99cac606cbcd223c3c83dd3.tar.gz scrotty-d2158f2bdaa090b3a99cac606cbcd223c3c83dd3.tar.bz2 scrotty-d2158f2bdaa090b3a99cac606cbcd223c3c83dd3.tar.xz |
python version, still too slow
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rwxr-xr-x | scrotty | 4 | ||||
-rwxr-xr-x | src/scrotty | 78 |
2 files changed, 80 insertions, 2 deletions
@@ -29,9 +29,9 @@ while [ -e /dev/fb$f ]; do fi ( echo P3 - cat /sys/class/graphics/fb0/virtual_size | sed -e 's/,/ /' + cat /sys/class/graphics/fb$f/virtual_size | sed -e 's/,/ /' echo 255 - cat /dev/fb0 | od -t u1 -v | cut -d ' ' -f 1 --complement | + cat /dev/fb$f | od -t u1 -v | cut -d ' ' -f 1 --complement | sed -e 's/\([0-9]\+\) \+\([0-9]\+\) \+\([0-9]\+\) \+\([0-9]\+\)/\3 \2 \1/g' ) | convert /dev/stdin $pathname (( f++ )) diff --git a/src/scrotty b/src/scrotty new file mode 100755 index 0000000..b334042 --- /dev/null +++ b/src/scrotty @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# -*- python -*- +''' +scrotty — Screenshot program for Linux's TTY +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' + +import os, sys + +fbno = 0 + +def write(string): + os.write(pipe_write, string.encode('utf-8')) + +while os.path.exists('/dev/fb%i' % fbno): + with open('/dev/fb%i' % fbno, 'rb') as file: + data = file.read() + + pathname = 'fb%i.png' % fbno + if os.path.exists(pathname): + i = 2 + while os.path.exists('%s.%i' % (pathname, i)): + i += 1 + pathname = '%s.%i' % (pathname, i) + + (pipe_read, pipe_write) = os.pipe() + pid = os.fork() + + if pid == 0: + os.close(pipe_write) + if pipe_read != 0: + os.close(0) + os.dup2(pipe_read, 0) + os.close(pipe_read) + os.execlp('convert', 'convert', '/dev/stdin', pathname) + + os.close(pipe_read) + + write('P3\n') + with open('/sys/class/graphics/fb%i/virtual_size' % fbno, 'rb') as file: + write(file.read().decode('utf-8', 'strict').replace(',', ' ')) + write('255\n') + + j = 0 + data_length = len(data) + for i in range(0, data_length, 4): + r, g, b = data[i + 2], data[i + 1], data[i + 0] + j += 1 + if (j == 5) or (i + 4 == data_length): + j = 0 + write('%i %i %i\n' % (r, g, b)) + else: + write('%i %i %i ' % (r, g, b)) + + os.close(pipe_write) + + reaped = 0 + while reaped != pid: + (reaped, status) = os.waitpid(pid, 0) + if status == 0: + print('Saved framebuffer %i to %s' % (fbno, pathname), file = sys.stderr) + else: + sys.exit(1) + fbno += 1 + |