forked from nmichaud/enable-mapping
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require pixel arrays to be passed to TileManager.process_raw
Before, encoded pixel buffers were being passed.
- Loading branch information
Showing
7 changed files
with
50 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from io import BytesIO | ||
|
||
import numpy as np | ||
from PIL import Image | ||
|
||
from kiva.compat import piltostring | ||
|
||
DEPTH_MAP = {'RGB': 3, 'RGBA': 4} | ||
|
||
|
||
def img_data_to_img_array(data): | ||
""" Convert a buffer of encoded image data to a numpy array of pixels. | ||
""" | ||
pil_img = Image.open(BytesIO(data)) | ||
if pil_img.mode not in ('RGB', 'RGBA'): | ||
pil_img = pil_img.convert(mode='RGBA') | ||
|
||
depth = DEPTH_MAP[pil_img.mode] | ||
img = np.fromstring(piltostring(pil_img), np.uint8) | ||
return np.resize(img, (pil_img.size[1], pil_img.size[0], depth)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters