Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For greyscale images styled to the white palette, use 1 band #1263

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- Add an endpoint to make it easier to replace thumbnails ([#1253](../../pull/1253))
- Presets from Large Image Configuration file ([#1248](../../pull/1248), [#1256](../../pull/1256))
- Reduce memory allocation during some region tiling operations ([#1261](../../pull/1261))
- Reduce memory allocation during some styling operations ([#1262](../../pull/1262))
- Reduce memory allocation during some styling operations ([#1262](../../pull/1262), [#1263](../../pull/1263))

### Changes
- Minor code changes based on suggestions from ruff linting ([#1257](../../pull/1257))
Expand Down
10 changes: 8 additions & 2 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,14 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa
if not style or ('icc' in style and len(style) == 1):
sc.output = image
else:
newwidth = 4
if (len(sc.style['bands']) == 1 and sc.style['bands'][0].get('band') != 'alpha' and
image.shape[-1] == 1):
palette = getPaletteColors(sc.style['bands'][0].get('palette', ['#000', '#FFF']))
if np.array_equal(palette, getPaletteColors('#fff')):
newwidth = 1
sc.output = np.zeros(
(image.shape[0], image.shape[1], 4),
(image.shape[0], image.shape[1], newwidth),
np.float32 if image.dtype != np.float64 else image.dtype)
image = self._applyStyleFunction(image, sc, 'pre')
for eidx, entry in enumerate(sc.style['bands']):
Expand Down Expand Up @@ -1493,7 +1499,7 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa
# divide.
# See https://docs.gimp.org/en/gimp-concepts-layer-modes.html for
# some details.
for channel in range(4):
for channel in range(sc.output.shape[2]):
if np.all(sc.palette[:, channel] == sc.palette[0, channel]):
if ((sc.palette[0, channel] == 0 and sc.composite != 'multiply') or
(sc.palette[0, channel] == 255 and sc.composite == 'multiply')):
Expand Down
5 changes: 5 additions & 0 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ def _resolveFramePaths(self, sourceList):
self._resolvePathPatterns(sources, source)
else:
self._resolveSourcePath(sources, source)
for source in sources:
if hasattr(source.get('path'), 'resolve'):
source['path'] = source['path'].resolve(False)
return sources

def _sourceBoundingBox(self, source, width, height):
Expand Down Expand Up @@ -936,6 +939,8 @@ def _mergeTiles(self, base, tile, x, y):
if base.shape[2] == 2 or base.shape[2] == 4:
hfill[:, :, -1] = 1
base = np.hstack((base, hfill))
if base.flags.writeable is False:
base = base.copy()
base[y:y + tile.shape[0], x:x + tile.shape[1], :] = tile
return base

Expand Down