Skip to content

Commit

Permalink
Add local color definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed May 11, 2022
1 parent 2eccfeb commit e68e2c1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions large_image/tilesource/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
# Turn off decompression warning check
PIL.Image.MAX_IMAGE_PIXELS = None

# Extend colors so G and GREEN map to expected values. CSS green is #0080ff,
# which is unfortunate.
colormap = {
'R': '#ff0000',
'G': '#00ff00',
'B': '#0000ff',
'RED': '#ff0000',
'GREEN': '#00ff00',
'BLUE': '#0000ff',
}


def _encodeImageBinary(image, encoding, jpegQuality, jpegSubsampling, tiffCompression):
"""
Expand Down Expand Up @@ -185,7 +196,7 @@ def _letterboxImage(image, width, height, fill):
corner = False
if fill.lower().startswith('corner:'):
corner, fill = True, fill.split(':', 1)[1]
color = PIL.ImageColor.getcolor(fill, image.mode)
color = PIL.ImageColor.getcolor(colormap.get(fill, fill), image.mode)
width = max(width, image.width)
height = max(height, image.height)
result = PIL.Image.new(image.mode, (width, height), color)
Expand Down Expand Up @@ -451,7 +462,7 @@ def _arrayToPalette(palette):
arr.append(numpy.array((list(clr) + [1, 1, 1])[:4]) * 255)
else:
try:
arr.append(PIL.ImageColor.getcolor(str(clr), 'RGBA'))
arr.append(PIL.ImageColor.getcolor(str(colormap.get(clr, clr)), 'RGBA'))
except ValueError:
try:
import matplotlib
Expand Down Expand Up @@ -484,7 +495,7 @@ def getPaletteColors(value):
palette = value
if palette is None:
try:
PIL.ImageColor.getcolor(str(value), 'RGBA')
PIL.ImageColor.getcolor(str(colormap.get(value, value)), 'RGBA')
palette = ['#000', str(value)]
except ValueError:
pass
Expand Down Expand Up @@ -559,6 +570,7 @@ def getAvailableNamedPalettes(includeColors=True, reduced=False):
palettes = set()
if includeColors:
palettes |= set(PIL.ImageColor.colormap.keys())
palettes |= set(colormap.keys())
_recursePalettablePalettes(palettable, palettes)
try:
import matplotlib
Expand Down

0 comments on commit e68e2c1

Please sign in to comment.