From 0f1ec6f6f211fab0509dcf682c4ed088799c038a Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 2 Nov 2021 21:25:00 +0000 Subject: [PATCH] Optimize memory a bit --- precompute_conversion.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/precompute_conversion.py b/precompute_conversion.py index c0be018..8c1e7a2 100644 --- a/precompute_conversion.py +++ b/precompute_conversion.py @@ -1,5 +1,6 @@ """Precompute CIE2000 perceptual colour distance matrices. +XXX The matrix of delta-E values is computed for all pairs of 24-bit RGB values, and Apple II target palette values. This is written out as a file that is mmapped at runtime for efficient access. For a 16-colour target palette this @@ -14,16 +15,18 @@ def main(): print("Precomputing conversion matrix from RGB to CAM16UCS colour space") # Compute matrix of all 24-bit RGB values, normalized to 0..1 range - bits24 = np.arange(2 ** 24).reshape(-1, 1) - all_rgb = (np.concatenate( + bits24 = np.arange(2 ** 24, dtype=np.uint32).reshape(-1, 1) + all_rgb = np.concatenate( [bits24 >> 16 & 0xff, bits24 >> 8 & 0xff, bits24 & 0xff], - axis=1) / 255).astype(np.float32) + axis=1).astype(np.float32) / 255 + del bits24 with colour.utilities.suppress_warnings(colour_usage_warnings=True): # Compute matrix of corresponding CAM16UCS colour values, indexed # by 24-bit RGB value all_cam16 = colour.convert(all_rgb, "RGB", "CAM16UCS").astype( np.float32) + del all_rgb np.save("data/rgb_to_cam16ucs.npy", all_cam16)