Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha blended blitting behaves inconsistently with and without MMX #3364

Open
SDLBugzilla opened this issue Feb 11, 2021 · 2 comments
Open
Assignees
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.10
Reported for operating system, platform: All, x86

Comments on the original bug report:

On 2019-08-12 05:50:10 +0000, Kichikuou wrote:

main.c:

#include <SDL.h>

int main(void) {
  SDL_Surface *src, *dst;
  src = SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 32, SDL_PIXELFORMAT_RGBA32);
  dst = SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 32, SDL_PIXELFORMAT_RGBA32);

  SDL_FillRect(src, NULL, SDL_MapRGBA(src->format, 255, 255, 0, 128));
  SDL_FillRect(dst, NULL, SDL_MapRGBA(dst->format, 255, 255, 255, 0));
  SDL_BlitSurface(src, NULL, dst, NULL);

  Uint8 r, g, b;
  SDL_GetRGB(*(Uint32*)dst->pixels, dst->format, &r, &g, &b);
  printf("(%d, %d, %d)\n", r, g, b);
}

This program prints (253, 253, 126) on my MacOS where BlitRGBtoRGBPixelAlphaMMX3DNOW() is used for blitting, but prints (255, 255, 127) on a Raspberry Pi where non-accelerated BlitRGBtoRGBPixelAlpha() is used.

In BlitRGBtoRGBPixelAlphaMMX3DNOW(), the resulting pixel value is calculated as:

(sa >> 8) + (d(255-a) >> 8)

where s is the source's RGB component value, a is the source's alpha value, and d is the destination's RGB component value. In BlitRGBtoRGBPixelAlpha(), a different calculation is used:

d + ((s-d)*a >> 8)

IMO BlitRGBtoRGBPixelAlpha's behavior is more desirable because it preserves the total signal level.

@slouken slouken removed the bug label May 11, 2022
@icculus
Copy link
Collaborator

icculus commented Sep 9, 2023

BlitRGBtoRGBPixelAlphaMMX3DNOW is gone in SDL3 (but there's still an BlitRGBtoRGBPixelAlphaMMX function which may have the same problem).

I wonder if keeping the MMX versions are worth it, too. We have a NEON version but not SSE atm.

@slouken
Copy link
Collaborator

slouken commented Sep 10, 2023

The last time I checked, the MMX code was a big improvement over the C code and we didn't have AVX or anything faster/newer. That might change soon, but FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants