Fixed bug 1534 - SIGSEGV in SDL_ConvertSurface() for certain formats in SDL2
Don't assume that 8 bit formats are indexed. Thanks to Gabriel Jacobo for research and potential patches.
This commit is contained in:
parent
80d6ec24cd
commit
e2929bcb73
3 changed files with 235 additions and 229 deletions
|
@ -239,9 +239,11 @@ SDL_CalculateBlit(SDL_Surface * surface)
|
||||||
/* Choose a standard blit function */
|
/* Choose a standard blit function */
|
||||||
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
|
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
|
||||||
blit = SDL_BlitCopy;
|
blit = SDL_BlitCopy;
|
||||||
} else if (surface->format->BitsPerPixel < 8) {
|
} else if (surface->format->BitsPerPixel < 8 &&
|
||||||
|
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
|
||||||
blit = SDL_CalculateBlit0(surface);
|
blit = SDL_CalculateBlit0(surface);
|
||||||
} else if (surface->format->BytesPerPixel == 1) {
|
} else if (surface->format->BytesPerPixel == 1 &&
|
||||||
|
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
|
||||||
blit = SDL_CalculateBlit1(surface);
|
blit = SDL_CalculateBlit1(surface);
|
||||||
} else if (map->info.flags & SDL_COPY_BLEND) {
|
} else if (map->info.flags & SDL_COPY_BLEND) {
|
||||||
blit = SDL_CalculateBlitA(surface);
|
blit = SDL_CalculateBlitA(surface);
|
||||||
|
@ -260,8 +262,13 @@ SDL_CalculateBlit(SDL_Surface * surface)
|
||||||
if (blit == NULL)
|
if (blit == NULL)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (surface->format->BytesPerPixel > 1
|
Uint32 src_format = surface->format->format;
|
||||||
&& dst->format->BytesPerPixel > 1) {
|
Uint32 dst_format = dst->format->format;
|
||||||
|
|
||||||
|
if (!SDL_ISPIXELFORMAT_INDEXED(src_format) &&
|
||||||
|
!SDL_ISPIXELFORMAT_FOURCC(src_format) &&
|
||||||
|
!SDL_ISPIXELFORMAT_INDEXED(dst_format) &&
|
||||||
|
!SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
|
||||||
blit = SDL_Blit_Slow;
|
blit = SDL_Blit_Slow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2436,7 +2436,6 @@ SDL_CalculateBlitN(SDL_Surface * surface)
|
||||||
case 0:
|
case 0:
|
||||||
blitfun = NULL;
|
blitfun = NULL;
|
||||||
if (dstfmt->BitsPerPixel == 8) {
|
if (dstfmt->BitsPerPixel == 8) {
|
||||||
/* We assume 8-bit destinations are palettized */
|
|
||||||
if ((srcfmt->BytesPerPixel == 4) &&
|
if ((srcfmt->BytesPerPixel == 4) &&
|
||||||
(srcfmt->Rmask == 0x00FF0000) &&
|
(srcfmt->Rmask == 0x00FF0000) &&
|
||||||
(srcfmt->Gmask == 0x0000FF00) &&
|
(srcfmt->Gmask == 0x0000FF00) &&
|
||||||
|
|
|
@ -220,7 +220,7 @@ SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
|
||||||
#endif /* USE_ASM_STRETCH */
|
#endif /* USE_ASM_STRETCH */
|
||||||
const int bpp = dst->format->BytesPerPixel;
|
const int bpp = dst->format->BytesPerPixel;
|
||||||
|
|
||||||
if (src->format->BitsPerPixel != dst->format->BitsPerPixel) {
|
if (src->format->format != dst->format->format) {
|
||||||
return SDL_SetError("Only works with same format surfaces");
|
return SDL_SetError("Only works with same format surfaces");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue