comparison src/video/quartz/SDL_QuartzWM.m @ 592:1970e458070d

Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 01 Feb 2003 20:33:59 +0000
parents 04dcaf3da918
children 7ec821f3cbd0
comparison
equal deleted inserted replaced
591:9c9598e4b904 592:1970e458070d
225 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) 225 static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
226 { 226 {
227 NSBitmapImageRep *imgrep; 227 NSBitmapImageRep *imgrep;
228 NSImage *img; 228 NSImage *img;
229 SDL_Surface *mergedSurface; 229 SDL_Surface *mergedSurface;
230 Uint8 *surfPtr; 230 int i,j;
231 int i,j,masksize;
232 NSAutoreleasePool *pool; 231 NSAutoreleasePool *pool;
233 SDL_Rect rrect; 232 SDL_Rect rrect;
234 NSSize imgSize = {icon->w, icon->h}; 233 NSSize imgSize = {icon->w, icon->h};
235 234
236 pool = [ [ NSAutoreleasePool alloc ] init ]; 235 pool = [ [ NSAutoreleasePool alloc ] init ];
242 if (mergedSurface==NULL) { 241 if (mergedSurface==NULL) {
243 NSLog(@"Error creating surface for merge"); 242 NSLog(@"Error creating surface for merge");
244 goto freePool; 243 goto freePool;
245 } 244 }
246 245
246 if (mergedSurface->pitch !=
247 mergedSurface->format->BytesPerPixel * mergedSurface->w) {
248 SDL_SetError ("merged surface has wrong format");
249 SDL_FreeSurface (mergedSurface);
250 goto freePool;
251 }
252
247 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) { 253 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
248 NSLog(@"Error blitting to mergedSurface"); 254 NSLog(@"Error blitting to mergedSurface");
249 goto freePool; 255 goto freePool;
250 } 256 }
251 257
252 if (mask) { 258 if (mask) {
253 masksize=icon->w*icon->h; 259
254 surfPtr = (Uint8 *)mergedSurface->pixels; 260 Uint32 *pixels = mergedSurface->pixels;
255 #define ALPHASHIFT 3 261 for (i = 0; i < mergedSurface->h; i++) {
256 for (i=0;i<masksize;i+=8) 262 for (j = 0; j < mergedSurface->w; j++) {
257 for (j=0;j<8;j++) 263
258 surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00; 264 int index = i * mergedSurface->w + j;
265 int mindex = index >> 3;
266 int bindex = 7 - (index & 0x7);
267
268 if (mask[mindex] & (1 << bindex))
269 pixels[index] |= 0x000000FF;
270 else
271 pixels[index] &= 0xFFFFFF00;
272 }
273 }
259 } 274 }
260 275
261 imgrep = [ [ NSBitmapImageRep alloc] 276 imgrep = [ [ NSBitmapImageRep alloc]
262 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 277 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels
263 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 278 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4