mirror of
https://frontier.innolan.net/github/AmigaExamples.git
synced 2026-09-12 05:51:41 +00:00
Removed unused python files
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
from array import array
|
||||
|
||||
|
||||
class BitplaneImage(object):
|
||||
def __init__(self, byte_width, height, bitplanes):
|
||||
self.byte_width = byte_width
|
||||
self.height = height
|
||||
self.bitplanes = bitplanes
|
||||
|
||||
|
||||
def image_to_bitplanes(image, bit_depth):
|
||||
"""
|
||||
Convert a PIL image into bitplanes.
|
||||
|
||||
Returns a bitmap image.
|
||||
"""
|
||||
bitplanes = [array('c') for _ in xrange(bit_depth)]
|
||||
width, height = image.size
|
||||
byte_width = (width + 7) // 8
|
||||
|
||||
for row in xrange(height):
|
||||
for byte in xrange(byte_width):
|
||||
planes = [0] * bit_depth
|
||||
for bit in xrange(8):
|
||||
palette_index = image.getpixel((byte * 8 + 7 - bit, row))
|
||||
for plane_index in range(bit_depth):
|
||||
planes[plane_index] |= ((palette_index >> plane_index) & 1) << bit
|
||||
for plane_index in range(bit_depth):
|
||||
bitplanes[plane_index].append(chr(planes[plane_index]))
|
||||
|
||||
return BitplaneImage(byte_width, height, bitplanes)
|
||||
|
||||
|
||||
def write_interleaved(file, image):
|
||||
"""Write all bitplanes in interleaved mode to a file."""
|
||||
for row in xrange(image.height):
|
||||
offset = row * image.byte_width
|
||||
for plane in image.bitplanes:
|
||||
plane[offset:offset + image.byte_width].write(file)
|
||||
|
||||
|
||||
def write_bitplane(file, image, bitplane_index):
|
||||
"""Write a single bitplane to a file."""
|
||||
image.bitplanes[bitplane_index].write(file)
|
||||
|
||||
|
||||
def to_amiga_colors(palette):
|
||||
"""
|
||||
Convert 24 bit colors to Amiga 12 bit colors.
|
||||
palette is a sequence of integers: [r, g, b, ...]
|
||||
"""
|
||||
number_of_colors = len(palette) // 3
|
||||
amiga_colors = []
|
||||
for color_index in xrange(number_of_colors):
|
||||
r, g, b = [c for c in palette[color_index * 3:(color_index + 1) * 3]]
|
||||
rgb = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4)
|
||||
amiga_colors.append(rgb)
|
||||
|
||||
return amiga_colors
|
||||
@@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import math
|
||||
from PIL import Image
|
||||
from bitmap import (
|
||||
image_to_bitplanes,
|
||||
write_bitplane,
|
||||
write_interleaved,
|
||||
to_amiga_colors,
|
||||
)
|
||||
|
||||
|
||||
def main(args):
|
||||
source_file = args.source
|
||||
bit_depth = args.depth
|
||||
verbose = args.verbose
|
||||
|
||||
img = Image.open(source_file)
|
||||
if img.mode != 'P':
|
||||
print 'Image is not palette-based'
|
||||
sys.exit(1)
|
||||
|
||||
palette = img.getpalette() # always 256*3 values
|
||||
if not bit_depth:
|
||||
max_index = img.getextrema()[1]
|
||||
bit_depth = int(math.log(max_index) / math.log(2)) + 1
|
||||
if verbose:
|
||||
print 'Maximum palette index used: %d: assuming bit depth %d' % (max_index, bit_depth)
|
||||
|
||||
amiga_palette = to_amiga_colors(
|
||||
palette[:(1 << bit_depth) * 3]
|
||||
)
|
||||
|
||||
width, height = img.size
|
||||
if (width & 7) != 0:
|
||||
print 'Width is not divisable by 8:', width
|
||||
sys.exit(1)
|
||||
|
||||
bitmap_image = image_to_bitplanes(img, bit_depth)
|
||||
if verbose:
|
||||
print 'Image width: %d pixels = %d bytes. Height: %d pixels' % (
|
||||
width, bitmap_image.byte_width, height)
|
||||
|
||||
if args.separate:
|
||||
for plane_index in range(bit_depth):
|
||||
with open(args.out % (plane_index + 1), 'wb') as out:
|
||||
write_bitplane(out, bitmap_image, plane_index)
|
||||
else:
|
||||
with open(args.out, 'wb') as out:
|
||||
write_interleaved(out, bitmap_image)
|
||||
|
||||
if args.copper:
|
||||
with open(args.copper, 'w') as out:
|
||||
for index, rgb in enumerate(amiga_palette):
|
||||
out.write('\tdc.w\t$%x,$%03x\n' % (0x180 + index * 2, rgb))
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description='Convert an image to Amiga bitplanes')
|
||||
parser.add_argument(
|
||||
'--depth', metavar='N', type=int, default=None,
|
||||
help='Set number of bitplanes in output')
|
||||
parser.add_argument(
|
||||
'--copper',
|
||||
help='Write palette as copper source code (default is to auto-detect)')
|
||||
parser.add_argument(
|
||||
'--separate', action='store_true',
|
||||
help='Write one bitplane per file. Use %%s in filename as replacement for bitplane number.')
|
||||
parser.add_argument(
|
||||
'--verbose', '-v', action='store_true',
|
||||
help='Write more information to stdout')
|
||||
parser.add_argument('source', metavar='IMAGE_FILE',
|
||||
help='Image file to convert to bitplanes')
|
||||
parser.add_argument('out', metavar='BITPLANES_FILE',
|
||||
help='File to write bitmaps to')
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
Reference in New Issue
Block a user