pencil2d / pencil

Pencil2D is an easy, intuitive tool to make 2D hand-drawn animations. Pencil2D is open source and cross-platform.
http://pencil2d.org
GNU General Public License v2.0
1.48k stars 272 forks source link

Failure to paste specific selections from Affinity products into a frame #1681

Open John-Hollingum opened 2 years ago

John-Hollingum commented 2 years ago

Issue Summary

Some clipboard selections from Affinity Photo will not paste into bitmap key frames

### Actual Results Some attempts to paste selections in the clipboard into bitmap key frames produced no visible result whether or not there was a selection marquee currently on the frame. The clipboard content pasted sensibly into other applications like Pages. ### Expected Results I had expected the images to appear somewhere in the workspace. ### Video or Image Reference ### Steps to reproduce This is the tricky bit. As far as I can tell, the steps used to create the error can produce correct results. That is, I open a jpeg file in Affinity Photo, I make a selection in the image I then paste it into a bitmap frame. Just cmd-c cmd-v. While some jpegs in Affinity work absolutely consistently, other images fail quite consistently. All the selections from Affinity paste into other applications as expected. If you can think of any significant differences in the source images I can dig a bit deeper, but it looks to me like some jpegs work and others don't. ### System Information + Pencil2D Version: Version: 0.6.6 commit: ac415788dfb21f66e1cbcc1ad60443225a2d0e37 date: 2021-02-17_13:03:37 + Operating System: Operating System: macOS 10.15 CPU Architecture: x86_64 Qt Version: 5.15.2 + RAM Size: 8 GB 1600 MHz DDR3 + Graphics Tablet:
Jose-Moreno commented 2 years ago

@John-Hollingum Hi John, thank you for your report. It is strange that copy /pasting is failing with some images and not others. In this case most of the heavy lifting is done by the original software (i.e Affinity) and each app seems to have a different requirement to properly copy to clipboard but overall they all should work as expected.

For example using Inkscape you can copy vectors and rasterize-paste them into Pencil2d without any issue, however they must be inside the canvas document over at Inkscape otherwise it won't work.

In order for us to test this out, Is it possible that you can share with us a few samples of the images that work and those that particularly don't work so we can test them out? I don't have Affinity Designer but I used to use Serif's Photoplus back in the day (it's predecessor) so I could download a trial to test.

Since this is a public forum if you can't share them openly due to non-disclosure restrictions please upload them on a google drive account and send a folder sharing invitation to pencil2danimation(at)gmail.com (at) -> @ so we can view them through the project's drive account and would only keep them until the testing has been concluded (and the issue resolved).

I personally have tested various images from work pasting over from apps like: Clip Studio Paint, Krita, Inkscape, Photoshop, Illustrator, GIMP, Animate CC and other apps. The only one that has have given poor results is Animate CC but that is actually expected since their clipboard handling has been known to be terrible since the age of Flash (often times it doesn't even work properly between Adobe apps 😕 ).

scribblemaniac commented 2 years ago

As @Jose-Moreno suggested, if you could share some of the files that do and don't work, that would be very helpful. Additionally, if you could try the following steps to gather some more information for us:

  1. Go to this page: https://jsfiddle.net/scribblemaniac/ar9qLuwn/ in Safari
  2. Copy an image from Affinity Photo in the same way that is causing issues with Pencil2D
  3. Click the "Check Clipboard" button in the bottom right quadrant of the webpage, and then select the Paste option.
  4. Some output should show up below the button, make note of it.
  5. Repeat steps 2-4 with a photo that is not causing issue with Pencil2D.
  6. Check if there's any difference in the output between the images that are and are not working. Share your results and the output text here.
John-Hollingum commented 2 years ago

Right, I copied some of the 'bad' image, and checked by pasting in Affinity, that I had actually got something. When I hit 'check clipboard' it gave me this:

Clipboard types:

Error: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

John-Hollingum commented 2 years ago

That doesn't tell me much as I get the same result with the 'good' image. Do I need to tweak some permissions in safari somehow?

John-Hollingum commented 2 years ago

The 'bad' image pastes OK when copied from Preview rather than Affinity. Is it possible affinity is sending the data to the clipboard in some deprecated format?

John-Hollingum commented 2 years ago

If I copy the 'bad' image from preview rather than affinity, then go into Finder ... Edit ... view clipboard, I get a window with the image in it. If I do the same after copying from either the 'good' or 'bad' image in Affinity, I get a blank window with the message 'Clipboard contains: text' in the bar at the bottom of the window, whatever that's called.

John-Hollingum commented 2 years ago

I've identified what the magic difference is between the two images. The good one is encoded with Color Format RGB/8 and ICC Profile sRGB IEC61966-2.1 . The bad one had Color Format CMYK/8 and an ICC Profile of U.S Web Coated (SWOP) V2. With my limited understanding of this field, it sounds like a additive RGB encoding works and a subtractive CMYK, printer-type encoding doesn't. I've got a workaround because Affinity can convert between formats so I don't have an urgent need for a fix.

Jose-Moreno commented 2 years ago

I've identified what the magic difference is between the two images. The good one is encoded with Color Format RGB/8 and ICC Profile sRGB IEC61966-2.1 . The bad one had Color Format CMYK/8 and an ICC Profile of U.S Web Coated (SWOP) V2. With my limited understanding of this field, it sounds like a additive RGB encoding works and a subtractive CMYK, printer-type encoding doesn't. I've got a workaround because Affinity can convert between formats so I don't have an urgent need for a fix.

Hi @John-Hollingum Thank you for your testing. Interesting, yesterday while I wrote my reply, I actually tested copying and pasting both RGB and CMYK color space image from Adobe Illustrator and it would paste just fine on Pencil2D's canvas. However this might be because Illustrator might pre-emptively convert the original image to an RGB colorspace once it sends the data to the clipboard.

The 'bad' image pastes OK when copied from Preview rather than Affinity. Is it possible affinity is sending the data to the clipboard in some deprecated format?

While we can't overrule how the color space might be affecting the clipboard handling as you surmise, I too think this issue has to do with how Affinity handles the images on their end.

Jose-Moreno commented 2 years ago

https://forum.affinity.serif.com/index.php?/topic/79016-convert-cmyk-image-to-rgb-when-copying-from-another-designer-project/ https://affinity.help/designer/en-US.lproj/index.html?page=pages/Clr/ClrProfiles.html?title=Color%20management https://affinity.help/designer/en-US.lproj/index.html?page=pages/Clr/ClrModels.html?title=Color%20models

Reading through the links above as well as the linked manual pages on color management makes me think that instead of having a deprecated format. What could be happening is that Affinity apps might be not converting the image at all, leaving the data "as is", when capturing and sending the copied image data to the clipboard.

Even if the software has been configured to handle color management and convert the color model of incoming image data, this procedure seems to occurs only when pasting the data, not during the copying procedure.

Considering that when you sent data into this "preview" feature you mentioned, and it actually works it's possible that for visualization purposes, the data is normalized and reconverted to a screen safe color space such as sRGB for the Preview window.

On the other hand the pasting operation in Pencil2D could be expecting only screen color space, sRGB image data. So more than a bug, from what I can see Pencil2D could consider implementing a color space conversion system for pasted images to avoid potential issues like these in the future, but that's about it. I don't think this is actually a bug, but rather a limitation of only being able to accept RGB pictures (which makes sense since as an animation program it rarely deals with printing)

I'd like to test this hypothesis a bit more so I'll look into testing out a few CMYK pictures I have, however If it's possible please share at least one of the failing images you tested out so we can at least replicate the problem.

John-Hollingum commented 2 years ago

I agree it's not a bug although it might be nice if Pencil2d could detect the presence of CMYK data and just say something like 'can't paste CMYK data, convert to RGB'. Some people may figure out how to fix it, and if there is a reportable message it helps everyone.

MrStevns commented 2 years ago

I have been able to reproduce the problem with Affinity Designer, since I don't have Affinity Photo. I followed as @John-Hollingum wrote above, change the color format to cmyk and color profile to U.S Web Coated (SWOP) v2

Unfortunately we're bound by what Qt provides here and they don't give us much. In this case, when I check the data we get, it's all null, so there's nothing to check. We therefore cannot say anything either about why it won't paste. We could however show a dialog that for unknown reasons we can't paste the content.

I have tried all the various data types we can get from qmimedata which resides in the clipboard but none of them returns anything...

At this point i'm not sure there's anything we can do except make a bug report or feature request to Qt.

MrStevns commented 2 years ago

I looked at bit more info it this morning together with @scribblemaniac, I think it's safe to assume that whatever Affinity is doing when they copy to the clipboard, it's not compatible with the standard clipboard features. I tried to copy the CMYK formatted image into Clip Studio Paint and the result is the same, nothing is pasted.

I also copied a cmyk tiff image from CSP and pasted that successfully into Pencil2D

In the end we can't do much except show a dialog where it says "ERROR: We were not able to paste from the clipboard, unknown data".

Jose-Moreno commented 1 year ago

Bumping this again. I ended up searching a bit more about this issue it seems the Affinity forums have a plethora of threads regarding Deigner's & Photo's inability to copy / paste to other apps.

Then I found this https://forum.affinity.serif.com/index.php?/topic/29343-copy-and-pasting-to-other-applications/#comment-146437

_"Designer uses SVG version 1.1 XML formatted text for this."_

After digging a bit more I found the app manual and It seems Designer has a functionality to enable Copy items as SVG, which should hopefully allow pasting into Pencil2D considering we can copy / paste form Inkscape directly and Pencil2D does rasterize it.

https://affinity.help/designer2/en-US.lproj/index.html?page=pages/ObjectControl/copyPasteOptions.html?title=Copying%20and%20pasting%20objects

"The Copy items as SVG preference (accessed via Preferences>General) copies objects in SVG format in readiness for pasting to external apps."

As for Affinity Photo, there is an identical preference for vector objects and it is assumed that raster graphics (PNG and other intermediate formats) are in fact capable of being sent to clipboard form their end.

https://affinity.help/photo2/English.lproj/index.html?page=pages/LayerOperations/copyPasteOptions.html?title=Copying%20and%20pasting%20content

I do not have these apps to test, but if anyone sees and has access to the most recent versions of the software please try performing the following tests:

With default configuration

  1. Copy & Paste Vector objects from Affinity Designer & Photo to a text file.
  2. Copy & Paste Raster images from Affinity Designer & Photo to a text file.
  3. Copy & paste from Affinity products (2.2 and above) to Pencil2D

With the "Copy items as SVG" configuration enabled

  1. Copy & Paste Vector objects from Affinity Designer & Photo to a text file.
  2. Copy & Paste Raster images from Affinity Designer & Photo to a text file.
  3. Copy & paste from Affinity products (2.2 and above) to Pencil2D