diff options
author | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:07:17 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:07:17 +0200 |
commit | 467868432601ac9f0ba76506bf0f33b79d428ac3 (patch) | |
tree | 53743336b28b407b83fd0ca2987397e6b811a8a7 /common | |
parent | 55c5d83e6ef3586db477c26f93539d8182956b0e (diff) |
massive conversion of string in bytearrays. TODO: check is all fine
Diffstat (limited to 'common')
-rw-r--r-- | common/pixmap.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/common/pixmap.py b/common/pixmap.py index 51bfd8b..3e52486 100644 --- a/common/pixmap.py +++ b/common/pixmap.py @@ -2,23 +2,23 @@ import io def decodepixmap(data): - f = io.StringIO(data) + f = io.BytesIO(data) sig = f.readline().strip() - assert sig == "P6" + assert sig == b"P6" while 1: line = f.readline().strip() - if not line.startswith('#'): + if not line.startswith(b'#'): break wh = line.split() w, h = list(map(int, wh)) sig = f.readline().strip() - assert sig == "255" + assert sig == b"255" data = f.read() f.close() return w, h, data def encodepixmap(w, h, data): - return 'P6\n%d %d\n255\n%s' % (w, h, data) + return b'P6\n%d %d\n255\n%s' % (w, h, data) def cropimage(xxx_todo_changeme, xxx_todo_changeme1): (w, h, data) = xxx_todo_changeme @@ -30,39 +30,39 @@ def cropimage(xxx_todo_changeme, xxx_todo_changeme1): for p in range(y1*scanline + x1*3, (y1+h1)*scanline + x1*3, scanline)] - return w1, h1, ''.join(lines) + return w1, h1, b''.join(lines) def vflip(w, h, data): scanline = w*3 lines = [data[p:p+scanline] for p in range(0, len(data), scanline)] lines.reverse() - return ''.join(lines) + return b''.join(lines) def hflip(w, h, data): scanline = w*3 - lines = [''.join([data[p:p+3] for p in range(p1+scanline-3, p1-3, -3)]) + lines = [b''.join([data[p:p+3] for p in range(p1+scanline-3, p1-3, -3)]) for p1 in range(0, len(data), scanline)] - return ''.join(lines) + return b''.join(lines) def rotate_cw(w, h, data): scanline = w*3 lastline = len(data) - scanline - lines = [''.join([data[p:p+3] for p in range(lastline + p1, -1, -scanline)]) + lines = [b''.join([data[p:p+3] for p in range(lastline + p1, -1, -scanline)]) for p1 in range(0, scanline, 3)] - return ''.join(lines) + return b''.join(lines) def rotate_ccw(w, h, data): scanline = w*3 - lines = [''.join([data[p:p+3] for p in range(p1, len(data), scanline)]) + lines = [b''.join([data[p:p+3] for p in range(p1, len(data), scanline)]) for p1 in range(scanline-3, -3, -3)] - return ''.join(lines) + return b''.join(lines) def rotate_180(w, h, data): scanline = w*3 - lines = [''.join([data[p:p+3] for p in range(p1+scanline-3, p1-3, -3)]) + lines = [b''.join([data[p:p+3] for p in range(p1+scanline-3, p1-3, -3)]) for p1 in range(0, len(data), scanline)] lines.reverse() - return ''.join(lines) + return b''.join(lines) def makebkgnd(w, h, data): scanline = 3*w @@ -73,14 +73,14 @@ def makebkgnd(w, h, data): line.append(2 * (chr(ord(data[p ]) >> 3) + chr(ord(data[p+1]) >> 3) + chr(ord(data[p+2]) >> 3))) - line = ''.join(line) + line = b''.join(line) result.append(line) result.append(line) - return w*2, h*2, ''.join(result) + return w*2, h*2, b''.join(result) -translation_darker = ('\x00\x01' + '\x00'*126 + - ''.join([chr(n//4) for n in range(0,128)])) -translation_dragon = translation_darker[:255] + '\xC0' +translation_darker = (b'\x00\x01' + b'\x00'*126 + + b''.join([bytes([n//4]) for n in range(0,128)])) +translation_dragon = translation_darker[:255] + b'\xC0' def make_dark(xxx_todo_changeme2, translation): (w, h, data) = xxx_todo_changeme2 @@ -163,5 +163,5 @@ def imagezoomer(w, h, data): # ______________________________ result.append(revcache[p1]) - data = ''.join(result) + data = b''.join(result) yield (rw, rh, data) |