From 1b155cb7e70fb40c0b013372a4d2ce38e32132e8 Mon Sep 17 00:00:00 2001 From: Diego Roversi Date: Tue, 10 Sep 2019 16:28:20 +0200 Subject: 2to3 and some other manual fix --- bubbob/images/buildcolors.py | 64 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/bubbob/images/buildcolors.py b/bubbob/images/buildcolors.py index 0f7ea01..6110f6a 100644 --- a/bubbob/images/buildcolors.py +++ b/bubbob/images/buildcolors.py @@ -56,13 +56,13 @@ def initpalettelut (): # Palette 0 must contain NO duplicate colors. PaletteIndex = {} for i in range (PALETTESIZE): - v = Palettes[i] + v = Palettes[i] #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)]) - PaletteIndex[s] = i + s = "".join ([chr ((v >> shift) & 0xff) for shift in (0,8,16)]) + PaletteIndex[s] = i # invalidate COLORS, but match the length to the number of alt palettes. - COLORS = range ((len (Palettes) / PALETTESIZE) - 1) + COLORS = list(range((len (Palettes) // PALETTESIZE) - 1)) #print 'COLORS',COLORS COLORMAPS = [{} for n in COLORS] #print 'COLORMAPS',COLORMAPS @@ -75,10 +75,10 @@ def loadpalettesets (filename): assert ((os.path.getsize (filename) % (PALETTESIZE * 3)) == 0) #print os.path.getsize (filename) f = open (filename, 'rb') - for i in range (os.path.getsize(filename) / (PALETTESIZE * 3)): + for i in range (os.path.getsize(filename) // (PALETTESIZE * 3)): for j in range (PALETTESIZE): tmp = f.read (3) - val = ord (tmp[0]) | (ord (tmp[1]) << 8) | (ord (tmp[2]) << 16) + val = tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) Palettes.append (val) #debuggest #print len(Palettes) @@ -95,12 +95,12 @@ def inputfiles (): os.path.join (ThisDir, os.pardir, 'ext7', 'image1-%d.ppm'): 1, } d = {} - execfile (os.path.join(ThisDir, os.pardir, 'sprmap.py'), d) + 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 sprmap.items (): + for key, (filename, rect) in list(sprmap.items ()): if filename.find('%d') >= 0: InputFiles[os.path.join (ThisDir, filename)] = 1 - return InputFiles.keys () + return list(InputFiles.keys ()) # ____________________________________________________________ @@ -124,33 +124,33 @@ def palettepixelmap (r, g, b): # print max(r,g,b) packed = chr(r) + chr(g) + chr(b) try: - index = PaletteIndex[packed] + index = PaletteIndex[packed] #print 'index %r' % index # print 'USING', usingpalette - v = thispalette[index] #Palettes[(PALETTESIZE * (usingpalette + 1)) + index] + v = thispalette[index] #Palettes[(PALETTESIZE * (usingpalette + 1)) + index] # print 'hit! %r' % packed # print '-> %r' % (chr(v & 0xff) + chr ((v >> 8) & 0xff) + chr((v >> 16) & 0xff)) # print '%r : %r' % (Palettes[index], Palettes[PALETTESIZE + index]) - return v & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff + return v & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff except KeyError: - return r,g,b + return r,g,b def ppmbreak (f): 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 = map (int, wh) + w, h = list(map (int, wh)) sig = f.readline ().strip() - assert sig == "255" + assert sig == b"255" data = f.read () return w, h, data COLORMAPS = [{} for n in COLORS] -del n +#del n def paletterotate (imglist, chr=chr, int=int, ord=ord): global thispalette @@ -178,7 +178,7 @@ def paletterotate (imglist, chr=chr, int=int, ord=ord): append (colormap[rgb1]) else: # print 'HI!' - r, g, b = ord(rgb1[0]), ord(rgb1[1]), ord(rgb1[2]) + 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) @@ -226,15 +226,15 @@ def writeout (imglist, namepattern, paletted = False): w, h, data = imglist[i] fn = namepattern % i f = open (fn, 'wb') - print >> f, 'P6' - print >> f, w, h - print >> f, 255 - f.write (data) - f.close () + 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.close() def convert (name): - print >> sys.stderr, 'generating colors for %s...' % name + print('generating colors for %s...' % name, file=sys.stderr) imglist = [ppmbreak (open (name % 0, 'rb'))] paletted = False if Palettes: @@ -242,7 +242,7 @@ def convert (name): paletted = True else: imglist.append(ppmbreak (open (name % 1, 'rb'))) - rotate (imglist) + rotate (imglist) writeout (imglist, name, paletted) def updatecheck (): @@ -285,7 +285,7 @@ else: if __name__ == '__auto__': # when execfile'd from images.py - rebuild = updatecheck ().items () + rebuild = list(updatecheck ().items ()) rebuild.sort () for fn, r in rebuild: if r: @@ -308,15 +308,15 @@ if __name__ == '__main__': except OSError: pass else: - print 'rm', filename % n + print('rm', filename % n) sys.exit() else: rebuild = updatecheck () - if 0 in rebuild.values (): - print >> sys.stderr, ('%d images up-to-date. ' + if 0 in list(rebuild.values ()): + print(('%d images up-to-date. ' 'Use -f to force a rebuild or -c to clean.' % - rebuild.values ().count(0)) - files = [fn for fn, r in rebuild.items () if r] + list(rebuild.values ()).count(0)), file=sys.stderr) + files = [fn for fn, r in list(rebuild.items ()) if r] files.sort () for filename in files: -- cgit v1.2.3