DirectFB: fixed creation of palette textures
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 7db35dd..6a59bb7 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1146,8 +1146,10 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
return NULL;
}
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
- SDL_SetError("Palettized textures are not supported");
- return NULL;
+ if (!IsSupportedFormat(renderer, format)) {
+ SDL_SetError("Palettized textures are not supported");
+ return NULL;
+ }
}
if (w <= 0 || h <= 0) {
SDL_SetError("Texture dimensions can't be 0");
@@ -1341,6 +1343,18 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
} else {
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
}
+
+#if SDL_VIDEO_RENDER_DIRECTFB
+ /* DirectFB allows palette format for textures.
+ * Copy SDL_Surface palette to the texture */
+ if (SDL_ISPIXELFORMAT_INDEXED(format)) {
+ if (SDL_strcasecmp(renderer->info.name, "directfb") == 0) {
+ extern void DirectFB_SetTexturePalette(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Palette *pal);
+ DirectFB_SetTexturePalette(renderer, texture, surface->format->palette);
+ }
+ }
+#endif
+
} else {
SDL_PixelFormat *dst_fmt;
SDL_Surface *temp = NULL;
diff --git a/src/video/directfb/SDL_DirectFB_render.c b/src/video/directfb/SDL_DirectFB_render.c
index 90adccb..5f5e0b8 100644
--- a/src/video/directfb/SDL_DirectFB_render.c
+++ b/src/video/directfb/SDL_DirectFB_render.c
@@ -324,6 +324,22 @@ DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
return 1;
}
+
+/* Copy the SDL_Surface palette to the DirectFB texture palette */
+void DirectFB_SetTexturePalette(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Palette *pal)
+{
+ int i;
+ DFBColor dfbpal[256];
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+ for (i = 0; i < pal->ncolors; i++) {
+ dfbpal[i].a = pal->colors[i].a;
+ dfbpal[i].r = pal->colors[i].r;
+ dfbpal[i].g = pal->colors[i].g;
+ dfbpal[i].b = pal->colors[i].b;
+ }
+ data->palette->SetEntries(data->palette, dfbpal, pal->ncolors, 0);
+}
+
static int
DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{