def main(): ilbm = ILBM() ilbm.ChunkBlackList.append('JUNK') for path in sys.argv[1:]: ilbm.load(path) for chunk in ilbm: pprint(chunk)
def main(): ilbm = ILBM() ilbm.ChunkBlackList.append('JUNK') for path in sys.argv[1:]: ilbm.load(path) for chunk in ilbm: pprint((chunk.name, chunk.data))
def convert(input, output): im = Image.open(input) pix = array('B', im.getdata()) pal = im.getpalette() width, height = im.size colors = im.getextrema()[1] + 1 depth = int(math.ceil(math.log(colors, 2))) bmhd = BitMapHeader(width, height, 0, 0, depth, 0, 0, 0, 1, 1, width, height) cmap = [Color(*pal[i * 3:(i + 1) * 3]) for i in range(colors)] body = c2p(pix, width, height, depth) ilbm = ILBM() ilbm.append(IffChunk('BMHD', bmhd)) ilbm.append(IffChunk('CMAP', cmap)) ilbm.append(IffChunk('BODY', body)) ilbm.save(output)
def convert(input, output): im = Image.open(input) pix = array('B', im.getdata()) pal = im.getpalette() width, height = im.size colors = im.getextrema()[1] + 1 depth = int(math.ceil(math.log(colors, 2))) bmhd = BitMapHeader(width, height, 0, 0, depth, 0, 0, 0, 1, 1, width, height) cmap = [Color(*pal[i*3:(i+1)*3]) for i in range(colors)] body = c2p(pix, width, height, depth) ilbm = ILBM() ilbm.append(IffChunk('BMHD', bmhd)) ilbm.append(IffChunk('CMAP', cmap)) ilbm.append(IffChunk('BODY', body)) ilbm.save(output)
def main(): parser = argparse.ArgumentParser( description='Compresses ILBM IFF file with LZO or Deflate algorithm.') parser.add_argument( '-m', '--method', type=str, choices=['none', 'lzo', 'deflate'], default='lzo', help='Compression method to use.') parser.add_argument( '-f', '--force', action='store_true', help='If the output file exists, the tool will overwrite it.') parser.add_argument( 'input', metavar='INPUT', type=str, help='Input ILBM IFF file name.') parser.add_argument( 'output', metavar='OUTPUT', type=str, nargs='?', help='Output ILBM IFF file name.') args = parser.parse_args() if args.output is None: args.output = args.input if not os.path.isfile(args.input): raise SystemExit('File "%s" does not exists!' % args.input) if os.path.exists(args.output) and not args.force: raise SystemExit( 'File "%s" already exists (use "-f" to override).' % args.output) ilbm = ILBM() ilbm.ChunkBlackList.append('CRNG') if ilbm.load(args.input): bmhd = ilbm.get('BMHD') body = ilbm.get('BODY') size = ((bmhd.data.w + 15) & ~15) / 8 * bmhd.data.h * bmhd.data.nPlanes logging.info(bmhd.data) logging.info( 'BODY size before compression: %d/%d' % (len(body.data), size)) if bmhd.data.compression in [0, 1, 254, 255]: body.data = body.data.read() if bmhd.data.compression == 1: body.data = UnRLE(body.data) if bmhd.data.compression == 254: body.data = zopfli.decompress(body.data, size) if bmhd.data.compression == 255: body.data = lzo.decompress(body.data, size) if args.method == 'deflate': opts = zopfli.Options() body.data = zopfli.compress(opts, body.data, len(body.data)) bmhd.data = bmhd.data._replace(compression=254) if args.method == 'lzo': body.data = lzo.compress(body.data) bmhd.data = bmhd.data._replace(compression=255) if args.method == 'none': bmhd.data = bmhd.data._replace(compression=0) logging.info( 'BODY size after compression: %d/%d' % (len(body.data), size)) ilbm.save(args.output) else: logging.warning('Unknown compression: %d' % bmhd.data.compression)
def main(): parser = argparse.ArgumentParser( description='Compresses ILBM IFF file with LZO or Deflate algorithm.') parser.add_argument('-m', '--method', type=str, choices=['none', 'lzo', 'deflate'], default='lzo', help='Compression method to use.') parser.add_argument( '-f', '--force', action='store_true', help='If the output file exists, the tool will overwrite it.') parser.add_argument('input', metavar='INPUT', type=str, help='Input ILBM IFF file name.') parser.add_argument('output', metavar='OUTPUT', type=str, nargs='?', help='Output ILBM IFF file name.') args = parser.parse_args() if args.output is None: args.output = args.input if not os.path.isfile(args.input): raise SystemExit('File "%s" does not exists!' % args.input) if os.path.exists(args.output) and not args.force: raise SystemExit('File "%s" already exists (use "-f" to override).' % args.output) ilbm = ILBM() ilbm.ChunkBlackList.append('CRNG') if ilbm.load(args.input): bmhd = ilbm.get('BMHD') body = ilbm.get('BODY') size = ((bmhd.data.w + 15) & ~15) / 8 * bmhd.data.h * bmhd.data.nPlanes payload = body.data.read() logging.info(bmhd.data) logging.info('BODY size before compression: %d/%d' % (len(payload), size)) if bmhd.data.compression in [0, 1, 254, 255]: if bmhd.data.compression == 1: payload = UnRLE(payload) if bmhd.data.compression == 254: payload = zopfli.decompress(payload, size) if bmhd.data.compression == 255: payload = lzo.decompress(payload, size) compression = 0 if args.method == 'deflate': opts = zopfli.Options() payload = zopfli.compress(opts, payload, len(payload)) compression = 254 if args.method == 'lzo': payload = lzo.compress(payload) compression = 255 if args.method == 'none': compression = 0 body.data = payload bmhd.data = bmhd.data._replace(compression=compression) logging.info('BODY size after compression: %d/%d' % (len(body.data), size)) ilbm.save(args.output) else: logging.warning('Unknown compression: %d' % bmhd.data.compression)