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

Fix multisource dtype bugs #1520

Merged
merged 1 commit into from
May 10, 2024
Merged
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
11 changes: 6 additions & 5 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,28 +939,28 @@
(tile.shape[0] + y - base.shape[0], base.shape[1], base.shape[2]),
dtype=base.dtype)
if base.shape[2] in {2, 4}:
vfill[:, :, -1] = fullAlphaValue(self.dtype)
vfill[:, :, -1] = fullAlphaValue(base.dtype)

Check warning on line 942 in sources/multi/large_image_source_multi/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/multi/large_image_source_multi/__init__.py#L942

Added line #L942 was not covered by tests
base = np.vstack((base, vfill))
if base.shape[1] < tile.shape[1] + x:
hfill = np.zeros(
(base.shape[0], tile.shape[1] + x - base.shape[1], base.shape[2]),
dtype=base.dtype)
if base.shape[2] in {2, 4}:
hfill[:, :, -1] = fullAlphaValue(self.dtype)
hfill[:, :, -1] = fullAlphaValue(base.dtype)

Check warning on line 949 in sources/multi/large_image_source_multi/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/multi/large_image_source_multi/__init__.py#L949

Added line #L949 was not covered by tests
base = np.hstack((base, hfill))
if base.flags.writeable is False:
base = base.copy()
if base.shape[2] in {2, 4}:
baseA = base[y:y + tile.shape[0], x:x + tile.shape[1], -1].astype(
float) / fullAlphaValue(self.dtype)
tileA = tile[:, :, -1].astype(float) / fullAlphaValue(self.dtype)
float) / fullAlphaValue(base.dtype)
tileA = tile[:, :, -1].astype(float) / fullAlphaValue(tile.dtype)
outA = tileA + baseA * (1 - tileA)
base[y:y + tile.shape[0], x:x + tile.shape[1], :-1] = (
np.where(tileA[..., np.newaxis], tile[:, :, :-1], 0) +
base[y:y + tile.shape[0], x:x + tile.shape[1], :-1] * baseA[..., np.newaxis] *
(1 - tileA[..., np.newaxis])
) / np.where(outA[..., np.newaxis], outA[..., np.newaxis], 1)
base[y:y + tile.shape[0], x:x + tile.shape[1], -1] = outA * fullAlphaValue(self.dtype)
base[y:y + tile.shape[0], x:x + tile.shape[1], -1] = outA * fullAlphaValue(base.dtype)
else:
base[y:y + tile.shape[0], x:x + tile.shape[1], :] = tile
return base
Expand Down Expand Up @@ -1157,6 +1157,7 @@
ts, transform, corners, scale, sourceEntry.get('frame', 0),
source.get('position', {}).get('crop'))
if sourceTile is not None and all(dim > 0 for dim in sourceTile.shape):
sourceTile = sourceTile.astype(ts.dtype)
tile = self._mergeTiles(tile, sourceTile, x, y)
return tile

Expand Down