Fixed bug 4798 - PNG w/transparency breaks in SDL 2.0.10 but works in SDL 2.0.9
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 75dc2bb..814e536 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -959,6 +959,8 @@
     SDL_Color copy_color;
     SDL_Rect bounds;
     int ret;
+    int palette_ck_transform = 0;
+    int palette_ck_value = 0;
 
     if (!surface) {
         SDL_InvalidParamError("surface");
@@ -1019,8 +1021,23 @@
     bounds.y = 0;
     bounds.w = surface->w;
     bounds.h = surface->h;
+
+    /* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
+    if (copy_flags & SDL_COPY_COLORKEY) {
+        if (surface->format->palette && !format->palette) {
+            palette_ck_transform = 1;
+            palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
+            surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
+        }
+    }
+
     ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
 
+    /* Restore value */
+    if (palette_ck_transform) {
+        surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
+    }
+
     /* Clean up the original surface, and update converted surface */
     convert->map->info.r = copy_color.r;
     convert->map->info.g = copy_color.g;
@@ -1055,7 +1072,9 @@
                   surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
                 /* The palette is identical, just set the same colorkey */
                 SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
-            } else if (format->Amask) {
+            } else if (!format->palette) {
+                /* Was done by 'palette_ck_transform' */
+            }else if (format->Amask) {
                 set_colorkey_by_color = SDL_TRUE;
                 ignore_alpha = SDL_FALSE;
             } else {