mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
Maintain paletted textures (#574)
This commit is contained in:
parent
96f60cb683
commit
28b026f605
@ -22,13 +22,14 @@ bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
|
|||||||
desc.dwWidth = surface->w;
|
desc.dwWidth = surface->w;
|
||||||
desc.dwHeight = surface->h;
|
desc.dwHeight = surface->h;
|
||||||
desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
|
desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
|
||||||
desc.ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel == 8 ? 24 : details->bits_per_pixel;
|
desc.ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel;
|
||||||
desc.ddpfPixelFormat.dwRBitMask = details->Rmask;
|
desc.ddpfPixelFormat.dwRBitMask = details->Rmask;
|
||||||
desc.ddpfPixelFormat.dwGBitMask = details->Gmask;
|
desc.ddpfPixelFormat.dwGBitMask = details->Gmask;
|
||||||
desc.ddpfPixelFormat.dwBBitMask = details->Bmask;
|
desc.ddpfPixelFormat.dwBBitMask = details->Bmask;
|
||||||
desc.ddpfPixelFormat.dwRGBAlphaBitMask = details->Amask;
|
desc.ddpfPixelFormat.dwRGBAlphaBitMask = details->Amask;
|
||||||
|
|
||||||
if (VideoManager()->GetDirect3D()->DirectDraw()->CreateSurface(&desc, &p_textureInfo->m_surface, NULL) != DD_OK) {
|
LPDIRECTDRAW pDirectDraw = VideoManager()->GetDirect3D()->DirectDraw();
|
||||||
|
if (pDirectDraw->CreateSurface(&desc, &p_textureInfo->m_surface, NULL) != DD_OK) {
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -45,29 +46,31 @@ bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
|
|||||||
Uint8* srcPixels = (Uint8*) surface->pixels;
|
Uint8* srcPixels = (Uint8*) surface->pixels;
|
||||||
|
|
||||||
if (details->bits_per_pixel == 8) {
|
if (details->bits_per_pixel == 8) {
|
||||||
SDL_Palette* palette = SDL_GetSurfacePalette(surface);
|
SDL_Palette* sdlPalette = SDL_GetSurfacePalette(surface);
|
||||||
if (palette) {
|
if (!sdlPalette) {
|
||||||
for (int y = 0; y < surface->h; ++y) {
|
|
||||||
Uint8* srcRow = srcPixels + y * surface->pitch;
|
|
||||||
Uint8* dstRow = dst + y * desc.lPitch;
|
|
||||||
for (int x = 0; x < surface->w; ++x) {
|
|
||||||
SDL_Color color = palette->colors[srcRow[x]];
|
|
||||||
dstRow[x * 3 + 0] = color.r;
|
|
||||||
dstRow[x * 3 + 1] = color.g;
|
|
||||||
dstRow[x * 3 + 2] = color.b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
p_textureInfo->m_surface->Unlock(desc.lpSurface);
|
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
PALETTEENTRY entries[256];
|
||||||
memcpy(dst, srcPixels, surface->pitch * surface->h);
|
for (int i = 0; i < sdlPalette->ncolors; ++i) {
|
||||||
|
entries[i].peRed = sdlPalette->colors[i].r;
|
||||||
|
entries[i].peGreen = sdlPalette->colors[i].g;
|
||||||
|
entries[i].peBlue = sdlPalette->colors[i].b;
|
||||||
|
entries[i].peFlags = PC_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
LPDIRECTDRAWPALETTE ddPalette = nullptr;
|
||||||
|
if (pDirectDraw->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, entries, &ddPalette, NULL) != DD_OK) {
|
||||||
|
SDL_DestroySurface(surface);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_textureInfo->m_surface->SetPalette(ddPalette);
|
||||||
|
ddPalette->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(dst, srcPixels, surface->pitch * surface->h);
|
||||||
p_textureInfo->m_surface->Unlock(desc.lpSurface);
|
p_textureInfo->m_surface->Unlock(desc.lpSurface);
|
||||||
p_textureInfo->m_palette = NULL;
|
p_textureInfo->m_palette = NULL;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user