Improve clipboard operation speed on Windows
I'm working on a python utility to interact with the windows clipboard. It doesn't depend on 3rd party utilities and should be much faster and more flexible than our current approach. The module (clipette) only supports RGB bitmap images now but I'm slowly working on transparency and supporting more formats. After it's good enough, we can work on integrating it with ImagePaste. What do you think?
Amazing, that's a new approach that I haven't thought about.
The script basically uses a shared library of Windows to access to OS APIs and then works with clipboard using them. I wonder if there's a way to do the same on macOS, a quick search brings me to nowhere.
For MacOS, there must be some official documentation about how a software is supposed to exchange clipboard data? (like there is for windows)
And if so, there might also be a way to port that to a python script, given the tool to make that possible exists? (like ctypes for directly accessing windows' clipboard utility)
On macOS this is done through the NSPasteboard https://developer.apple.com/documentation/appkit/nspasteboard which is what the pasteboard module uses, though I haven't looked further into whether this can be achieved like you have done through Windows using a shared library that's native on the platform
In my import addon , I use ctype to improve import speed. It is much faster(about 1ms-) than calling the shell (0.7s). But there is still some encode problem with it https://github.com/atticus-lv/super_io/blob/master/clipboard/clipboard.py#L293
Update: Transparency works now. I've added support for Bitmaps and PNG (both copying and pasting) which is most of what we'll need.
The current hurdles are integrating it with blender. The way I've used ctypes doesn't seem to work through blender, will need to figure that out. Another problem is that blender doesn't support bitmaps with alpha. That's a problem because lot ot the times transparent images are only available on clipboard as bitmaps and I can only save that as a bitmap. But since blender can't read or convert this transparent bitmap, it's stuck.
It's done! Check out the clipette branch and let me know what you think @thanhph111
Sorry if I've not followed any formatting conventions or for the poor structure of the clipette module. I just don't think I properly understand those things yet.
Wow, amazing! This will be a significant upgrade. I'll take a look this weekend. Don't worry about the minor format stuff, you've done most of the work.