in src/open_vp_cal/imaging/imaging_utils.py [0:0]
def generate_image_cie(scale: int, file_path: str) -> bool:
""" Generates and image of the CIE 1931 chromaticity diagram in the correct 0-1 range and position
within the image. Scaled to the given factor
Args:
scale: The scale to apply to the image
file_path: The file path to write the image to
Returns: True if the image was written successfully
"""
spectral_locus_x, spectral_locus_y = utils.get_spectral_locus_positions(scale)
polygon = list(zip(spectral_locus_x, spectral_locus_y))
buf = Oiio.ImageBuf(Oiio.ImageSpec(scale, scale, 3, Oiio.FLOAT))
Oiio.ImageBufAlgo.fill(
buf,
[1, 1, 1]
)
for y_pos in range(scale):
for x_pos in range(scale):
adjusted_y = scale - y_pos - 1
if utils.is_point_inside_polygon((x_pos, adjusted_y), polygon):
x_normalized = x_pos / scale
y_normalized = adjusted_y / scale
xyY = colour.xy_to_xyY((x_normalized, y_normalized), 1)
XYZ = colour.xyY_to_XYZ(xyY)
illuminant = colour.CCS_ILLUMINANTS[
"CIE 1931 2 Degree Standard Observer"
]["D65"]
rgb = colour.XYZ_to_RGB(
XYZ,
illuminant,
RGB_COLOURSPACE_ACES2065_1.whitepoint,
RGB_COLOURSPACE_ACES2065_1.matrix_XYZ_to_RGB,
"Cat02",
None,
)
# rgb = [max(0, min(1, channel)) for channel in colour.XYZ_to_sRGB(XYZ)]
buf.setpixel(x_pos, y_pos, (rgb[0], rgb[1], rgb[2]))
res = write_image(buf, file_path, "float")
if not res:
raise ValueError("Failed to write image buffer to display")
return True