Commits

illume committed 40072b4

pygame.image.save was not resetting color key correctly.

Comments (0)

Files changed (2)

 
     unsigned surf_flags;
     unsigned surf_alpha;
+    unsigned surf_colorkey;
 
     ss_rows = 0;
     ss_size = 0;
 
     surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY);
     surf_alpha = surface->format->alpha;
+    surf_colorkey = surface->format->colorkey;
+
     if (surf_flags & SDL_SRCALPHA)
         SDL_SetAlpha (surface, 0, 255);
     if (surf_flags & SDL_SRCCOLORKEY)
     if (surf_flags & SDL_SRCALPHA)
         SDL_SetAlpha (surface, SDL_SRCALPHA, (Uint8)surf_alpha);
     if (surf_flags & SDL_SRCCOLORKEY)
-        SDL_SetColorKey (surface, SDL_SRCCOLORKEY, surface->format->colorkey);
+        SDL_SetColorKey (surface, SDL_SRCCOLORKEY, surf_colorkey);
 
     for (i = 0; i < ss_h; i++)
     {
                 pass
 
                 
+    def test_save_colorkey(self):
+        """ make sure the color key is not changed when saving.
+        """
+        s = pygame.Surface((10,10), pygame.SRCALPHA, 32)
+        s.fill((23,23,23))
+        s.set_colorkey((0,0,0))
+        colorkey1 = s.get_colorkey()
+        p1 = s.get_at((0,0))
+        
+        temp_filename = "tmpimg.png"
+        try:
+            pygame.image.save(s, temp_filename)
+            s2 = pygame.image.load(temp_filename)
+        finally:
+            os.remove(temp_filename)
 
 
+        colorkey2 = s.get_colorkey()
+        # check that the pixel and the colorkey is correct.
+        self.assertEqual(colorkey1, colorkey2)
+        self.assertEqual(p1, s2.get_at((0,0)))
+        
+        
+        
+        
     def assertPremultipliedAreEqual(self, string1, string2, source_string):
         self.assertEqual(len(string1), len(string2))
         block_size = 20