diff options
author | Diego Roversi <diegor@tiscali.it> | 2020-05-03 13:05:41 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2020-05-03 13:05:41 +0200 |
commit | 7dcf600ce94cad5ee03dc50d6f9b385dca67c081 (patch) | |
tree | 511612197656f7149879b552be4aeb97e9675bda /bubbob | |
parent | f0ab42b99bb6d2a19ecef26f0ad6f3e3f4a92499 (diff) |
buildcolors.py: convert string to bytearray
Diffstat (limited to 'bubbob')
-rw-r--r-- | bubbob/images/buildcolors.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/bubbob/images/buildcolors.py b/bubbob/images/buildcolors.py index 6110f6a..378387a 100644 --- a/bubbob/images/buildcolors.py +++ b/bubbob/images/buildcolors.py @@ -57,9 +57,10 @@ def initpalettelut (): PaletteIndex = {} for i in range (PALETTESIZE): v = Palettes[i] + # DEBUG: print(f"type={type(v)} v={v}",file=sys.stderr) #if v & 0xff == 0 and (v >> 8) & 0xff == 0x87 and (v >> 16) & 0xff == 0: # print 'FOUND' - s = "".join ([chr ((v >> shift) & 0xff) for shift in (0,8,16)]) + s = (v).to_bytes(3, byteorder='big') PaletteIndex[s] = i # invalidate COLORS, but match the length to the number of alt palettes. COLORS = list(range((len (Palettes) // PALETTESIZE) - 1)) @@ -95,6 +96,7 @@ def inputfiles (): os.path.join (ThisDir, os.pardir, 'ext7', 'image1-%d.ppm'): 1, } d = {} + # TODO: sostituire con un import exec(compile(open(os.path.join(ThisDir, os.pardir, 'sprmap.py'), "rb").read(), os.path.join(ThisDir, os.pardir, 'sprmap.py'), 'exec'), d) sprmap = d['sprmap'] for key, (filename, rect) in list(sprmap.items ()): @@ -181,11 +183,11 @@ def paletterotate (imglist, chr=chr, int=int, ord=ord): r, g, b = rgb1[0], rgb1[1], rgb1[2] # print '%d,%d,%d ->' % (r,g,b) r, g, b = palettepixelmap (r, g, b) -# print '%d,%d,%d.' % (r,g,b) - newrgb = chr (int (r))+chr (int (g))+chr (int (b)) + print('r,g,b %d,%d,%d.' % (r,g,b), file=sys.stderr) + newrgb = bytes([r,g,b]) #chr (int (r))+chr (int (g))+chr (int (b)) append (newrgb) colormap[rgb1] = newrgb - imglist.append((gw, gh, ''.join (image))) + imglist.append((gw, gh, b''.join (image))) def rotate (imglist, chr=chr, int=int, ord=ord): @@ -213,10 +215,10 @@ def rotate (imglist, chr=chr, int=int, ord=ord): append (colormap[rgb1]) else: r, g, b = fn(ord(rgb1[0]), ord(rgb1[1]), ord(rgb1[2])) - newrgb = chr(int(r))+chr(int(g))+chr(int(b)) + newrgb = bytes([r,g,b]) # chr(int(r))+chr(int(g))+chr(int(b)) append(newrgb) colormap[rgb1] = newrgb - imglist.append((bw, bh, ''.join(image))) + imglist.append((bw, bh, b''.join(image))) def writeout (imglist, namepattern, paletted = False): start = 2 @@ -229,7 +231,7 @@ def writeout (imglist, namepattern, paletted = False): f.write(b"P6\n") f.write(f"{w} {h}\n".encode()) # print(w, h, file=f) f.write(b"255\n") - f.write(data.encode()) + f.write(data) f.close() |