mirror of https://github.com/encounter/SDL.git
video: Add SDL_PremultiplySurfaceAlphaToARGB8888()
A number of video backends need to get ARGB8888 formatted surfaces with premultiplied alpha, typically for mouse cursors. Add a new function to do this, based loosely on legacy_alpha_premultiply_ARGB8888() from the KMSDRM backend. The new function, SDL_PremultiplySurfaceAlphaToARGB8888() takes two arguments: - src: an SDL_Surface to be converted. - dst: a buffer which is filled with premultiplied ARGB8888 data of the same size as the surface (assuming pitch = w). This is not heavily optimised: it just repeatedly calls SDL_GetRGBA() to do the conversion, but should do for now.
This commit is contained in:
parent
007b5463e8
commit
84808ea4bb
|
@ -1227,4 +1227,34 @@ SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Creates a copy of an ARGB8888-format surface's pixels with premultiplied alpha */
|
||||||
|
void
|
||||||
|
SDL_PremultiplySurfaceAlphaToARGB8888(SDL_Surface *src, Uint32 *dst)
|
||||||
|
{
|
||||||
|
Uint8 A, R, G, B;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
if (SDL_MUSTLOCK(src))
|
||||||
|
SDL_LockSurface(src);
|
||||||
|
|
||||||
|
for (y = 0; y < src->h; ++y) {
|
||||||
|
Uint8 *src_px = (Uint8*)(src->pixels) + (y * src->pitch);
|
||||||
|
for (x = 0; x < src->w; ++x) {
|
||||||
|
/* Component bytes extraction. */
|
||||||
|
SDL_GetRGBA(*(Uint32*)src_px, src->format, &R, &G, &B, &A);
|
||||||
|
src_px += src->format->BytesPerPixel;
|
||||||
|
|
||||||
|
/* Alpha pre-multiplication of each component. */
|
||||||
|
R = (float)A * ((float)R /255);
|
||||||
|
G = (float)A * ((float)G /255);
|
||||||
|
B = (float)A * ((float)B /255);
|
||||||
|
|
||||||
|
/* ARGB8888 pixel recomposition. */
|
||||||
|
(*dst++) = (((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8)) | ((Uint32)B << 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK(src))
|
||||||
|
SDL_UnlockSurface(src);
|
||||||
|
}
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -43,6 +43,7 @@ extern void SDL_InvalidateAllBlitMap(SDL_Surface *surface);
|
||||||
extern void SDL_DitherColors(SDL_Color * colors, int bpp);
|
extern void SDL_DitherColors(SDL_Color * colors, int bpp);
|
||||||
extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||||
extern void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel);
|
extern void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel);
|
||||||
|
extern void SDL_PremultiplySurfaceAlphaToARGB8888(SDL_Surface *src, Uint32 *dst);
|
||||||
|
|
||||||
#endif /* SDL_pixels_c_h_ */
|
#endif /* SDL_pixels_c_h_ */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue