Jump to content

Median alpha bug


Go to solution Solved by Rick Brewster,

Recommended Posts

Pdn 5.0.7

Running the built-in Noise/Median (default settings) on an object layer with background bgra = 0,0,0,0 changes this to bgra = 1,1,1,1.
It does this for the whole layer regardless of distance from or even presence of an object.

 

Test: Add new layer, use eye dropper to check values, run Median, check values again.

 

It's the change in the alpha that is most annoying as it messes with effects that detect object edges but is visually indiscernible.
Possibly small implications for file sizes too perhaps?

 

I vaguely remember this issue from way back ... (quick search). I mentioned it in my Object Bevel thread in 2016.
Just wondered if it's likely to be looked into?

  • Like 1

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

6 hours ago, Red ochre said:

Test: Add new layer, use eye dropper to check values, run Median, check values again.

 

Repros for me.

  • Upvote 1
Link to comment
Share on other sites

I think this has been an issue ever since the Median effect was added to the app.

 

Unfortunately I don't really understand the code -- I didn't write it, and it's fairly cryptic.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Also worth pointing out that any change to Median will affect any plugin that is using Median. I know @BoltBait has a bunch of these, and I think he even compensates for this issue.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

That said, I think I see what the issue is -- I would just need to find a way to fix it without affecting plugins. And test, somehow, that it doesn't affect the results of Median too much.

 

  • You're a Smart Cookie! 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

48 minutes ago, Rick Brewster said:

That said, I think I see what the issue is -- I would just need to find a way to fix it without affecting plugins.

 

If the code is in rivy/OpenPDN, I can only guess that a conditional within "Apply" is all that is needed to fix median effect. I don't know, but the code itself is fairly cryptic as you said.

Edited by Reptillian

G'MIC Filter Developer

 

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

Link to comment
Share on other sites

Perhaps a simple and ugly 'bodge' after the Median code?... If the bug in the original code is not an easy fix.

 

pseudo code:

if(current pixel == ColorBgra.FromBgra(1,1,1,1)){current pixel = ColorBgra.FromBgra(0,0,0,0);}
dst[x,y] = current pixel;

 

@Rick Brewster Thanks for taking a look at the problem though!... correcting the original code would always be the better option, if possible.

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

No the fix seems like it's just changing,

 

while (b < 255 & bCount < minCount)
{
    bCount += hb[b];
    ++b;
}

 

to

 

while (b < 255 & bCount < minCount)
{
    bCount += hb[b];
    if (bCount < minCount)
    {
        ++b;
    }
}

 

in LocalHistogramEffect::GetPercentile(). (and the same pattern goes for the blocks of code afterward which are responsible for g, r, and a)

 

The old code would always increment b,g,r,a to 1, it could never equal 0, but it seems like that should not happen if bCount was pushed to or past minCount.

 

This method is only used by the Median effect so it won't affect the other LocalHistogramEffects (Outline, Reduce Noise, Surface Blur).

  • Upvote 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

5 hours ago, Rick Brewster said:

Also worth pointing out that any change to Median will affect any plugin that is using Median. I know @BoltBait has a bunch of these, and I think he even compensates for this issue.

 

I don't believe any of my GPU plugins use the Median effect.

 

The only older style plugin that uses it is Oil Paint+ which works just fine if you fix this bug.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...