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 some issues with compositing rgba geotiffs #915

Merged
merged 1 commit into from
Aug 5, 2022
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 @@ -27,7 +27,7 @@
- Be more consistent in source class name attribute assignment ([884](../../pull/884))

### Bug Fixes
- Fix alpha on GDAL sources with a projection that have an explicit alpha channel ([909](../../pull/909))
- Fix alpha on GDAL sources with a projection that have an explicit alpha channel ([909](../../pull/909), [915](../../pull/915))

## 1.15.1

Expand Down
5 changes: 4 additions & 1 deletion sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def _setDefaultStyle(self):
bstyle['nodata'] = bandInfo.get('nodata', None)
if not hasAlpha and self.projection:
style.append({
'band': len(self.getBandInformation()) + 1,
'band': (
self._bandNumber('alpha', False)
if self._bandNumber('alpha', False) is not None else
(len(self.getBandInformation()) + 1)),
'min': 0,
'max': 'auto',
'composite': 'multiply',
Expand Down
Binary file added test/test_files/rgba_geotiff.tiff
Binary file not shown.
21 changes: 21 additions & 0 deletions test/test_source_gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,24 @@ def testNoData():
imagePath, projection='EPSG:3857',
style={'bands': [{'band': 1, 'max': 100, 'min': 5, 'nodata': 0}]})
assert source.getThumbnail()[0]


def testAlphaProjection():
testDir = os.path.dirname(os.path.realpath(__file__))
imagePath = os.path.join(testDir, 'test_files', 'rgba_geotiff.tiff')
source = large_image_source_gdal.open(
imagePath, projection='EPSG:3857')
base = source.getThumbnail(encoding='PNG')[0]
basenp = source.getThumbnail(format='numpy')[0]
assert numpy.count_nonzero(basenp[:, :, 3] == 255) > 30000
source = large_image_source_gdal.open(
imagePath, projection='EPSG:3857',
style={'bands': [
{'band': 1, 'palette': 'R'},
{'band': 2, 'palette': 'G'},
{'band': 3, 'palette': 'B'}]})
assert source.getThumbnail(encoding='PNG')[0] == base
assert not (source.getThumbnail(format='numpy')[0] - basenp).any()
source = large_image_source_gdal.open(
imagePath)
assert numpy.count_nonzero(source.getThumbnail(format='numpy')[0][:, :, 3] == 255) > 30000
banesullivan marked this conversation as resolved.
Show resolved Hide resolved