From 495d4ed9037be694551c82f41a2a9bbfe5b2bf68 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Tue, 1 Sep 2015 17:06:51 +0900 Subject: [PATCH] Fix the pixel mapping and improve image processing The indexing of the byte array was wrong, which is why the images produced had that funky spiral shape (which wasn't real). The polar mapping was also incorrect (the tracks were mapped to cylinders and vice versa). Besides correcting these issues, improve the output by: - Point scaling the source vertically by 3x to produce better-defined tracks - Overlaying a "venetian blinds" pattern to add gaps between tracks - Resizing horizontally to 3072 pixels to reduce aliasing - 2x oversampling on the polar conversion again to reduce aliasing --- DSK Image/DSK-Image.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/DSK Image/DSK-Image.py b/DSK Image/DSK-Image.py index 8228ad4..66cd3f8 100644 --- a/DSK Image/DSK-Image.py +++ b/DSK Image/DSK-Image.py @@ -50,9 +50,8 @@ PIXELS = [] try: byte = DSK.read(1) # read a byte while byte !="": # while the file still has bytes in it - byte = DSK.read(1) - if len(byte) > 0: # the last byte, for whatever reason, is length 0. Bah. - BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array + BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array + byte = DSK.read(1) except: print("\n\nOops. Is " + INPUTFILE + " a DSK file of 143kb?\n\n") @@ -62,11 +61,10 @@ finally: sys.stdout.write("\r Starting.\n\n") - for TRACK in range(0,TRACKS,1): # for each of the 35 tracks + for TRACK in range(TRACKS): # for each of the 35 tracks LINE=[] # start a new line of pixels - for SECTOR in range(0,SECTORS*BYTESPERSECTOR,1): # write the bytes for the sectors in that track to the line array - offset = (SECTOR * TRACK) + SECTOR - LINE.append(BYTES[(SECTOR * TRACK) + SECTOR]) + for SECTOR in range(SECTORS*BYTESPERSECTOR): # write the bytes for the sectors in that track to the line array + LINE.append(BYTES[(SECTORS*BYTESPERSECTOR * TRACK) + SECTOR]) sys.stdout.write("\r Track: " + str(TRACK)) sys.stdout.flush() @@ -92,7 +90,8 @@ OUTPUTFILE = os.path.join(INPUTFILE + ".png") try: - subprocess.call(['convert', 'DiskImageTEMP.png', '-matte', '-virtual-pixel', 'transparent', '-resize', '1024x1024!', '-rotate', '90', '-distort', 'Polar', '512 110 512,512 -180,180', OUTPUTFILE]) + subprocess.call(['convert', 'DiskImageTEMP.png', '-scale', '100%x300%', '-resize', '3072x!', '(', '-size', '3072x115', 'pattern:horizontal3', '-negate', '-alpha', 'copy', '-fx', '#000', ')', '-composite', '-virtual-pixel', 'HorizontalTile', '-flip', '+distort', 'Polar', '1024 220', '-resize', '50%x50%', OUTPUTFILE]) + # convert the 4096x35px image to a square, rotate, then rotate around an axis. except OSError: print("\n\nOops. This script requires ImageMagick: http://www.imagemagick.org/")