Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40593
This commit is contained in:
parent
602b6f286b
commit
9c821f6677
1 changed files with 23 additions and 8 deletions
|
@ -227,8 +227,7 @@ static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
|
||||||
NSBitmapImageRep *imgrep;
|
NSBitmapImageRep *imgrep;
|
||||||
NSImage *img;
|
NSImage *img;
|
||||||
SDL_Surface *mergedSurface;
|
SDL_Surface *mergedSurface;
|
||||||
Uint8 *surfPtr;
|
int i,j;
|
||||||
int i,j,masksize;
|
|
||||||
NSAutoreleasePool *pool;
|
NSAutoreleasePool *pool;
|
||||||
SDL_Rect rrect;
|
SDL_Rect rrect;
|
||||||
NSSize imgSize = {icon->w, icon->h};
|
NSSize imgSize = {icon->w, icon->h};
|
||||||
|
@ -244,18 +243,34 @@ static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
|
||||||
goto freePool;
|
goto freePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mergedSurface->pitch !=
|
||||||
|
mergedSurface->format->BytesPerPixel * mergedSurface->w) {
|
||||||
|
SDL_SetError ("merged surface has wrong format");
|
||||||
|
SDL_FreeSurface (mergedSurface);
|
||||||
|
goto freePool;
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
|
if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
|
||||||
NSLog(@"Error blitting to mergedSurface");
|
NSLog(@"Error blitting to mergedSurface");
|
||||||
goto freePool;
|
goto freePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask) {
|
if (mask) {
|
||||||
masksize=icon->w*icon->h;
|
|
||||||
surfPtr = (Uint8 *)mergedSurface->pixels;
|
Uint32 *pixels = mergedSurface->pixels;
|
||||||
#define ALPHASHIFT 3
|
for (i = 0; i < mergedSurface->h; i++) {
|
||||||
for (i=0;i<masksize;i+=8)
|
for (j = 0; j < mergedSurface->w; j++) {
|
||||||
for (j=0;j<8;j++)
|
|
||||||
surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
|
int index = i * mergedSurface->w + j;
|
||||||
|
int mindex = index >> 3;
|
||||||
|
int bindex = 7 - (index & 0x7);
|
||||||
|
|
||||||
|
if (mask[mindex] & (1 << bindex))
|
||||||
|
pixels[index] |= 0x000000FF;
|
||||||
|
else
|
||||||
|
pixels[index] &= 0xFFFFFF00;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imgrep = [ [ NSBitmapImageRep alloc]
|
imgrep = [ [ NSBitmapImageRep alloc]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue