plat/clipdrop.rs#
Source: lib/plat/clipdrop.rs
clipdrop -- the shared helpers of the clipboard image formats and file drops (every OS)
[src/plat/clipdrop.s; docs/modules/CLIPBOARD_DND.md]
drop_reset() start a new pending drop (the old list and data are dropped)
drop_add(path) -> bool one path (empty, too long, NUL inside or too many: false)
drop_uri_list(data) -> n text/uri-list: every file:// URI (host empty or "localhost"),
%XX decoded, '#' lines skipped
drop_take() -> paths hand the pending list over (E_DROP data = its count)
clip_dib_to_bmp(dib) -> BMP file a clipboard DIB (BITMAPCOREHEADER / INFO / V4 / V5
header, masks, colour table, pixels) as a BMP file, None when the header is
invalid. 32-bit BI_RGB / BI_BITFIELDS / BI_ALPHABITFIELDS DIBs are rewritten with
a V5 header (BI_BITFIELDS, the source masks) and paint.net's alpha rule: the alpha
channel (the 4th byte of BI_RGB, else the header's alpha mask) is used when any
pixel has a non-zero alpha, else the image is opaque (alpha mask 0). Other depths
are copied with a BITMAPFILEHEADER in front.
clip_bmp_fix(bmp) -> BMP file the same rule for a BMP file (image/bmp of other programs)
Every length is checked: clipboard / drop data come from other programs. The pending
list keeps raw bytes (a decoded URI need not be UTF-8); drop_take converts lossily.
fn drop_reset()forget the pending list (and the rest of the pending drop: dnd.rs)fn drop_add(path: &str) -> boolone path (copied) -> false when it is empty, too long, has a NUL or the list is fullfn drop_uri_list(data: &[u8]) -> u32text/uri-list -> paths addedfn drop_take() -> Vec<String>hand the pending list over (it starts empty again)fn clip_dib_to_bmp(dib: &[u8]) -> Option<Vec<u8>>a clipboard DIB as a BMP file (None: invalid header)fn clip_bmp_fix(bmp: &[u8]) -> Option<Vec<u8>>a BMP file of another program with the same alpha rulefn clipimg_pack(png: &[u8], bmp: &[u8]) -> Vec<u8>the CLIPIMG bytes of a PNG file and a BMP file (either may be empty)fn clipimg_split(data: &[u8]) -> Option<(&[u8], &[u8])>(PNG, BMP) of CLIPIMG bytes (an absent part is empty; None: malformed)