From 3528220d4d6c5e39b6847e7331472d5e5f60121d Mon Sep 17 00:00:00 2001 From: Jarikf Date: Sat, 16 Apr 2022 03:54:48 +0300 Subject: [PATCH] fix palette images with bytes transparency conversion (#21) Co-authored-by: Iaroslav Fadeev --- pillow_heif/heif.py | 3 ++- .../palette_with_bytes_transparency.png | Bin 0 -> 1138 bytes tests/opener_encoder_test.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/images/jpeg_gif_png/palette_with_bytes_transparency.png diff --git a/pillow_heif/heif.py b/pillow_heif/heif.py index fa1ba588..cce0732c 100644 --- a/pillow_heif/heif.py +++ b/pillow_heif/heif.py @@ -300,7 +300,8 @@ def add_from_pillow(self, pil_image: Image, load_one=False): if k in frame.info: additional_info[k] = frame.info[k] if frame.mode == "P": - frame = frame.convert(mode="RGB") + mode = 'RGBA' if frame.info.get('transparency') else 'RGB' + frame = frame.convert(mode=mode) # How here we can detect bit depth of Pillow image? pallete.rawmode or maybe something else? __bit_depth = 8 self._add_frombytes(__bit_depth, frame.mode, frame.size, frame.tobytes(), add_info={**additional_info}) diff --git a/tests/images/jpeg_gif_png/palette_with_bytes_transparency.png b/tests/images/jpeg_gif_png/palette_with_bytes_transparency.png new file mode 100644 index 0000000000000000000000000000000000000000..859f9c384113a55f59bacf13c222a672e4cfedc5 GIT binary patch literal 1138 zcmeAS@N?(olHy`uVBq!ia0vp^DImB|mLR{SoeCq4#o0^({WOH+K zZEbB!OUtZTv+C;V7B61hP+t$^R#jHk)KoV$HvahWK_4>^)ciYov&%Ju{_SNe*FJ8WS z{^I4!SFeHGH}Bp(d;a3_(`QefJqId&`~Ll-Cr|I*e{lWg?Hjl6Jbe7*)}6aR15cej zckjWYPoKZsfB5*r$4{59T?d*8H2K|!4`X}Tol|}B@|A0Q7wliqc<{*4LrYqhx1?_0wR`XW0~;n3?cTe$sJM9Iq{&;i zZQr)SF+Qysj%NA|zn#`t_5iPMte%?!wB5sd)jG3gWMy-H5W( zdV257s?}?PeceuNo|P0EK5fQ~nX_lVd~|8yf(3347WVe`HxDh-kq}(gS+H#BlC85E zCzZu7T)afVpU+!Y;r`8II$D~x=^CwBA%|B_-oJg-txE@r=lN}JiCDg3B{1}SY7MK4 zGt*}{?^)c_o!}%d%vZlAbk58vrAdM3j&6;PiShCEoz&A}TPYpZVdj}*x@B7E#KT8gWJt@iBR zeE7glpDv|kh3*-yhG)(mTf1_3WVv(y`t*&LdSYhiuA131@jz@wkWt4YzU;QTaUo`WQaS3T&Ou4V9fx}t zmPjp}f93S1NZY&b4&UE7_5GG3cdop8aOcCdkN<}a5IkRH2P_^GJzX3_D(1XB*a+k> l9A5A