Use SDL_PremultiplySurfaceAlpha() when creating NSImages
This commit is contained in:
@@ -253,7 +253,6 @@ NSImage *Cocoa_CreateImage(SDL_Surface *surface)
|
|||||||
SDL_Surface *converted;
|
SDL_Surface *converted;
|
||||||
NSBitmapImageRep *imgrep;
|
NSBitmapImageRep *imgrep;
|
||||||
Uint8 *pixels;
|
Uint8 *pixels;
|
||||||
int i;
|
|
||||||
NSImage *img;
|
NSImage *img;
|
||||||
|
|
||||||
converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
|
converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
|
||||||
@@ -261,6 +260,9 @@ NSImage *Cocoa_CreateImage(SDL_Surface *surface)
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Premultiply the alpha channel */
|
||||||
|
SDL_PremultiplySurfaceAlpha(converted, SDL_FALSE);
|
||||||
|
|
||||||
imgrep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
imgrep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
||||||
pixelsWide:converted->w
|
pixelsWide:converted->w
|
||||||
pixelsHigh:converted->h
|
pixelsHigh:converted->h
|
||||||
@@ -281,15 +283,6 @@ NSImage *Cocoa_CreateImage(SDL_Surface *surface)
|
|||||||
SDL_memcpy(pixels, converted->pixels, (size_t)converted->h * converted->pitch);
|
SDL_memcpy(pixels, converted->pixels, (size_t)converted->h * converted->pitch);
|
||||||
SDL_DestroySurface(converted);
|
SDL_DestroySurface(converted);
|
||||||
|
|
||||||
/* Premultiply the alpha channel */
|
|
||||||
for (i = (surface->h * surface->w); i--;) {
|
|
||||||
Uint8 alpha = pixels[3];
|
|
||||||
pixels[0] = (Uint8)(((Uint16)pixels[0] * alpha) / 255);
|
|
||||||
pixels[1] = (Uint8)(((Uint16)pixels[1] * alpha) / 255);
|
|
||||||
pixels[2] = (Uint8)(((Uint16)pixels[2] * alpha) / 255);
|
|
||||||
pixels += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
img = [[NSImage alloc] initWithSize:NSMakeSize(surface->w, surface->h)];
|
img = [[NSImage alloc] initWithSize:NSMakeSize(surface->w, surface->h)];
|
||||||
if (img != nil) {
|
if (img != nil) {
|
||||||
[img addRepresentation:imgrep];
|
[img addRepresentation:imgrep];
|
||||||
|
|||||||
Reference in New Issue
Block a user