Skip to content

Commit

Permalink
Add limited caching for color distance
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Jan 12, 2020
1 parent 031e707 commit 64a83e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions blessed/color.py
Expand Up @@ -11,6 +11,11 @@

from math import atan2, cos, exp, sin, sqrt

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache


def rgb_to_xyz(red, green, blue):
"""
Expand Down Expand Up @@ -71,6 +76,7 @@ def xyz_to_lab(x_val, y_val, z_val):
return cie_l, cie_a, cie_b


@lru_cache(maxsize=256)
def rgb_to_lab(red, green, blue):
"""
Convert RGB color to CIE-Lab color.
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -2,5 +2,7 @@ wcwidth>=0.1.4
six>=1.9.0
# support python2.6 by using backport of 'orderedict'
ordereddict==1.1; python_version < "2.7"
# support python2.7 by using backport of 'functools.lru_cache'
backports.functools-lru-cache>=1.2.1; python_version < "3.2"
# Windows requires jinxed
jinxed>=0.5.4; platform_system == "Windows"

0 comments on commit 64a83e7

Please sign in to comment.