b-init / ImagePaste

A simple Blender addon to grab images from your clipboard and paste as a reference image in viewport or onto the image editor.
GNU General Public License v3.0
251 stars 9 forks source link

Clipboard cannot handle transparent pixels #12

Closed thanhph111 closed 3 years ago

thanhph111 commented 3 years ago

Describe the bug

The transparent pixels in images copied from website to Blender and copied from Blender to another place are in wrong color (see the recordings below).

To Reproduce

Copy from website:

  1. Copy a transparent image from website.
  2. Go to Blender and paste as a reference, paste as a plane or paste as a node.
  3. The pasted image doesn't maintain correct transparent pixels.

Copy from Blender:

  1. Open a transparent image with Image Editor.
  2. Use Image > Copy to Clipboard.
  3. Paste it to another software like Microsoft Word.
  4. The pasted image doesn't maintain correct transparent pixels.

Expected behavior

Pasted images to or from Blender must be exactly the same as the original images.

Platform

Operating System:

Blender:

Screencast

Copy from website Copy from Blender
1 2

Additional context

I think it is not efficient to use normal PowerShell cmdlet as it is not built to handle this, we need to use more dedicated assemblies.

Here is the transparent image to test: Image.

b-init commented 3 years ago

Got it working in the latest commit https://github.com/Yeetus3141/ImagePaste/commit/43f92ed9ead261be7a3757ce5fea924b4749b81e! (for both copy and paste) But i've never used powershell scripting before and there probably are some newbie-doodoos. But it works well! Would you like to take a look and make sure everything's right?

thanhph111 commented 3 years ago

Cool! I've tried with System.Windows.Forms before but got nowhere. Didn't know it can work with PowerShell. I'm doing some tests now. Good job man.

Do you think it would be better to move this change to a separate branch so we can do some experiments without affecting the main? If you want, I'll do some polishing for this.

BTW, I admit the terms can be confusing at first. But since these push and pull methods belong to Clipboard, we will see from its perspective. So the push means that the Clipboard gives us the data (it pushes data away, to a files for example), and the pull means it takes images from us (it pulls the image towards itself and we can paste image from it later). I think I didn't explain it thoroughly in the docs so you might get it wrong. Sorry for that.

b-init commented 3 years ago

Yeah another branch for it sounds better, I probably should've done that from the beginning. And I'm sure there's a lot to be polished in my cmdlet scripts so sure! thanks.

oh it was just too confusing when looking the push/pull methods because I was looking at it from blender's side, as that's more intuitive to me. Although your reasoning is fair, I'd still prefer the current way (https://github.com/Yeetus3141/ImagePaste/commit/43f92ed9ead261be7a3757ce5fea924b4749b81e) because whenever we're using this method, it's "blender" executing those commands and hence push for pushing to clipboard from blender and pull for pulling from clipboard to blender makes more sense to me. But using the other terminology shouldn't really be an issue anyway and you're free to change it back if that makes more sense with respect to the code.

thanhph111 commented 3 years ago

I think your point of view is good, I just want to give a different perspective to make it more intuitive and easier to remember.

Because we usually write Clipboard.push and Clipboard.pull, we should think that the Clipboard performs the push or pull operation but not the Blender. So if we include Blender, we can think this way: "Blender tells the clipboard to write to a file (push) and then Blender imports that file" and "Blender saves an image to a file and tells the clipboard to read it (pull)". That's also the way the code runs so I think it's nice to be in that way.

I opened #22 to further discuss about this.

thanhph111 commented 3 years ago

The PR #22 partially handle this issue, the rest is discussed in #23.