I found a way for OSX x64 but it was complicated to get it working; had to use asm to work around the problem of OSX not supporting passing of structures by value.
Code: Select all
; OSX 64 bit
ImportC ""
CGBitmapContextCreate(*bdata, width, height, bitsPerComponent, bytesPerRow, cs, bitmapInfo)
CGColorSpaceCreateDeviceRGB()
CGColorSpaceRelease(cs)
CGContextRelease(c)
CGImageRelease(image)
EndImport
Procedure CGContextDrawImage_addr()
ProcedureReturn ?cgcdi_start
cgcdi_start:
!extern _CGContextDrawImage
!sub rsp, 40
!movq [rsp ], xmm0
!movq [rsp + 8], xmm1
!movq [rsp + 16], xmm2
!movq [rsp + 24], xmm3
!call _CGContextDrawImage
!add rsp, 40
!ret
EndProcedure
Procedure CGWindowListCreateImage_addr()
ProcedureReturn ?cgwlci_start
cgwlci_start:
!extern _CGWindowListCreateImage
!sub rsp, 40
!movq [rsp ], xmm0
!movq [rsp + 8], xmm1
!movq [rsp + 16], xmm2
!movq [rsp + 24], xmm3
!call _CGWindowListCreateImage
!add rsp, 40
!ret
EndProcedure
Prototype CGContextDrawImage_proto(c, x.d, y.d, w.d, h.d, image)
Prototype CGWindowListCreateImage_proto(x.d, y.d, w.d, h.d, listOption, windowID, imageOption)
Global CGWindowListCreateImage.CGWindowListCreateImage_proto = CGWindowListCreateImage_addr()
Global CGContextDrawImage.CGContextDrawImage_proto = CGContextDrawImage_addr()
Procedure.l GetColorUnderMouse()
Protected.i image, csRGB, ctx, c.l
image = CGWindowListCreateImage(DesktopMouseX(), DesktopMouseY(), 1, 1, 1, 0, 0)
csRGB = CGColorSpaceCreateDeviceRGB()
ctx = CGBitmapContextCreate(@c, 1, 1, 8, 4, csRGB, 1)
CGContextDrawImage(ctx, 0, 0, 1, 1, image)
CGColorSpaceRelease(csRGB)
CGImageRelease(image)
CGContextRelease(ctx)
ProcedureReturn c
EndProcedure
or a bit shorter
Code: Select all
; OSX 64 bit
ImportC ""
CGBitmapContextCreate(*bdata, width, height, bitsPerComponent, bytesPerRow, cs, bitmapInfo)
CGColorSpaceCreateDeviceRGB()
CGColorSpaceRelease(cs)
CGContextRelease(c)
CGImageRelease(image)
EndImport
Procedure.l GetColorUnderMouse()
Protected.i image, csRGB, ctx
Protected c.l, x.d, y.d, one.d = 1
x = DesktopMouseX()
y = DesktopMouseY()
csRGB = CGColorSpaceCreateDeviceRGB()
ctx = CGBitmapContextCreate(@c, 1, 1, 8, 4, csRGB, 1)
CGColorSpaceRelease(csRGB)
!extern _CGContextDrawImage
!extern _CGWindowListCreateImage
!movsd xmm0, [p.v_x]
!movsd xmm1, [p.v_y]
!movsd xmm2, [p.v_one]
!sub rsp, 32
!movsd [rsp ], xmm0
!movsd [rsp + 8], xmm1
!movsd [rsp + 16], xmm2
!movsd [rsp + 24], xmm2
!mov rdi, 1
!xor rsi, rsi
!xor rdx, rdx
!call _CGWindowListCreateImage
!add rsp, 32
!mov [p.v_image], rax
!mov rdi, [p.v_ctx]
!mov rsi, rax
!pxor xmm0, xmm0
!movsd xmm2, [p.v_one]
!sub rsp, 32
!movupd [rsp], xmm0
!movsd [rsp + 16], xmm2
!movsd [rsp + 24], xmm2
!call _CGContextDrawImage
!add rsp, 32
CGImageRelease(image)
CGContextRelease(ctx)
ProcedureReturn c
EndProcedure