From cd3b7c6043916f172abef01f427c719741fa9f1f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 1 Feb 2003 20:33:59 +0000 Subject: [PATCH] Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!) --- src/video/quartz/SDL_QuartzWM.m | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/video/quartz/SDL_QuartzWM.m b/src/video/quartz/SDL_QuartzWM.m index 4f098d381..97c1a7f55 100644 --- a/src/video/quartz/SDL_QuartzWM.m +++ b/src/video/quartz/SDL_QuartzWM.m @@ -227,8 +227,7 @@ static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) NSBitmapImageRep *imgrep; NSImage *img; SDL_Surface *mergedSurface; - Uint8 *surfPtr; - int i,j,masksize; + int i,j; NSAutoreleasePool *pool; SDL_Rect rrect; NSSize imgSize = {icon->w, icon->h}; @@ -244,18 +243,34 @@ static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) 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)) { NSLog(@"Error blitting to mergedSurface"); goto freePool; } if (mask) { - masksize=icon->w*icon->h; - surfPtr = (Uint8 *)mergedSurface->pixels; - #define ALPHASHIFT 3 - for (i=0;i>3]&(1<<(7-j)))?0xFF:0x00; + + Uint32 *pixels = mergedSurface->pixels; + for (i = 0; i < mergedSurface->h; i++) { + for (j = 0; j < mergedSurface->w; j++) { + + 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]