diff options
author | Diego Roversi <diegor@tiscali.it> | 2020-05-03 11:57:32 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2020-05-03 11:57:32 +0200 |
commit | 9c32edfdd54e0ad22fed09c33262f5963accfaf6 (patch) | |
tree | d06e27743c4f6e0a0add3196d045dd4361913fd3 /display | |
parent | 4a2a48ee144ab2389e3006e9789b50402919e53e (diff) |
display: more conversion from string to bytearray
Diffstat (limited to 'display')
-rw-r--r-- | display/dpy_pygame.py | 3 | ||||
-rw-r--r-- | display/pclient.py | 8 | ||||
-rw-r--r-- | display/pythonxlibintf.py | 12 |
3 files changed, 14 insertions, 9 deletions
diff --git a/display/dpy_pygame.py b/display/dpy_pygame.py index 498b5dc..a3c2a1f 100644 --- a/display/dpy_pygame.py +++ b/display/dpy_pygame.py @@ -72,7 +72,8 @@ class Display: def pixmap(self, w, h, data, colorkey=-1): print(f"pixmap type(data) = {type(data)}, data={data[:128]}", file=sys.stderr) - img = pygame.image.fromstring(data, (w, h), "RGB") + print(f"pixmap len(data) = {len(data)}, (h, w) = {(h, w)}", file=sys.stderr) + img = pygame.image.fromstring(data[:w*h*3], (w, h), "RGB") if colorkey >= 0: r = colorkey & 0xFF g = (colorkey >> 8) & 0xFF diff --git a/display/pclient.py b/display/pclient.py index 9c8f9f4..25820b1 100644 --- a/display/pclient.py +++ b/display/pclient.py @@ -52,6 +52,8 @@ class Icon: def clear(self): if 'pixmap' in self.__dict__: del self.pixmap + def __str__(self): + return f"Icon( bmpcode={self.bmpcode}, alpha={self.alpha} )" class DataChunk(caching.Data): SOURCEDIR = os.path.abspath(os.path.join(os.path.dirname(caching.__file__), @@ -348,6 +350,7 @@ class Playfield: if data.pending: raise KeyError data = data.read() + print(f"getpixmap(bmpcode = {bmpcode}) data={data[:64]} colorkey={colorkey}",file=sys.stderr) pixmap = loadpixmap(self.dpy, data, colorkey) self.pixmaps[bmpcode] = pixmap return pixmap @@ -358,7 +361,7 @@ class Playfield: currentsounds = {} base = 0 - while udpdata[base+4:base+6] == '\xFF\xFF': + while udpdata[base+4:base+6] == b'\xFF\xFF': key, lvol, rvol = struct.unpack("!hBB", udpdata[base:base+4]) try: snd = self.sounds[key] @@ -476,6 +479,7 @@ class Playfield: self.dpy.taskbar(rect) for x, y, ico, id in icons: try: + print(f"x={x} y={y} ico={ico} id={id}",file=sys.stderr) self.dpy.putppm(x, y, ico.pixmap, ico.rect) except KeyError: pass @@ -546,7 +550,7 @@ class Playfield: setattr(self, name, None) def udp_over_udp_decoder(self, udpdata): - if len(udpdata) > 3 and '\x80' <= udpdata[0] < '\x90': + if len(udpdata) > 3 and b'\x80' <= udpdata[0] < b'\x90': data = self.dynamic_decompress(udpdata) if data: self.pending_udp_data = data diff --git a/display/pythonxlibintf.py b/display/pythonxlibintf.py index 04d85bb..846be78 100644 --- a/display/pythonxlibintf.py +++ b/display/pythonxlibintf.py @@ -44,8 +44,8 @@ class Display: self.motionev = None self.dpy.flush() - pixel = "\x00\x00\x80" - hole = "\x01\x01\x01" + pixel = b"\x00\x00\x80" + hole = b"\x01\x01\x01" self.taskbkgnd = self.pixmap(32, 32, ((pixel+hole)*16 + (hole+pixel)*16) * 16, 0x010101) @@ -97,14 +97,14 @@ class Display: maskdata.append(long2string(maskline, scanline)) plane /= 2 - imgdata = ''.join(imgdata) + imgdata = b''.join(imgdata) if colorkey >= 0: - maskdata = ''.join(maskdata) + maskdata = b''.join(maskdata) mask = self.win.create_pixmap(w, h, depth) mask.put_image(self.gc, 0, 0, w, h, X.XYPixmap, depth, 0, maskdata) else: mask = None - imgdata = ''.join(imgdata) + imgdata = b''.join(imgdata) image = self.win.create_pixmap(w, h, depth) image.put_image(self.gc, 0, 0, w, h, X.XYPixmap, depth, 0, imgdata) image.mask = mask @@ -201,4 +201,4 @@ class Display: def long2string(bits, strlen): - return ''.join([chr((bits>>n)&0xFF) for n in range(0, 8*strlen, 8)]) + return b''.join([chr((bits>>n)&0xFF) for n in range(0, 8*strlen, 8)]) |