Created
September 7, 2019 20:17
-
-
Save sofroniewn/62d4ec2146232abd80470f7ccefee8a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def _get_viewer_thumbnail(self): | |
| """Creat an overall thumbnail based on the layer thumbnails.""" | |
| thumbnail = np.zeros(layers.Layer._thumbnail_shape, dtype=np.uint8) | |
| for layer in self.layers[::-1]: | |
| if layer.blending == 'translucent': | |
| f_dest = thumbnail[..., 3][..., None] / 255 | |
| f_source = 1 - layer.thumbnail[..., 3][..., None] / 255 | |
| elif layer.blending == 'additive': | |
| f_dest = thumbnail[..., 3][..., None] / 255 | |
| f_source = 1 | |
| elif layer.blending == 'opaque': | |
| f_dest = 0 | |
| f_source = 1 | |
| else: | |
| raise ValueError(f'Layer blending mode not recognized, got {layer.blending}') | |
| thumbnail = thumbnail * f_dest + layer.thumbnail * f_source | |
| thumbnail = thumbnail.astype(np.uint8) | |
| return thumbnail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment