Skip to content

Commit

Permalink
add support for packbits compressed images (#54)
Browse files Browse the repository at this point in the history
* add support for packbits compressed images

* update readme
  • Loading branch information
geospatial-jeff authored Jun 14, 2020
1 parent 9963224 commit ccc1314
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ async with COGReader("https://async-cog-reader-test-data.s3.amazonaws.com/lzw_co
```

### Image Data
The reader also has methods for reading internal image tiles and performing partial reads. Currently only jpeg, lzw,
and webp compressions are supported.
The reader also has methods for reading internal image tiles and performing partial reads. Currently only jpeg, lzw, packbits, and webp compressions are supported.

#### Image Tiles
Reading the top left tile of an image at native resolution:
Expand Down
5 changes: 5 additions & 0 deletions aiocogeo/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ def _deflate(self, tile: bytes) -> np.ndarray:
"""Internal method to decompress DEFLATE image bytes and convert to numpy array"""
decoded = self._reshape(np.frombuffer(imagecodecs.zlib_decode(tile), self.dtype))
self._unpredict(decoded)
return np.rollaxis(decoded, 2, 0)

def _packbits(self, tile: bytes) -> np.ndarray:
"""Internal method to decompress PACKBITS image bytes and convert to numpy array"""
decoded = self._reshape(np.frombuffer(imagecodecs.packbits_decode(tile), self.dtype))
return np.rollaxis(decoded, 2, 0)
1 change: 1 addition & 0 deletions aiocogeo/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
6: "jpeg",
7: "jpeg",
8: "deflate",
32773: "packbits",
50001: "webp",
}

Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"https://async-cog-reader-test-data.s3.amazonaws.com/naip_image_nodata.tif",
"https://async-cog-reader-test-data.s3.amazonaws.com/naip_image.tif",
"https://async-cog-reader-test-data.s3.amazonaws.com/naip_image_masked.tif",
"http://async-cog-reader-test-data.s3.amazonaws.com/packbits_cog.tif",
"https://async-cog-reader-test-data.s3.amazonaws.com/int16_deflate.tif",
os.path.join(DATA_DIR, "cog.tif"),
]
Expand Down

0 comments on commit ccc1314

Please sign in to comment.