def dePAT(patfile, patid=0, day=1): pat = demkf.deMKF(patfile, patid) if len(pat) == 768 or day: pat = pat[0:768] else: pat = pat[768:1536] return "".join([chr(ord(x) * 4) for x in pat])
def dePAT(patfile,patid=0,day=1): pat = demkf.deMKF(patfile,patid) if len(pat) == 768 or day: pat=pat[0:768] else: pat=pat[768:1536] return "".join([chr(ord(x)*4) for x in pat])
def process(): pat = utilcommon.getPalette(args) frames = [] memset(buffer,0,length) first_index, = struct.unpack("<I",args.rng.read(4)) num = first_index//4 for frame in range(0, num): content=demkf.deMKF(args.rng, frame) if len(content) == 0: continue if args.algorithm.lower() == 'YJ1'.lower(): content=deyj1.deYJ1(content) elif args.algorithm.lower() == "YJ2".lower(): content=deyj2.deYJ2(content) pixels = deRNG(content,buffer); im = Image.frombytes("P", (320,200), pixels) im.putpalette(pat) im.info['transparency'] = args.transparent_palette_index frames.append(im) if args.saveraw: open(args.output.name+frame+".raw","wb").write(buffer) img=Image.frombytes("P", (320,200), frames[0].tobytes()) img.save(args.output, save_all=True, append_images=frames[1:], palette=pat, include_color_table=False, duration=args.millisecs_per_frame) if args.show: im.show()
def process(f,output,pal,id): pat = demkf.deMKF(pal,id) if len(pat) > 768: pat=pat[0:768] pat="".join([chr(ord(x)*4) for x in pat]) im=Image.frombytes("P", (320,200), f.read()) im.putpalette(pat) #im.show(); //uncomment it to view im.save(output)
def getPalette(args): pat = bytearray(demkf.deMKF(args.palette, args.palette_id)) if len(pat) > 768 and args.night: pat=pat[768:1536] else: if args.night: print("this palette index does not have a night alternative, turns to day") pat=pat[0:768] for i in range(0,len(pat)): pat[i]=pat[i]*4 return bytes(pat)
def process(f, output, pal, id): pat = demkf.deMKF(pal, id) if len(pat) > 768: pat = pat[0:768] pat = "".join([chr(ord(x) * 4) for x in pat]) im = Image.frombytes("P", (320, 200), f.read()) im.putpalette(pat) #im.show(); //uncomment it to view im.save(output)
def process(): im = Image.open(args.image) if im.mode != "P": if args.quantize == False: print "This image have no palette, that implies not a image derle produces; turn on quantize automatically" args.quantize = True if args.palette == None: print "Invalid configuration! quantize must specify palette/id" return elif 'transparency' in im.info: if args.transparent_palette_index != im.info['transparency']: if args.quantize: im = im.convert("RGBA") else: print "input PNG built-in transparency color %d index not same as default %d; is it exported from derle? If not, suggest you rerun encoder with quantize, or color may be terrible" % ( im.info['transparency'], args.transparent_palette_index) args.transparent_palette_index = im.info['transparency'] else: #P but no transparency if args.quantize: im = im.convert("RGBA") else: print "input PNG not specified transparency color; it must not be exported from derle. Suggestion: rerun encoder with quantize, or color will be terrible" ima = im if args.quantize: pat = demkf.deMKF(args.palette, args.palette_id) if len(pat) > 768: pat = pat[0:768] pat = "".join([chr(ord(x) * 4) for x in pat]) pat = pat[0:args.transparent_palette_index * 3] + "\x00\x00\x00" + pat[args.transparent_palette_index * 3 + 3:] imp = Image.new("P", (16, 16)) imp.putpalette(pat) im = utilcommon.quantizetopalette(im, imp, 1 if args.dither else 0) if args.save_quantized_png: im.save(args.output.name + ".quantized.png") if args.show: im.show() if args.quantize: for x in range(0, im.width): for y in range(0, im.height): if ima.getpixel((x, y))[3] == 0: im.putpixel((x, y), args.transparent_palette_index) buffer = enRLE(im.tobytes(), im.width, im.height) if args.output: args.output.write(buffer)
def process(): im=Image.open(args.image) if im.mode != "P": if args.quantize == False: print "This image have no palette, that implies not a image derle produces; turn on quantize automatically" args.quantize=True if args.palette == None: print "Invalid configuration! quantize must specify palette/id" return elif 'transparency' in im.info: if args.transparent_palette_index != im.info['transparency'] : if args.quantize: im=im.convert("RGBA") else: print "input PNG built-in transparency color %d index not same as default %d; is it exported from derle? If not, suggest you rerun encoder with quantize, or color may be terrible" % (im.info['transparency'],args.transparent_palette_index) args.transparent_palette_index = im.info['transparency'] else: #P but no transparency if args.quantize: im=im.convert("RGBA") else: print "input PNG not specified transparency color; it must not be exported from derle. Suggestion: rerun encoder with quantize, or color will be terrible" ima=im if args.quantize: pat = demkf.deMKF(args.palette,args.palette_id) if len(pat) > 768: pat=pat[0:768] pat="".join([chr(ord(x)*4) for x in pat]) pat=pat[0:args.transparent_palette_index*3]+"\x00\x00\x00"+pat[args.transparent_palette_index*3+3:] imp=Image.new("P",(16,16)) imp.putpalette(pat) im=utilcommon.quantizetopalette(im,imp, 1 if args.dither else 0) if args.save_quantized_png: im.save(args.output.name+".quantized.png") if args.show: im.show() if args.quantize: for x in range(0,im.width): for y in range(0,im.height): if ima.getpixel( (x,y) )[3] == 0: im.putpixel( (x,y), args.transparent_palette_index) buffer = enRLE(im.tobytes(),im.width,im.height) if args.output: args.output.write(buffer)
def process(): im = Image.open(args.image) if im.width != 320 or im.height != 200: print "alert! not fit size for FBP" return if im.mode != "P": print "This image have no palette, that implies not a image derle produces; turn on quantize automatically" args.quantize = True if args.palette == None: print "Invalid configuration! quantize must specify palette/id" return ima = im if args.quantize: pat = demkf.deMKF(args.palette, args.palette_id) if len(pat) > 768: pat = pat[0:768] pat = "".join([chr(ord(x) * 4) for x in pat]) imp = Image.new("P", (16, 16)) imp.putpalette(pat) im = utilcommon.quantizetopalette(im, imp, 1 if args.dither else 0) args.output.write(im.tobytes())
def process(): im=Image.open(args.image) if im.width != 320 or im.height !=200: print "alert! not fit size for FBP" return if im.mode != "P": print "This image have no palette, that implies not a image derle produces; turn on quantize automatically" args.quantize=True if args.palette == None: print "Invalid configuration! quantize must specify palette/id" return ima=im if args.quantize: pat = demkf.deMKF(args.palette,args.palette_id) if len(pat) > 768: pat=pat[0:768] pat="".join([chr(ord(x)*4) for x in pat]) imp=Image.new("P",(16,16)) imp.putpalette(pat) im=utilcommon.quantizetopalette(im,imp, 1 if args.dither else 0) args.output.write(im.tobytes())
def process(): pat = utilcommon.getPalette(args.palette,args.palette_id) frames = [] memset(buffer,0,length) num, = struct.unpack("<I",args.rng.read(4)) for frame in range(0, num): content=demkf.deMKF(args.rng, frame) content=deyj1.deYJ1(content) bytes = deRNG(content,buffer); im = Image.frombytes("P", (320,200), bytes) im.putpalette(pat) im.info['transparency'] = args.transparent_palette_index frames.append(im) if args.saveraw: open(args.output.name+frame+".raw","wb").write(buffer) img=Image.new("P", (320,200), args.transparent_palette_index) img.save(args.output, save_all=True, append_images=frames, palette=pat, include_color_table=False, duration=args.millisecs_per_frame) if args.show: im.show()
def process(): pat = demkf.deMKF(args.palette,args.palette_id) if len(pat) > 768: pat=pat[0:768] pat="".join([chr(ord(x)*4) for x in pat]) width,height,buffer = deRLE(args.rle.read()) if args.saveraw: open(args.output.name+".raw","wb").write(buffer) im=Image.frombytes("P", (width,height), buffer) im.putpalette(pat) im.info['transparency'] = args.transparent_palette_index if args.show: im.show(); if args.output: im.save(args.output)
def getPalette(palette_file, palette_id): pat = demkf.deMKF(palette_file, palette_id) if len(pat) > 768: pat=pat[0:768] pat="".join([chr(ord(x)*4) for x in pat]) return pat