Skip to content

Commit 5619ff0

Browse files
committed
chore: image_util.assets is a package
1 parent ba2776f commit 5619ff0

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

invokeai/app/invocations/composition-nodes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
srgb_from_okhsv,
3030
)
3131
from invokeai.backend.image_util.composition import (
32-
CIELAB_TO_UPLAB_ICC_PATH,
3332
MAX_FLOAT,
3433
equivalent_achromatic_lightness,
3534
gamut_clip_tensor,
35+
get_uplab_profile,
3636
remove_nans,
3737
srgb_from_linear_srgb,
3838
tensor_from_pil_image,
@@ -118,8 +118,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
118118
if self.preserve_lightness or (space == "lch") or (space == "uplab"):
119119
profile_srgb = ImageCms.createProfile("sRGB")
120120
if space == "uplab":
121-
with open(CIELAB_TO_UPLAB_ICC_PATH, "rb") as f:
122-
profile_uplab = ImageCms.getOpenProfile(f)
121+
profile_uplab = get_uplab_profile()
123122
if profile_uplab is None:
124123
profile_lab = ImageCms.createProfile("LAB", colorTemp=6500)
125124
else:

invokeai/backend/image_util/assets/__init__.py

Whitespace-only changes.

invokeai/backend/image_util/composition.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
# Copyright (c) 2023 Darren Ringer <dwringer@gmail.com>
88
# Parts based on Oklab: Copyright (c) 2021 Bj�rn Ottosson <https://bottosson.github.io/>
99
# HSL code based on CPython: Copyright (c) 2001-2023 Python Software Foundation; All Rights Reserved
10+
import importlib.resources
1011
from math import pi as PI
11-
from pathlib import Path
1212

1313
import torch
14-
from PIL import Image
14+
from PIL import Image, ImageCms
1515

16+
from invokeai.backend.image_util import assets
1617
from invokeai.backend.image_util.color_conversion import (
1718
gamut_clip_tensor,
1819
)
@@ -23,8 +24,11 @@
2324

2425
MAX_FLOAT = torch.finfo(torch.tensor(1.0).dtype).max
2526

27+
2628
# CIE Lab to Uniform Perceptual Lab profile is copyright © 2003 Bruce Justin Lindbloom. All rights reserved. <http://www.brucelindbloom.com>
27-
CIELAB_TO_UPLAB_ICC_PATH = Path(__file__).parent / "assets" / "CIELab_to_UPLab.icc"
29+
def get_uplab_profile():
30+
with importlib.resources.open_binary(assets, "CIELab_to_UPLab.icc") as icc:
31+
return ImageCms.getOpenProfile(icc)
2832

2933

3034
def equivalent_achromatic_lightness(lch_tensor: torch.Tensor):

0 commit comments

Comments
 (0)