@@ -173,6 +173,44 @@ def test_scale__alpha(self):
173
173
self .assertEqual (s .get_alpha (), s3 .get_alpha ())
174
174
self .assertEqual (s .get_alpha (), s2 .get_alpha ())
175
175
176
+ def test_scale__palette (self ):
177
+ """see if palette information from source is kept.
178
+
179
+ Test for newsurf_fromsurf regression reported in
180
+ https://github.com/pygame-community/pygame-ce/issues/3463"""
181
+
182
+ s = pygame .Surface ((32 , 32 ), depth = 8 )
183
+ s .fill ("red" , [0 , 0 , 32 , 16 ])
184
+ s .fill ("purple" , [0 , 16 , 32 , 16 ])
185
+ self .assertTrue (len (s .get_palette ()) > 0 )
186
+
187
+ s2 = pygame .transform .scale (s , (64 , 64 ))
188
+ self .assertEqual (s .get_palette ()[0 ], s2 .get_palette ()[0 ])
189
+ self .assertEqual (s .get_at_mapped ((0 , 0 )), s2 .get_at_mapped ((0 , 0 )))
190
+ self .assertEqual (s .get_at_mapped ((0 , 17 )), s2 .get_at_mapped ((0 , 35 )))
191
+
192
+ # Also test with a custom palette to make sure the output doesn't just
193
+ # have a default palette.
194
+ s = pygame .Surface ((32 , 32 ), depth = 8 )
195
+ s .set_palette (
196
+ [
197
+ pygame .Color ("red" ),
198
+ pygame .Color ("purple" ),
199
+ pygame .Color ("gold" ),
200
+ pygame .Color ("blue" ),
201
+ pygame .Color ("lightgreen" ),
202
+ ]
203
+ )
204
+ s .fill ("red" , [0 , 0 , 32 , 16 ])
205
+ s .fill ("purple" , [0 , 16 , 32 , 16 ])
206
+ self .assertTrue (len (s .get_palette ()) > 0 )
207
+
208
+ s2 = pygame .transform .scale (s , (64 , 64 ))
209
+ self .assertEqual (s .get_palette ()[0 ], s2 .get_palette ()[0 ])
210
+ self .assertEqual (s .get_palette (), s2 .get_palette ())
211
+ self .assertEqual (s .get_at_mapped ((0 , 0 )), s2 .get_at_mapped ((0 , 0 )))
212
+ self .assertEqual (s .get_at_mapped ((0 , 17 )), s2 .get_at_mapped ((0 , 35 )))
213
+
176
214
def test_scale__destination (self ):
177
215
"""see if the destination surface can be passed in to use."""
178
216
@@ -1727,6 +1765,34 @@ def test_invert(self):
1727
1765
pygame .Surface ((10 , 10 ), depth = 8 ),
1728
1766
)
1729
1767
1768
+ def test_invert__palette (self ):
1769
+ """see if palette information from source is kept.
1770
+
1771
+ Test for newsurf_fromsurf regression reported in
1772
+ https://github.com/pygame-community/pygame-ce/issues/3463"""
1773
+
1774
+ s = pygame .Surface ((32 , 32 ), depth = 8 )
1775
+ s .set_palette ([pygame .Color ("orange" ) for _ in range (256 )])
1776
+ s .set_palette (
1777
+ [
1778
+ pygame .Color ("red" ),
1779
+ pygame .Color ("purple" ),
1780
+ pygame .Color ("gold" ),
1781
+ pygame .Color ("blue" ),
1782
+ pygame .Color ("lightgreen" ),
1783
+ ]
1784
+ )
1785
+ s .fill ("red" , [0 , 0 , 32 , 16 ])
1786
+ s .fill ("blue" , [0 , 16 , 32 , 16 ])
1787
+ self .assertTrue (len (s .get_palette ()) > 0 )
1788
+
1789
+ s2 = pygame .transform .invert (s )
1790
+ self .assertEqual (s .get_palette ()[0 ], s2 .get_palette ()[0 ])
1791
+ self .assertEqual (s .get_palette (), s2 .get_palette ())
1792
+
1793
+ self .assertEqual (s2 .get_at ((0 , 0 )), pygame .Color ("lightgreen" ))
1794
+ self .assertEqual (s2 .get_at ((0 , 17 )), pygame .Color ("gold" ))
1795
+
1730
1796
def test_smoothscale (self ):
1731
1797
"""Tests the stated boundaries, sizing, and color blending of smoothscale function"""
1732
1798
# __doc__ (as of 2008-08-02) for pygame.transform.smoothscale:
0 commit comments