mirror of
https://github.com/option8/RetroConnector.git
synced 2024-10-31 20:05:07 +00:00
added subprocess calls
more error checking, changed sys to subprocess
This commit is contained in:
parent
c0f6bbea83
commit
5bebbcfbc6
@ -8,7 +8,15 @@
|
||||
|
||||
|
||||
import os,sys # filesystem functions
|
||||
import subprocess
|
||||
|
||||
|
||||
try:
|
||||
import png # PNG image library
|
||||
except:
|
||||
print("This script requires the python PNG module: https://pypi.python.org/pypi/pypng (or: pip install pypng)\n\n")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
try:
|
||||
INPUTFILE = sys.argv[1] # what DSK file to parse
|
||||
@ -17,12 +25,23 @@ except:
|
||||
print("\n\nUsage: python [filename]\n\n [filename] should be a DSK file of 143kb.\n\n")
|
||||
sys.exit(0) # exit on exception - no file chosen
|
||||
finally:
|
||||
print("Checking " + INPUTFILE + "...\n")
|
||||
|
||||
# to do: check for 140k 5.25'' disks vs 400k/800k 3.5'' and adjust accordingly
|
||||
|
||||
if (os.path.getsize(INPUTFILE)) != 143360: # check file size. for 5.25'', it needs to be 143k
|
||||
print("\n\nOops. Is " + INPUTFILE + " a DSK file of 143kb?\n\n")
|
||||
sys.exit(0) # exit on exception - file is empty, etc
|
||||
|
||||
# The point: Make a PNG image from the data on a floppy disk image.
|
||||
# 5.15'' disks have 35 tracks, each with 16 sectors of 256 bytes each, for a total of 143,360 bytes
|
||||
# so 35 lines of 4096 px.
|
||||
TRACKS = 35
|
||||
SECTORS = 16
|
||||
BYTESPERSECTOR = 256
|
||||
|
||||
PNG = open("DiskImageTEMP.png", "wb") # open a PNG for writing
|
||||
|
||||
# The point: Make a PNG image from the data on a floppy disk image.
|
||||
# 35 tracks, each with 16 sectors of 256 bytes each, for a total of 143,360 bytes
|
||||
# so 35 lines of 4096 px.
|
||||
|
||||
# new, empty arrays
|
||||
BYTES = []
|
||||
@ -43,9 +62,9 @@ finally:
|
||||
sys.stdout.write("\r Starting.\n\n")
|
||||
|
||||
|
||||
for TRACK in range(0,35,1): # for each of the 35 tracks
|
||||
for TRACK in range(0,TRACKS,1): # for each of the 35 tracks
|
||||
LINE=[] # start a new line of pixels
|
||||
for SECTOR in range(0,4096,1): # write the bytes for the sectors in that track to the line array
|
||||
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])
|
||||
|
||||
@ -57,10 +76,10 @@ finally:
|
||||
sys.stdout.flush()
|
||||
|
||||
# write to the PNG file
|
||||
w = png.Writer(4096,35, greyscale=True, bitdepth=8)
|
||||
w = png.Writer(SECTORS*BYTESPERSECTOR,TRACKS, greyscale=True, bitdepth=8)
|
||||
w.write(PNG, PIXELS) # each number in the array becomes a pixel in the image. each array becomes a line.
|
||||
|
||||
sys.stdout.write("\n\n\r Writing to disk. Chunka-chunk-cka. Whirr.\n\n")
|
||||
sys.stdout.write("\n\n\r Writing bytes to disk. Chunka-chunka-chunk. Whirr.\n\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
@ -71,8 +90,13 @@ PNG.close()
|
||||
OUTPUTFILE = os.path.join(INPUTFILE + ".png")
|
||||
# set a destination file same as DSK, but with PNG extension
|
||||
|
||||
os.system('convert DiskImageTEMP.png -matte -virtual-pixel transparent -resize 1024x1024! -rotate 90 -distort Polar \'512 110 512,512 -180,180\' ' + OUTPUTFILE)
|
||||
|
||||
try:
|
||||
subprocess.call(['convert', 'DiskImageTEMP.png', '-matte', '-virtual-pixel', 'transparent', '-resize', '1024x1024!', '-rotate', '90', '-distort', 'Polar', '512 110 512,512 -180,180', 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/")
|
||||
sys.exit(0) # exit on exception - needs imagemagick installed
|
||||
|
||||
os.system('open ' + OUTPUTFILE) # opens the resulting image in the default image viewer (Preview.app)
|
||||
subprocess.call(['open', OUTPUTFILE]) # opens the resulting image in the default image viewer (Preview.app)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user