Last active
January 6, 2019 20:40
-
-
Save SimonDanisch/55c5853d084b21a1f04653517dedb280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Colors, FixedPointNumbers | |
const DWORD = Culong | |
const LONG = Clong | |
const WORD = Cushort | |
const CIEXYZTRIPLE = NTuple{3, XYZ{Float32}} | |
struct BITMAPV5HEADER | |
bV5Size::DWORD | |
bV5Width::LONG | |
bV5Height::LONG | |
bV5Planes::WORD | |
bV5BitCount::WORD | |
bV5Compression::DWORD | |
bV5SizeImage::DWORD | |
bV5XPelsPerMeter::LONG | |
bV5YPelsPerMeter::LONG | |
bV5ClrUsed::DWORD | |
bV5ClrImportant::DWORD | |
bV5RedMask::DWORD | |
bV5GreenMask::DWORD | |
bV5BlueMask::DWORD | |
bV5AlphaMask::DWORD | |
bV5CSType::DWORD | |
bV5Endpoints::CIEXYZTRIPLE | |
bV5GammaRed::DWORD | |
bV5GammaGreen::DWORD | |
bV5GammaBlue::DWORD | |
bV5Intent::DWORD | |
bV5ProfileData::DWORD | |
bV5ProfileSize::DWORD | |
bV5Reserved::DWORD | |
end | |
function clipboard_image() | |
if ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL) == 0 | |
error("couldn't open clipboard") | |
end | |
pdata = ccall((:GetClipboardData, "user32"), stdcall, Ptr{UInt16}, (UInt32,), 17) | |
if ccall((:CloseClipboard, "user32"), stdcall, Cint, ()) == 0 | |
error("couldn't close clipboard") | |
end | |
pdata == C_NULL && return nothing | |
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), pdata) | |
header = unsafe_load(Ptr{BITMAPV5HEADER}(plock), 1) | |
CType = header.bV5BitCount == 32 ? BGRA{N0f8} : RGB{N0f8} | |
offset = sizeof(header) + header.bV5ClrUsed * sizeof(CType) | |
data = rotl90(unsafe_wrap(Array, Ptr{CType}(plock + offset), (header.bV5Width, header.bV5Height))) | |
@assert ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{UInt16},), plock) != 0 | |
return data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment