|
Lines 468-477
Link Here
|
| 468 |
NSSize size = imageHandle.size(); |
468 |
NSSize size = imageHandle.size(); |
| 469 |
NSArray screens = null; |
469 |
NSArray screens = null; |
| 470 |
NSString key = null; |
470 |
NSString key = null; |
| 471 |
if (OS.VERSION >= 0x1070) { |
471 |
screens = NSScreen.screens(); |
| 472 |
screens = NSScreen.screens(); |
472 |
key = NSString.stringWith("NSScreenNumber"); |
| 473 |
key = NSString.stringWith("NSScreenNumber"); |
|
|
| 474 |
} |
| 475 |
CGRect rect = new CGRect(); |
473 |
CGRect rect = new CGRect(); |
| 476 |
rect.origin.x = x; |
474 |
rect.origin.x = x; |
| 477 |
rect.origin.y = y; |
475 |
rect.origin.y = y; |
|
Lines 486-531
Link Here
|
| 486 |
OS.memmove(display, displays + (i * 4), 4); |
484 |
OS.memmove(display, displays + (i * 4), 4); |
| 487 |
OS.CGDisplayBounds(display[0], rect); |
485 |
OS.CGDisplayBounds(display[0], rect); |
| 488 |
double /*float*/ scaling = 1; |
486 |
double /*float*/ scaling = 1; |
| 489 |
if (OS.VERSION >= 0x1070) { |
487 |
for (int j = 0; j < screens.count(); j++) { |
| 490 |
for (int j = 0; j < screens.count(); j++) { |
488 |
NSScreen screen = new NSScreen(screens.objectAtIndex(j)); |
| 491 |
NSScreen screen = new NSScreen(screens.objectAtIndex(j)); |
489 |
if (display[0] == new NSNumber(screen.deviceDescription().objectForKey(key)).intValue()) { |
| 492 |
if (display[0] == new NSNumber(screen.deviceDescription().objectForKey(key)).intValue()) { |
490 |
scaling = screen.backingScaleFactor(); |
| 493 |
scaling = screen.backingScaleFactor(); |
491 |
break; |
| 494 |
break; |
|
|
| 495 |
} |
| 496 |
} |
492 |
} |
|
|
493 |
} |
| 494 |
/* |
| 495 |
* Add a high resolution image representation to the image if scaling factor is > 1 |
| 496 |
*/ |
| 497 |
if (scaling > 1) { |
| 498 |
int width = (int) (size.width * scaling); |
| 499 |
int height = (int) (size.height * scaling); |
| 500 |
NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc(); |
| 501 |
rep = rep.initWithBitmapDataPlanes(0, width, height, 8, 3, false, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32); |
| 502 |
OS.memset(rep.bitmapData(), 0xFF, width * height * 4); |
| 503 |
imageHandle.addRepresentation(rep); |
| 504 |
rep.release(); |
| 497 |
} |
505 |
} |
| 498 |
long /*int*/ srcImage = 0; |
506 |
long /*int*/ srcImage = 0; |
| 499 |
long /*int*/ address = OS.VERSION >= 0x1070 ? 0 : OS.CGDisplayBaseAddress(display[0]); |
507 |
srcImage = OS.CGDisplayCreateImage(display[0]); |
| 500 |
if (address != 0) { |
|
|
| 501 |
long /*int*/ width = OS.CGDisplayPixelsWide(display[0]); |
| 502 |
long /*int*/ height = OS.CGDisplayPixelsHigh(display[0]); |
| 503 |
long /*int*/ bpr = OS.CGDisplayBytesPerRow(display[0]); |
| 504 |
long /*int*/ bpp = OS.CGDisplayBitsPerPixel(display[0]); |
| 505 |
long /*int*/ bps = OS.CGDisplayBitsPerSample(display[0]); |
| 506 |
int bitmapInfo = OS.kCGImageAlphaNoneSkipFirst; |
| 507 |
switch ((int)/*63*/bpp) { |
| 508 |
case 16: bitmapInfo |= OS.kCGBitmapByteOrder16Host; break; |
| 509 |
case 32: bitmapInfo |= OS.kCGBitmapByteOrder32Host; break; |
| 510 |
} |
| 511 |
if (OS.__BIG_ENDIAN__() && OS.VERSION >= 0x1040) { |
| 512 |
long /*int*/ colorspace = OS.CGColorSpaceCreateDeviceRGB(); |
| 513 |
long /*int*/ context = OS.CGBitmapContextCreate(address, width, height, bps, bpr, colorspace, bitmapInfo); |
| 514 |
OS.CGColorSpaceRelease(colorspace); |
| 515 |
srcImage = OS.CGBitmapContextCreateImage(context); |
| 516 |
OS.CGContextRelease(context); |
| 517 |
} else { |
| 518 |
long /*int*/ provider = OS.CGDataProviderCreateWithData(0, address, bpr * height, 0); |
| 519 |
long /*int*/ colorspace = OS.CGColorSpaceCreateDeviceRGB(); |
| 520 |
srcImage = OS.CGImageCreate(width, height, bps, bpp, bpr, colorspace, bitmapInfo, provider, 0, true, 0); |
| 521 |
OS.CGColorSpaceRelease(colorspace); |
| 522 |
OS.CGDataProviderRelease(provider); |
| 523 |
} |
| 524 |
} else { |
| 525 |
if (OS.VERSION >= 0x1060) srcImage = OS.CGDisplayCreateImage(display[0]); |
| 526 |
} |
| 527 |
if (srcImage != 0) { |
508 |
if (srcImage != 0) { |
| 528 |
copyArea(image, (int)(x * scaling - rect.origin.x), (int)(y * scaling - rect.origin.y), srcImage, scaling); |
509 |
copyArea(image, (int)(x * scaling - rect.origin.x), (int)(y * scaling - rect.origin.y), srcImage); |
| 529 |
OS.CGImageRelease(srcImage); |
510 |
OS.CGImageRelease(srcImage); |
| 530 |
} |
511 |
} |
| 531 |
} |
512 |
} |
|
Lines 537-543
Link Here
|
| 537 |
} |
518 |
} |
| 538 |
} |
519 |
} |
| 539 |
|
520 |
|
| 540 |
void copyArea (Image image, int x, int y, long /*int*/ srcImage, double /*float*/ scaling) { |
521 |
void copyArea (Image image, int x, int y, long /*int*/ srcImage) { |
| 541 |
if (srcImage == 0) return; |
522 |
if (srcImage == 0) return; |
| 542 |
NSBitmapImageRep rep = image.getRepresentation(); |
523 |
NSBitmapImageRep rep = image.getRepresentation(); |
| 543 |
long /*int*/ bpc = rep.bitsPerSample(); |
524 |
long /*int*/ bpc = rep.bitsPerSample(); |
|
Lines 557-566
Link Here
|
| 557 |
OS.CGColorSpaceRelease(colorspace); |
538 |
OS.CGColorSpaceRelease(colorspace); |
| 558 |
if (context != 0) { |
539 |
if (context != 0) { |
| 559 |
CGRect rect = new CGRect(); |
540 |
CGRect rect = new CGRect(); |
| 560 |
rect.origin.x = -x / scaling; |
541 |
rect.origin.x = -x; |
| 561 |
rect.origin.y = y / scaling; |
542 |
rect.origin.y = y; |
| 562 |
rect.size.width = OS.CGImageGetWidth(srcImage) / scaling; |
543 |
rect.size.width = OS.CGImageGetWidth(srcImage); |
| 563 |
rect.size.height = OS.CGImageGetHeight(srcImage) / scaling; |
544 |
rect.size.height = OS.CGImageGetHeight(srcImage); |
| 564 |
OS.CGContextTranslateCTM(context, 0, -(rect.size.height - height)); |
545 |
OS.CGContextTranslateCTM(context, 0, -(rect.size.height - height)); |
| 565 |
OS.CGContextDrawImage(context, rect, srcImage); |
546 |
OS.CGContextDrawImage(context, rect, srcImage); |
| 566 |
OS.CGContextRelease(context); |
547 |
OS.CGContextRelease(context); |