将 SDL 1.2 的默认调色板与 SDL_CreateRGBSurface() 匹配?
Match SDL 1.2's default palette with SDL_CreateRGBSurface()?
我正在将使用 8 位索引颜色表面的 a SDL 1.2 program (repository) 移植到 SDL2。
不幸的是,SDL_CreateRGBSurface()
默认为 8 bpp 表面设置一个全白的 256 条目调色板,而不是 SDL_SetVideoMode()
在 SDL 1.2 中设置的 RGB884 调色板。
如何设置与 SDL 1.2 SDL_SetVideoMode(..., ..., 8, SDL_SWSURFACE)
调用中的默认调色板相匹配的调色板?
SDL_SetPaletteColors()
和从 SDL 1.2 的 SDL_SetVideoMode()
输出派生的表给我这个片段:
surface = SDL_CreateRGBSurface(0, 100, 100, 8, 0, 0, 0, 0);
Uint8 r[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
Uint8 g[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
Uint8 b[4] = { 0, 85, 170, 255 };
int curColor = 0;
for( unsigned int i = 0; i < 8; ++i )
for( unsigned int j = 0; j < 8; ++j )
for( unsigned int k = 0; k < 4; ++k )
{
SDL_Color color = { r[i], g[j], b[k], 255 };
SDL_SetPaletteColors( surface->format->palette, &color, curColor, 1 );
curColor++;
}
我正在将使用 8 位索引颜色表面的 a SDL 1.2 program (repository) 移植到 SDL2。
不幸的是,SDL_CreateRGBSurface()
默认为 8 bpp 表面设置一个全白的 256 条目调色板,而不是 SDL_SetVideoMode()
在 SDL 1.2 中设置的 RGB884 调色板。
如何设置与 SDL 1.2 SDL_SetVideoMode(..., ..., 8, SDL_SWSURFACE)
调用中的默认调色板相匹配的调色板?
SDL_SetPaletteColors()
和从 SDL 1.2 的 SDL_SetVideoMode()
输出派生的表给我这个片段:
surface = SDL_CreateRGBSurface(0, 100, 100, 8, 0, 0, 0, 0);
Uint8 r[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
Uint8 g[8] = { 0, 36, 73, 109, 146, 182, 219, 255 };
Uint8 b[4] = { 0, 85, 170, 255 };
int curColor = 0;
for( unsigned int i = 0; i < 8; ++i )
for( unsigned int j = 0; j < 8; ++j )
for( unsigned int k = 0; k < 4; ++k )
{
SDL_Color color = { r[i], g[j], b[k], 255 };
SDL_SetPaletteColors( surface->format->palette, &color, curColor, 1 );
curColor++;
}