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)