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

Tile iterators now report their length #1730

Merged
merged 1 commit into from
Nov 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Better handle IndicaLabs tiff files ([#1717](../../pull/1717))
- Better detect files with geotransform data that aren't geospatial ([#1718](../../pull/1718))
- Better scale float-valued tiles ([#1725](../../pull/1725))
- Tile iterators now report their length ([#1730](../../pull/1730))

### Changes

Expand Down
9 changes: 9 additions & 0 deletions large_image/tilesource/tileiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
return self.info
return {}

def __len__(self) -> Optional[int]:
if self.info is None:
return None

Check warning on line 73 in large_image/tilesource/tileiterator.py

View check run for this annotation

Codecov / codecov/patch

large_image/tilesource/tileiterator.py#L73

Added line #L73 was not covered by tests
iterlen = ((cast(int, self.info['xmax']) - cast(int, self.info['xmin'])) *
(cast(int, self.info['ymax']) - cast(int, self.info['ymin'])))
if self.info.get('tile_position') is not None:
return 1 if cast(int, self.info['tile_position']) < iterlen else 0
return iterlen

def _tileIteratorInfo(self, **kwargs) -> Optional[Dict[str, Any]]: # noqa
"""
Get information necessary to construct a tile iterator.
Expand Down
2 changes: 1 addition & 1 deletion sources/pil/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def prerelease_local_scheme(version):
'all': [
'rawpy ; python_version < "3.13"',
'pillow-heif',
'pillow-jxl-plugin ; python_version < "3.13"',
'pillow-jxl-plugin',
'pillow-jpls',
],
'girder': f'girder-large-image{limit_version}',
Expand Down