Skip to content

Commit

Permalink
Merge pull request #1730 from girder/tile-iterator-length
Browse files Browse the repository at this point in the history
Tile iterators now report their length
  • Loading branch information
manthey authored Nov 25, 2024
2 parents c186297 + aa54e87 commit 1a49e4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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 @@ def _repr_json_(self) -> Dict:
return self.info
return {}

def __len__(self) -> Optional[int]:
if self.info is None:
return None
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

0 comments on commit 1a49e4a

Please sign in to comment.