50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import colorsys
|
|
|
|
from PIL import Image, ImageDraw, ImageCms
|
|
|
|
import math
|
|
|
|
from crop_card import BASE_DIR
|
|
|
|
|
|
def clamp(v, min_v, max_v):
|
|
return max(min_v, min(max_v, v))
|
|
|
|
|
|
# im = Image.new('RGB', (4096, 4096))
|
|
# d = ImageDraw.Draw(im)
|
|
# for y in range(4096):
|
|
# for x in range(4096):
|
|
# r = x // 16
|
|
# g = y // 16
|
|
# b = 0
|
|
# d.point((x, y), fill = (r, g, b))
|
|
|
|
im = Image.new('RGB', (1024, 1024))
|
|
d = ImageDraw.Draw(im)
|
|
center = 1024 / 2
|
|
radius = 1024 / 2
|
|
for y in range(1024):
|
|
for x in range(1024):
|
|
h = (math.atan2(y - center, x - center) + math.pi) / (math.pi * 2)
|
|
h = clamp(h, 0, 1)
|
|
distance_from_center = (abs(x - center) ** 2 + abs(y - center) ** 2) ** 0.5
|
|
s = distance_from_center / radius
|
|
if s > 1:
|
|
v = 0
|
|
else:
|
|
v = 1
|
|
s = clamp(s, 0, 1)
|
|
r, g, b = colorsys.hsv_to_rgb(h, s, v)
|
|
rgb = (
|
|
clamp(round(r * 255), 0, 255),
|
|
clamp(round(g * 255), 0, 255),
|
|
clamp(round(b * 255), 0, 255),
|
|
)
|
|
d.point((x, y), fill = rgb)
|
|
|
|
im = im.convert('RGB')
|
|
icc_profile = ImageCms.getOpenProfile(str(BASE_DIR / 'icc' / 'AdobeRGB1998.icc'))
|
|
im.save(BASE_DIR / 'archive' / 'gamut_srgb.jpg', 'JPEG', quality=100, subsampling=0)
|
|
im.save(BASE_DIR / 'archive' / 'gamut_icc.jpg', 'JPEG', quality=100, subsampling=0, icc_profile=icc_profile.tobytes())
|
|
|