Page 1 of 1

Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Sat Nov 21, 2020 8:06 pm
by peterbaumann
I'm working with some grids for lockdown-style music videos which have been created in Affinity Designer at 4k resolution. I've found that most of rescaling filters in Resolve don't work well for these pngs, resulting in black/white outlines or an embossed look around the gridlines. From my tests, nearest neighbour/bilinear can give ok results, but anything with angled lines looks horribly jagged as demonstrated by the video below. Oddly, the left-to-right diagonal line seems to be more of an issue for the scaler than the top-to-bottom line.



I know that as a temporary workaround I can rescale the grids in Affinity to 1080p to remove the jagged edges (presumably as Resolve isn't having to scale the images anymore), but is there any way to improve scaled PNGs in Resolve natively? Logos in particular can be particularly troublesome to work with in Resolve (either producing similarly jagged edges or blotchy edges) and it's a pain to have to take everything into a third party app to adjust before bringing them back into Resolve.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Sun Nov 22, 2020 12:14 am
by Dmytro Shijan
There are a lot of new (almost hidden) Image Scaling Options in Resolve 17. To see that list you need switch Resize filter to "Custom". Try them...

Image

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Sun Nov 22, 2020 12:35 am
by Dmytro Shijan
Another option - try change Alpha mode in Clip Attributes.
Seems Resolve can't smoothly downscale edges in transparent images.
Screen Shot 2020-11-22 at 2.31.14 AM.jpg
Screen Shot 2020-11-22 at 2.31.14 AM.jpg (33.52 KiB) Viewed 3223 times

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Nov 23, 2020 12:08 pm
by peterbaumann
Unfortunately the alpha mode didn't seem to make any difference (apart from 'None' and 'Invert' which don't work for this kind of thing).

I cycled through the scaling options using the Inspector panel on the right so it's per-clip and Nearest Neighbour was probably the best, but as is shown in the original video it's still noticeably worse than a 1080p png on a 1080p timeline. Almost all the other options add weird black/white lines or emboss-style effects to the boxes if I use those so I'm pretty much stuck with downscaling externally for now.

Anyone from Blackmagic able to confirm that this is the only solution at the moment?

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Nov 23, 2020 12:38 pm
by Hendrik Proosa
Do not use sharpening filters on plain color graphics. Sharpen effect comes from specific filtering kernel and inevitably will produce a high-contrast edge that you see. Cubic, gaussian, quadratic and linear should be safe (if they are mucked up it is imho a bug). Lanczos and Sinc are sharpening filters, nearest neighbor can create aliasing artifacts. Mitchell is somewhat between softening and sharpening. What Box, Bessel and Catmull-Rom do, I don't know.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Nov 23, 2020 1:05 pm
by peterbaumann
Thanks for the explanation, very helpful. I've uploaded another video with all of the filters for comparison. I don't think any of the 4k grids downscaled in Resolve are usable to be honest (these are with the Alpha mode set to Straight).


Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Nov 23, 2020 3:15 pm
by Hendrik Proosa
What color management are you using by the way? This kind of artifacts can creep out when filtering is done on nonlinear values, because it can produce a mismatch between rgb channels and associated alpha. To put it bluntly, any operations done with alpha on nonlinear values produces errors, how noticeable it is, depends on exact color handling.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Nov 23, 2020 3:34 pm
by peterbaumann
Davinci YRGB, which I think is the default one? Don't think I've changed it since downloading the DR17 Beta and creating a test database.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Wed Nov 25, 2020 11:45 am
by peterbaumann
Anyone know if the downscaling issue is 'expected behaviour' or whether it's a bug/something wrong in the settings?

I've uploaded an archive of the project here if anyone wants to test on their system: https://drive.google.com/drive/folders/10lJNk6PlMCIA07CrosOjM4_1DG_IwTXc?usp=sharing

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Sat Dec 05, 2020 10:45 pm
by Florian Gintenreiter
I ran into the same problem with PNG logo graphics. The same issue plagued some Resolve 15 Betas back in 2018. I wrote a forum post about the same thing then. It seems to be back and I'm having the issue on Resolve Beta 3.

https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=74766

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Thu Dec 31, 2020 10:52 am
by Stefano Marconcini
The problem still there on beta 6.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Thu Dec 31, 2020 11:08 pm
by richards
peterbaumann wrote:Anyone know if the downscaling issue is 'expected behaviour' or whether it's a bug/something wrong in the settings?
Stefano Marconcini wrote:The problem still there on beta 6.
I've just done some exhaustive tests of Resolve's alpha compositing of PNGs, and my conclusion is that Resolve is handling alpha and filtering correctly in most situations. The only situation I've found that it is doing the wrong thing is, oddly enough, when playback is paused and filtering is set to a non-trivial mode (e.g. Sharper, Smoother, etc; Bilinear, Nearest Neighbour, etc are unaffected by this). But even in those cases, as soon as playback is started the alpha filtering is displayed correctly.

I believe the problem people are seeing is the unfortunately non-intuitive behaviour of alpha compositing. For something that almost everybody (and I constantly get tripped up by too despite 'knowing' better, now) believes should be/is a trivial thing, it's actually surprisingly hard to get right. It goes back to how the source images are made - not how Resolve is handling them. The short answer is the mysterious "Premultiplied" alpha mode is the best way to get the results you intuitivly expect, except the use of premultiplied alpha is complex/poorly supported/quite unintuitive itself. Premultiplied alpha was specifically invented (well, technically it's the mathematically correct compositing operation, so invented isn't the right word - maybe discovered) for compositing.

A good introduction and overview is this article: https://limnu.com/premultiplied-alpha-primer-artists/

If anyone wants to read the source material for this, the research paper (Compositing Digital Images, Porter & Duff, Lucasfilm, 1984) is still available from Pixar: https://graphics.pixar.com/library/Compositing/

*edit: Re-reading this, it comes off a bit... holier than thou. Not my intent. To give a concrete explanation back to the original posters question about PNG files coming from Affinity Designer, the very last bullet point in the article I linked is the key to it all: "PNG images are always stored unmasked (unpremultiplied)". What that means is that Affinity Designer has to store something in the PNG's transparent areas - but you haven't put anything in those areas, they're transparent after all! If you dig into Affinity Designer's Export > PNG > More... there's a Matte colour. It seems a little broken (the default "transparent swatch" shows up as RGB 255,0,0, but it's actually using transparent black), but if you change it to a colour, it'll use that in all the transparent areas of the PNG. The default transparent black is correct however, so just leave it as that. The good news is that, using transparent black is the correct thing for "Premultiplied" alpha! But bad news is, it's not the default "Straight" alpha.

So if the default is correct, why isn't Premultiplied working? Tough to answer without having the source Affinity Designer file and PNG's to check.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Thu Dec 31, 2020 11:33 pm
by Stefano Marconcini
Thank you Richard, but into Fusion all works good.

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Fri Jan 01, 2021 2:19 am
by richards
I got ahead of myself when I said that Resolve seems to be handling alpha compositing correctly - I'd only tested Straight alpha, but it appears that Premultiplied is pretty much unusably broken. I have to do more testing, but right now it just doesn't act right at all in my tests, and when it's used the Composite Mode of clips in the timeline appears to be ignored.

Stefano Marconcini wrote:Thank you Richard, but into Fusion all works good.
It might be something about where Fusion comps sit in the data flow in Resolve compared to where Timelines/clips are composited. I'll add it to my list of things to try soon. First, figuring out what's up with Premultiplied...

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Mon Jan 04, 2021 10:54 pm
by Stefano Marconcini
Thank you.


Inviato dal mio iPhone utilizzando Tapatalk

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Tue Jan 05, 2021 12:30 am
by richards
I forgot to post an update to this saga - it turns out a lot of my testing has been invalidated by a caching bug in Resolve unfortunately. Despite having the Render Cache set to None, Resolve is caching the "result" of the image somewhere, and would not update that cached version even if I removed the image from both the timeline and the project's Media entirely. No wonder I was seeing such odd and unpredictable results!

The only reliable workaround for the caching that I've found so far was to change the length of the image's clip in the timeline, which does appear to force a refresh of the cached version.

The bad news is that even with that workaround, Premultiplied alpha isn't handled correctly. It's certainly more correct than I'd seen in my last test, but it'll still result in black fringes due to the incorrect Compositing Mode being used. You can choose different Compositing Modes (thanks bug...), but none of them are what's actually needed for Premultiplied. The modes at the end of the list (Foreground, Alpha, etc) don't seem to do anything; I was hoping that one of those would be a poorly named, but correct, mode, and maybe they're supposed to be if they worked.

I haven't re-tested Straight alpha, mainly because it'll never give correct downsampling so will always have fringes (see my first post about the math).

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Tue Jan 05, 2021 12:52 am
by richards
Here's a project that demonstrates the issue with Premultiplied alpha - or more specifically, the incorrect Compositing Mode that it uses (because the correct one doesn't exist). Resolve team, please add the required [One, InvSrcAlpha] Composite Mode!

One note about the project: I used a TIFF image rather than a PNG, because the PNG format explicitly does not support premultiplied alpha, whereas the TIFF format does. It's a major pain in the ass to generate correct Premultiplied content...

The resulting black fringes:
AlphaBlendingTest-01.png
AlphaBlendingTest-01.png (5.54 KiB) Viewed 2828 times


AlphaBlendingTest-01.dra.zip
(512.24 KiB) Downloaded 111 times

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Tue Jan 05, 2021 12:50 pm
by peterbaumann
Thanks for running all these tests, @richards.

Fingers crossed BM are looking into this and can add it to an upcoming beta release!

Re: Horrible downscaling of PNG grids in DR17 Beta 1

PostPosted: Sun Feb 07, 2021 12:14 pm
by peterbaumann
At first glance, it seems this has been fixed in beta 8. Thanks BM.

I've re-rendered the test video in Beta 8 here: