comparison src/video/quartz/SDL_QuartzWM.m @ 1659:14717b52abc0 SDL-1.3

Merge trunk-1.3-3
author Sam Lantinga <slouken@libsdl.org>
date Wed, 17 May 2006 08:18:28 +0000
parents e49147870aac
children 782fd950bd46
comparison
equal deleted inserted replaced
1658:e49147870aac 1659:14717b52abc0
39 int w, int h, int hot_x, int hot_y) { 39 int w, int h, int hot_x, int hot_y) {
40 WMcursor *cursor; 40 WMcursor *cursor;
41 int row, bytes; 41 int row, bytes;
42 42
43 /* Allocate the cursor memory */ 43 /* Allocate the cursor memory */
44 cursor = (WMcursor *)malloc(sizeof(WMcursor)); 44 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
45 if ( cursor == NULL ) { 45 if ( cursor == NULL ) {
46 SDL_OutOfMemory(); 46 SDL_OutOfMemory();
47 return(NULL); 47 return(NULL);
48 } 48 }
49 memset(cursor, 0, sizeof(*cursor)); 49 SDL_memset(cursor, 0, sizeof(*cursor));
50 50
51 if (w > 16) 51 if (w > 16)
52 w = 16; 52 w = 16;
53 53
54 if (h > 16) 54 if (h > 16)
55 h = 16; 55 h = 16;
56 56
57 bytes = (w+7)/8; 57 bytes = (w+7)/8;
58 58
59 for ( row=0; row<h; ++row ) { 59 for ( row=0; row<h; ++row ) {
60 memcpy(&cursor->curs.data[row], data, bytes); 60 SDL_memcpy(&cursor->curs.data[row], data, bytes);
61 data += bytes; 61 data += bytes;
62 } 62 }
63 for ( row=0; row<h; ++row ) { 63 for ( row=0; row<h; ++row ) {
64 memcpy(&cursor->curs.mask[row], mask, bytes); 64 SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
65 mask += bytes; 65 mask += bytes;
66 } 66 }
67 cursor->curs.hotSpot.h = hot_x; 67 cursor->curs.hotSpot.h = hot_x;
68 cursor->curs.hotSpot.v = hot_y; 68 cursor->curs.hotSpot.v = hot_y;
69 69
260 void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) 260 void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask)
261 { 261 {
262 NSBitmapImageRep *imgrep; 262 NSBitmapImageRep *imgrep;
263 NSImage *img; 263 NSImage *img;
264 SDL_Surface *mergedSurface; 264 SDL_Surface *mergedSurface;
265 int i,j;
266 NSAutoreleasePool *pool; 265 NSAutoreleasePool *pool;
267 SDL_Rect rrect; 266 Uint8 *pixels;
268 NSSize imgSize = {icon->w, icon->h}; 267 SDL_bool iconSrcAlpha;
268 Uint8 iconAlphaValue;
269 int i, j, maskPitch, index;
269 270
270 pool = [ [ NSAutoreleasePool alloc ] init ]; 271 pool = [ [ NSAutoreleasePool alloc ] init ];
271 SDL_GetClipRect(icon, &rrect); 272
272 273 imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4*icon->w bitsPerPixel: 32 ] autorelease ];
273 /* create a big endian RGBA surface */ 274 if (imgrep == nil) goto freePool;
274 mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 275 pixels = [ imgrep bitmapData ];
275 icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0); 276 SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
276 if (mergedSurface==NULL) { 277
277 NSLog(@"Error creating surface for merge"); 278 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
278 goto freePool; 279 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
279 } 280 #else
280 281 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
281 if (mergedSurface->pitch != 282 #endif
282 mergedSurface->format->BytesPerPixel * mergedSurface->w) { 283 mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS);
283 SDL_SetError ("merged surface has wrong format"); 284 if (mergedSurface == NULL) goto freePool;
284 SDL_FreeSurface (mergedSurface); 285
285 goto freePool; 286 /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
286 } 287 iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
287 288 iconAlphaValue = icon->format->alpha;
288 if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) { 289 SDL_SetAlpha(icon, 0, 255);
289 NSLog(@"Error blitting to mergedSurface"); 290 SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
290 goto freePool; 291 if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
291 } 292
292 293 SDL_FreeSurface(mergedSurface);
293 if (mask) { 294
294 295 /* apply mask, source alpha, and premultiply color values by alpha */
295 Uint32 *pixels = mergedSurface->pixels; 296 maskPitch = (icon->w+7)/8;
296 for (i = 0; i < mergedSurface->h; i++) { 297 for (i = 0; i < icon->h; i++) {
297 for (j = 0; j < mergedSurface->w; j++) { 298 for (j = 0; j < icon->w; j++) {
298 299 index = i*4*icon->w + j*4;
299 int index = i * mergedSurface->w + j; 300 if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) {
300 int mindex = index >> 3; 301 pixels[index + 3] = 0;
301 int bindex = 7 - (index & 0x7);
302
303 if (mask[mindex] & (1 << bindex))
304 pixels[index] |= 0x000000FF;
305 else
306 pixels[index] &= 0xFFFFFF00;
307 } 302 }
308 } 303 else {
309 } 304 if (iconSrcAlpha) {
310 305 if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha;
311 imgrep = [ [ NSBitmapImageRep alloc] 306 }
312 initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 307 else {
313 pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 308 pixels[index + 3] = 255;
314 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 309 }
315 bytesPerRow:icon->w<<2 bitsPerPixel:32 ]; 310 }
316 311 if (pixels[index + 3] < 255) {
317 img = [ [ NSImage alloc ] initWithSize:imgSize ]; 312 pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255;
318 313 pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255;
314 pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255;
315 }
316 }
317 }
318
319 img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ];
320 if (img == nil) goto freePool;
319 [ img addRepresentation: imgrep ]; 321 [ img addRepresentation: imgrep ];
320 [ NSApp setApplicationIconImage:img ]; 322 [ NSApp setApplicationIconImage:img ];
321 323
322 [ img release ];
323 [ imgrep release ];
324 SDL_FreeSurface(mergedSurface);
325 freePool: 324 freePool:
326 [pool release]; 325 [ pool release ];
327 } 326 }
328 327
329 int QZ_IconifyWindow (_THIS) { 328 int QZ_IconifyWindow (_THIS) {
330 329
331 if ( ! [ qz_window isMiniaturized ] ) { 330 if ( ! [ qz_window isMiniaturized ] ) {