mirror of
https://github.com/weiju/amiga-stuff
synced 2025-11-21 09:19:45 +00:00
png2image and wav2ami migrated to python3
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
For license, see gpl-3.0.txt
|
For license, see gpl-3.0.txt
|
||||||
@ -23,10 +23,10 @@ def color_to_plane_bits(color, depth):
|
|||||||
def write_amiga_image(image, outfile):
|
def write_amiga_image(image, outfile):
|
||||||
imdata = im.getdata()
|
imdata = im.getdata()
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
colors = [i for i in chunks(map(ord, im.palette.tobytes()), 3)]
|
colors = [i for i in chunks([b for b in im.palette.tobytes()], 3)]
|
||||||
depth = int(math.log(len(colors), 2))
|
depth = int(math.log(len(colors), 2))
|
||||||
|
|
||||||
map_words_per_row = width / 16
|
map_words_per_row = int(width / 16)
|
||||||
if width % 16 > 0:
|
if width % 16 > 0:
|
||||||
map_words_per_row += 1
|
map_words_per_row += 1
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ def write_amiga_image(image, outfile):
|
|||||||
planebits = color_to_plane_bits(color, depth)
|
planebits = color_to_plane_bits(color, depth)
|
||||||
# now we need to "or" the bits into the words in their respective planes
|
# now we need to "or" the bits into the words in their respective planes
|
||||||
wordidx = (x + i) / 16 # word number in current row
|
wordidx = (x + i) / 16 # word number in current row
|
||||||
pos = y * map_words_per_row + wordidx # list index in the plane
|
pos = int(y * map_words_per_row + wordidx) # list index in the plane
|
||||||
for planeidx in range(depth):
|
for planeidx in range(depth):
|
||||||
if planebits[planeidx]:
|
if planebits[planeidx]:
|
||||||
planes[planeidx][pos] |= (1 << (15 - (x + i) % 16)) # 1 << ((x + i) % 16)
|
planes[planeidx][pos] |= (1 << (15 - (x + i) % 16)) # 1 << ((x + i) % 16)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import wave
|
import wave
|
||||||
import struct
|
import struct
|
||||||
@ -13,12 +13,12 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('wavfile')
|
parser.add_argument('wavfile')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print args.wavfile
|
print(args.wavfile)
|
||||||
infile = wave.open(args.wavfile)
|
infile = wave.open(args.wavfile)
|
||||||
print "# channels: ", infile.getnchannels()
|
print("# channels: ", infile.getnchannels())
|
||||||
print "sample width: ", infile.getsampwidth()
|
print("sample width: ", infile.getsampwidth())
|
||||||
print "frame rate: ", infile.getframerate()
|
print("frame rate: ", infile.getframerate())
|
||||||
print "# frames: ", infile.getnframes()
|
print("# frames: ", infile.getnframes())
|
||||||
num_frames = infile.getnframes()
|
num_frames = infile.getnframes()
|
||||||
data = [conv_amplitude(infile.readframes(1)) for _ in range(num_frames)]
|
data = [conv_amplitude(infile.readframes(1)) for _ in range(num_frames)]
|
||||||
#print data
|
#print data
|
||||||
|
|||||||
Reference in New Issue
Block a user