Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 28th January 2017, 21:49   #2921  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 792
Bug in overlay?

Code:
background = blankclip(width=400,height=400,length=1,pixel_type="y8").mt_lut("255")

box = blankclip(width=100,height=100,length=1,pixel_type="y8").mt_lut("0")

mask = box.mt_lut("255")

#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 0
overlay(background, box, x=150, y=150)             # black box value is 1

scriptclip("""
subtitle(string(yplanemax)+"\n"+string(yplanemin),lsp=0)
""")
Also when reversing the black and white, using a "maximum" mask (instead of no mask) results in a white box balue of 254 instead of 255.

Last edited by ajp_anton; 28th January 2017 at 21:51.
ajp_anton is offline  
Old 28th January 2017, 23:04   #2922  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,158
Quote:
Originally Posted by ajp_anton View Post
Bug in overlay?

Code:
background = blankclip(width=400,height=400,length=1,pixel_type="y8").mt_lut("255")

box = blankclip(width=100,height=100,length=1,pixel_type="y8").mt_lut("0")

mask = box.mt_lut("255")

#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 0
overlay(background, box, x=150, y=150)             # black box value is 1

scriptclip("""
subtitle(string(yplanemax)+"\n"+string(yplanemin),lsp=0)
""")
Also when reversing the black and white, using a "maximum" mask (instead of no mask) results in a white box balue of 254 instead of 255.
I think this is known thing, even in masktools https://github.com/tp7/masktools/issues/12

edit: in original avisynth

Code:
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 1
overlay(background, box, x=150, y=150)             # black box value is 0
and there are another thing, if I overlay 2 rgb32 then I get all alpha in zero in normal avs, but in last avs+ it all 255
__________________
See My Avisynth Stuff

Last edited by real.finder; 28th January 2017 at 23:20.
real.finder is offline  
Old 29th January 2017, 09:52   #2923  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
The original blending formula is something like that, where an ideal mask is 0..1.0:
new_value = orig*(1-mask) + overlay*mask

This is equivalent to (only one multiplication, faster):
new_value = orig+(overlay-orig)*mask

As mask is coming from a clip, its value is 0..255

The approximation in overlay core:
new_value = ((orig * 256 + 128)+(overlay-orig)*mask) / 256

When orig=255, overlay=0, mask=255 (overlay is fully visible), we would expect 0 (=overlay)

Unfortunately the approximation above results in:

new_value = ((orig * 256 + 128)+(overlay-orig)*mask) / 256:
(255*256+128) + (0-255)*255) / 256 = 383/256 =
(65408 - 65025) / 256 =
383/256 = 1
which is obviously incorrect

For orig=0, overlay=255, mask=255 the result is 254 instead of 255.
pinterf is offline  
Old 29th January 2017, 11:04   #2924  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 792
So can it be fixed? I guess it's a bit complicated if you need
0 -> 0%
128 -> 50%
255 -> 100%
Do you need two separate linear scales on both sides of 128, a non-linear scale, or a special case for 255? Or treat both 0 and 1 as 0%?
ajp_anton is offline  
Old 29th January 2017, 14:30   #2925  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,158
Quote:
Originally Posted by ajp_anton View Post
So can it be fixed? I guess it's a bit complicated if you need
0 -> 0%
128 -> 50%
255 -> 100%
Do you need two separate linear scales on both sides of 128, a non-linear scale, or a special case for 255? Or treat both 0 and 1 as 0%?
in 16 bit you will get better result, and I think there is no problem at all in float point

but if you need it in 8 bit there are RMerge with mode=256

@pinterf
but there are difference between normal avs and avs+ like I mention
__________________
See My Avisynth Stuff

Last edited by real.finder; 29th January 2017 at 14:38.
real.finder is offline  
Old 29th January 2017, 16:58   #2926  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 792
Quote:
Originally Posted by real.finder View Post
in 16 bit you will get better result, and I think there is no problem at all in float point

but if you need it in 8 bit there are RMerge with mode=256

@pinterf
but there are difference between normal avs and avs+ like I mention
That's not a solution, it's a workaround. RMerge doesn't have arguments for x and y offsets, so that's not even a workaround. Float probably works while 16 bit still has this problem (though it's less noticeable).
ajp_anton is offline  
Old 29th January 2017, 18:01   #2927  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by real.finder View Post
and there are another thing, if I overlay 2 rgb32 then I get all alpha in zero in normal avs, but in last avs+ it all 255
What is the use case when you rely on having the output alpha is filled by zeros?

On the other hand in classic avisynth the alpha channel of an RGB32 after an Overlay is undefined.
At least after having a quick look at the source, it is not filled up by any defaults. There is always an RGB->444->RGB conversion sequence, and the final conversion back from internal 444 to rgb32 fills only r, g and b channels.

Avisynth+ Overlay may use ConvertToRGB32 (which fills up alpha with 255; full transparency).
Or it just simply preserves source clip's alpha info if it works in conversionless mode (no RGB->444->RGB conversion, blend works in RGB natively)
pinterf is offline  
Old 29th January 2017, 18:05   #2928  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by ajp_anton View Post
So can it be fixed? I guess it's a bit complicated if you need
0 -> 0%
128 -> 50%
255 -> 100%
Do you need two separate linear scales on both sides of 128, a non-linear scale, or a special case for 255? Or treat both 0 and 1 as 0%?
Mask value of 255 (and in general the maximum pixel value for a given bit depth) is definitely a special case that we have to handle.
It really should work as maximum transparency.
Much more special, I think than 128 / 50%
pinterf is offline  
Old 29th January 2017, 23:30   #2929  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,158
Quote:
Originally Posted by pinterf View Post
What is the use case when you rely on having the output alpha is filled by zeros?

On the other hand in classic avisynth the alpha channel of an RGB32 after an Overlay is undefined.
At least after having a quick look at the source, it is not filled up by any defaults. There is always an RGB->444->RGB conversion sequence, and the final conversion back from internal 444 to rgb32 fills only r, g and b channels.

Avisynth+ Overlay may use ConvertToRGB32 (which fills up alpha with 255; full transparency).
Or it just simply preserves source clip's alpha info if it works in conversionless mode (no RGB->444->RGB conversion, blend works in RGB natively)
Code:
background = blankclip(width=400,height=400,length=1, color=$FFFFFF,pixel_type="rgb32")

box = blankclip(width=100,height=100,length=1,pixel_type="rgb32")

overlay(background, box, x=150, y=150)
you can test it with mask too, but anyway it's not important

but I say something else

here in avs+ as ajp_anton say

Code:
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 0
overlay(background, box, x=150, y=150)             # black box value is 1

and here what I get with normal avs

Code:
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 1
overlay(background, box, x=150, y=150)             # black box value is 0
edit and here another test without mask in normal avs

Code:
overlay(background.invert, box.invert, x=150, y=150)             #white box value is 255, background is 0
__________________
See My Avisynth Stuff

Last edited by real.finder; 29th January 2017 at 23:39.
real.finder is offline  
Old 30th January 2017, 05:45   #2930  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,158
let's back to grun
Code:
SetFilterMTMode("GScriptClip", 3)
SetFilterMTMode("RequestLinear", 1) #or 3, mode 2 will make avs+ freeze and not respond (with real clip not ColorBars, ColorBars seems ok even with RequestLinear in mode 2 here)
ColorBars(width=640, height=480, pixel_type="yv12").AddGrainC(10000, 10000, seed=1)
#~ srestore() #seems ok
admfilter() #show error on screen
Prefetch(6)
__________________
See My Avisynth Stuff

Last edited by real.finder; 30th January 2017 at 10:16.
real.finder is offline  
Old 30th January 2017, 11:12   #2931  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by real.finder View Post

here in avs+ as ajp_anton say

Code:
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 0
overlay(background, box, x=150, y=150)             # black box value is 1
and here what I get with normal avs

Code:
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 1
overlay(background, box, x=150, y=150)             # black box value is 0
I think ajp_anton exchanged the comments of 0 and 1 values

My experience is:
Code:
background = blankclip(width=400,height=400,length=1,pixel_type="y8").mt_lut("255")
box = blankclip(width=100,height=100,length=1,pixel_type="y8").mt_lut("0")
mask = box.mt_lut("255")
#overlay(background, box, x=150, y=150, mask=mask)  # black box value is 1
overlay(background, box, x=150, y=150)             # black box value is 0

scriptclip("""
subtitle(string(yplanemax)+"\n"+string(yplanemin),lsp=0)
""")
return last
pinterf is offline  
Old 30th January 2017, 11:13   #2932  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 792
Yes, sorry, looks like I got the 0 and 1 wrong there.

How is 8(or higher)bit to float handled? Shouldn't it also be
0 -> .0
128 -> .5
255 -> 1.0 ?
Using "averageluma", 128 is converted to 0.501961 (128/255).
Using "yplanemax"/"-min", 128 is converted to 32896 (is this a bug? should be a float number, not a 16bit int)

Also, y=128 in 8bit -> float is different from 8bit -> 16bit -> float.

Last edited by ajp_anton; 30th January 2017 at 11:16.
ajp_anton is offline  
Old 30th January 2017, 11:20   #2933  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by real.finder View Post
let's back to grun
Code:
SetFilterMTMode("GScriptClip", 3)
SetFilterMTMode("RequestLinear", 1) #or 3, mode 2 will make avs+ freeze and not respond (with real clip not ColorBars, ColorBars seems ok even with RequestLinear in mode 2 here)
ColorBars(width=640, height=480, pixel_type="yv12").AddGrainC(10000, 10000, seed=1)
#~ srestore() #seems ok
admfilter() #show error on screen
Prefetch(6)
I have not continued the investigation on grunt freeze, I have spent three day on it in December, and it is still beyond my knowledge, I am not an avisynth expert. All I have seen that it gets deadlocked on an internal mutex. Scriptclip invoke runs under a different thread id and sometimes that conflicts with the internal cache mechanism. The problem can occur when a runtime function e.g. YPlaneMin requests the child frame and that frame should retreived from the cache. So I put aside this problem a bit until I have more time/knowledge on the topic.
pinterf is offline  
Old 30th January 2017, 14:36   #2934  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,899
When i'm creating an ouput like this :
Code:
PVideoFrame dst = env->NewVideoFrame(vi);
Is there something i can do to force an alignment value ?
(If i want aligned on 32 or 64 bits for exemple)
jpsdr is offline  
Old 30th January 2017, 16:34   #2935  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by jpsdr View Post
When i'm creating an ouput like this :
Code:
PVideoFrame dst = env->NewVideoFrame(vi);
Is there something i can do to force an alignment value ?
(If i want aligned on 32 or 64 bits for exemple)
Code:
PVideoFrame dst = env->NewVideoFrame(vi, 64);
pinterf is offline  
Old 30th January 2017, 17:33   #2936  |  Link
jpsdr
Registered User
 
Join Date: Oct 2002
Location: France
Posts: 1,899
Easy, lol ! Thanks.
Euh... Of course, i wanted to say 32 or 64 bytes... (YMM registers.... )
jpsdr is offline  
Old 30th January 2017, 17:38   #2937  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Avs+ default is 32
pinterf is offline  
Old 30th January 2017, 23:01   #2938  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,158
Quote:
Originally Posted by ajp_anton View Post
Yes, sorry, looks like I got the 0 and 1 wrong there.

How is 8(or higher)bit to float handled? Shouldn't it also be
0 -> .0
128 -> .5
255 -> 1.0 ?
Using "averageluma", 128 is converted to 0.501961 (128/255).
Using "yplanemax"/"-min", 128 is converted to 32896 (is this a bug? should be a float number, not a 16bit int)

Also, y=128 in 8bit -> float is different from 8bit -> 16bit -> float.
yes, I think there are bugs in Runtime Functions, AverageChromaU and AverageChromaV in float too
__________________
See My Avisynth Stuff
real.finder is offline  
Old 31st January 2017, 02:39   #2939  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
For now, what plugins support the new 16-bit format? RgTools; anything else?
MysteryX is offline  
Old 31st January 2017, 02:53   #2940  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,191
Quote:
Originally Posted by MysteryX View Post
For now, what plugins support the new 16-bit format? RgTools; anything else?
RgTools, Average, NNEDI3, DCTFilter, YadifMod2, FFMS2, RawSourcePlus, VapourSource, AVSResize, FQPlus, ModPlus, and MovePlus all support 10-16 bit and 32 bit float.

Edit: also pinterf's MVTools, MDepan, and DepanEstimate support 10-16 bit.

There's also VirtualDubFilterMod, avs2pipemod, and Avs2Yuv which support some of the new HBD colorspaces.

Last edited by Reel.Deel; 31st January 2017 at 20:33. Reason: add ffms2
Reel.Deel is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.