mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Fix alpha premultiplication being used when generating mipmaps
This commit is contained in:
parent
24b064e6b4
commit
f7d57aa859
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file
|
All notable changes to this project will be documented in this file
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed alpha premultiplication when generating mipmaps
|
||||||
|
|
||||||
|
|
||||||
## 0.1.0 - 2021-05-10
|
## 0.1.0 - 2021-05-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -256,7 +256,7 @@ def encode(image: Image.Image, encoder, four_cc: str, mip_count: typing.Optional
|
|||||||
image = image.convert(mode)
|
image = image.convert(mode)
|
||||||
|
|
||||||
sizes = quicktex.image_utils.mip_sizes(image.size, mip_count)
|
sizes = quicktex.image_utils.mip_sizes(image.size, mip_count)
|
||||||
images = [image] + [image.resize(size, Image.BILINEAR) for size in sizes[1:]]
|
images = [image] + [quicktex.image_utils.resize_no_premultiply(image, size) for size in sizes[1:]]
|
||||||
dds = DDSFile()
|
dds = DDSFile()
|
||||||
|
|
||||||
for i in images:
|
for i in images:
|
||||||
|
@ -32,3 +32,20 @@ def mip_sizes(dimensions: Tuple[int, int], mip_count: Optional[int] = None) -> L
|
|||||||
dimensions = tuple([max(dim // 2, 1) for dim in dimensions])
|
dimensions = tuple([max(dim // 2, 1) for dim in dimensions])
|
||||||
|
|
||||||
return chain
|
return chain
|
||||||
|
|
||||||
|
|
||||||
|
def resize_no_premultiply(image: Image.Image, size: Tuple[int, int]) -> Image.Image:
|
||||||
|
"""
|
||||||
|
Resize an image without premulitplying the alpha. Required due to a quick in Pillow
|
||||||
|
|
||||||
|
:param image: Image to resize
|
||||||
|
:param size: Size to resize to
|
||||||
|
:return: The resized image
|
||||||
|
"""
|
||||||
|
if image.mode == 'RGBA':
|
||||||
|
rgb = image.convert('RGB').resize(size, Image.BILINEAR)
|
||||||
|
a = image.getchannel('A').resize(size, Image.BILINEAR)
|
||||||
|
rgb.putalpha(a)
|
||||||
|
return rgb
|
||||||
|
else:
|
||||||
|
return image.resize(size, Image.BILINEAR)
|
||||||
|
Loading…
Reference in New Issue
Block a user