ImagePaste icon indicating copy to clipboard operation
ImagePaste copied to clipboard

Improve clipboard operation speed on Windows

Open b-init opened this issue 3 years ago • 7 comments

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?

b-init avatar Jun 09 '22 18:06 b-init

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.

thanhph111 avatar Jun 10 '22 03:06 thanhph111

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)

b-init avatar Jun 10 '22 17:06 b-init

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

williamchange avatar Jun 11 '22 07:06 williamchange

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

atticus-lv avatar Jun 11 '22 15:06 atticus-lv

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.

b-init avatar Sep 19 '22 15:09 b-init

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.

b-init avatar Sep 28 '22 11:09 b-init

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.

thanhph111 avatar Sep 28 '22 15:09 thanhph111