Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- import numpy as np
- from scipy.optimize import root_scalar
- from PIL import Image
- trans_flag = [[91, 206, 250],[245, 169, 184],[255, 255, 255],[245, 169, 184],[91, 206, 250]]
- def parse_flag(s):
- r=[]
- for w in s.split():
- c=[]
- for i in range(3):
- c.append(int(w[i*2:i*2+2],16))
- r.append(c)
- return r
- demigirl_flag = parse_flag('7f7f7f c3c3c3 ffaec9 ffffff ffaec9 c3c3c3 7f7f7f')
- @functools.lru_cache()
- def solve_color(y, z, i):
- sy = y / 255
- sz = z / 255
- x = root_scalar((lambda x:x**2.2+(2*sy-x)**2.2-2*sz), x0=0.5, x1=0.7)
- x = int(round(255*min(1,max(0,x.root))))
- if i:
- x = max(0,min(255,2*y-x))
- return x
- def gamma_flag(lx, ly, fp, stripes_y, stripes_z, desat_y, desat_z):
- stripes_y = np.array(list(map(list, stripes_y)))
- stripes_z = np.array(list(map(list, stripes_z)))
- stripes_y = np.array(stripes_y+(127-stripes_y)*desat_y,np.uint8)
- ztg=255*(np.mean(stripes_y)/255)**2.2
- stripes_z = np.array(stripes_z+(ztg-stripes_z)*desat_z,np.uint8)
- ny = stripes_y.shape[0]
- nz = stripes_z.shape[0]
- pix = np.zeros((ly, lx, 3), dtype=np.uint8)
- for y in range(ly):
- sy = stripes_y[y*ny//ly]
- sz = stripes_z[y*nz//ly]
- for x in range(lx):
- f = (x+y)&1
- for j in range(3):
- pix[y][x][j] = solve_color(sy[j], sz[j], f)
- im = Image.fromarray(pix)
- im.save(fp)
- gamma_flag(1536, 1024, 'gamma_trans_demigirl.png', trans_flag, demigirl_flag, 0.93,0.86)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement