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 Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th April 2020, 17:03   #41  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
HBD update https://github.com/realfinder/AVS-St...Levels_mt.avsi

special thanks for pinterf and StainlessS for float clip support
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 6th March 2021, 12:27   #42  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 124
real.finder, thanks for updating the script.
I am working on the restoration of cartoons. And this script helped me a lot. Didée wrote 4 different scripts: Ylevels - the main one and YlevelsG, YlevelsS, YlevelsC based on it. I collected 4 scripts in 1 and simplified them a bit. Perhaps it will be useful to someone other than me.

Code:
/*
NEEDED PLUGINS: 
  MaskTools2 (v2.2.5 or above)
	https://github.com/pinterf/masktools/releases
	http://avisynth.nl/index.php/MaskTools2/mt_lut

PARAMETERS:
  "input_low"    : (Default: 0)      - The range is not limited.
  "gamma"        : (Default: 1.0)    - The range 0.1 ... 10.
  "input_high"   : (Default: 255)    - The range is not limited.
  "output_low"   : (Default: 0)      - The range is not limited.
  "output_high"  : (Default: 255)    - The range is not limited.
  "mode"         : (Default: "Line") - The function to change of luma.
                                       Mode must be only: "Line", "Grad", "Sin", "Cos"
  "chroma"       : (Default: false)  - Use chroma.

USAGE:
  YLevels(0, 1.2, 255, 0, 255, "Line", false)
  YLevels(0, 1.2, 255)
  YLevels(gamma=1.2)
*/


function YLevels(clip clp, \
                 float "input_low", float "gamma", float "input_high", float "output_low", float "output_high", \
                 string "mode", bool "chroma") {
il     = String(Default(input_low, 0))
gamma  = Default(gamma, 1.0)
ih     = String(Default(input_high, 255))
ol     = String(Default(output_low, 0))
oh     = String(Default(output_high, 255))
mode   = Default(mode, "Line")
chroma = Default(chroma, false)

try { bpc = clp.BitsPerComponent } catch(msg) { bpc = 8 }

chrom = chroma ? "process" : "copy"

gm = String(Min(Max(0.1, gamma), 10.0))

Line = "x "+il+" - "+ih+" "+il+" - / 1 "+gm+" / ^ "+oh+" "+ol+" - * "+ol+" +"
Grad = gamma > 1.0 ? Line+" x * x 255 x - * + 255 /" : Line+" 255 x - * x x * + 255 /"
Sin  = "x x pi * 2 255 * / sin "+Line+" x - * +"
Cos  = Line+" x pi * 2 255 * / cos "+Line+" x - * -"

# Old function
# Sin  = Line+" x 162.33804 / sin 255 * * x 255 x 162.33804 / sin 255 * - * + 255 /"
# Cos  = Line+" 255 x 162.33804 / cos 255 * - * x x 162.33804 / cos 255 * * + 255 /"

# function:
# Line = (((X-'input_low')/('input_high'-'input_low'))^(1/'gamma'))*('output_high'-'output_low')+'output_low'
# Gradient = (gamma>1.0) ? ('Line'*X+X*(255-X))/255 : ('Line'*(255-X)+X*X)/255
# Sine = ('Line'*sin(X/162.97466)*255+X*(255-sin(X/162.97466)*255))/255    simplified  X+('Line'-X)*sin(X*pi/(2*255))
# Cosine = ('Line'*(255-cos(X/162.97466)*255)+X*cos(X/162.97466)*255)/255  simplified  'Line'-('Line'-X)*cos(X*pi/(2*255))
# 2*256/pi = 162.97466  must be  2*255/pi = 162.33804

Ymode = mode == "Line" ? Line : \
                         mode == "Grad" ? Grad : \
                                          mode == "Sin" ? Sin : Cos

mt_lut(clp, expr=Ymode, Y=3, chroma=chrom, scale_inputs=bpc==8?"none":"allf", use_expr=bpc==8?0:2)
}


/*
FlimsYlevels is a modified version of Didee's Ylevels.
It's designed to give washed-out looking video more dynamic range, 
by making the dark bits darker and boosting the bright bits, but 
without clipping either end too much.

FlimsYlevels(amp, prot, chroma) 
amp    - sets the strength, or amplitude, of the effect.
prot   - protection from the clipping (changes the range 0 ... 255).
chroma - use chroma.
*/

Function FlimsYLevels(clip clp, int "amp", int "prot", bool "chroma") {
amp    = String(Default(amp, 10))
prot   = String(Default(prot, 3))
chroma = Default(chroma, false)

try { bpc = clp.BitsPerComponent } catch(msg) { bpc = 8 }

chrom = chroma ? "process" : "copy"

Flims = "x x "+prot+" - pi * 127.5 "+prot+" - / sin "+amp+" * -"
#function    x - 'amp'*sin((x-'prot')*pi/(127.5-'prot'))

mt_lut(clp, expr=Flims, Y=3, chroma=chrom, scale_inputs=bpc==8?"none":"allf", use_expr=bpc==8?0:2)
}
I did a comparison of Levels, Yevels_mt and Yevels. Yevels_mt and Yevels gave the same result. And I got a question:
1. Why do you need "divisor"? I understand that you cannot divide by zero.
Quote:
divisor = (input_high == input_low)? 1: input_high-input_low
2. Why use the "clip" function built into MaskTools2?
Quote:
0 1 clip
3. Why use "scalef" when there is "scale_inputs" in mt_lut?
Quote:
\? "x" + string (input_low) + "scalef -" + string (divisor) + "scalef /"
Examples:



And another question about the YlevelsS and YlevelsC functions.
YlevelsS and YlevelsC ignore the "input_low" parameter. Is this a mistake or not?

Last edited by Arx1meD; 6th March 2021 at 13:08.
Arx1meD is offline   Reply With Quote
Old 6th March 2021, 14:23   #43  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
well, I try not to change how the original function work, divisor if it not in the original then we (me and pinterf and StainlessS) added later since there were some problem in float input scaling

Quote:
Why use "scalef" when there is "scale_inputs" in mt_lut?
scalef should be faster than using scale_inputs
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 6th March 2021, 14:44   #44  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 124
Quote:
Originally Posted by real.finder View Post
scalef should be faster than using scale_inputs
I thought the same and checked the speed of the script with "scalef" and "scale_inputs". There was no time difference.
If use use_expr = 1, then the speed of the script is very slow. If use_expr = 0 or 2 there is no difference.
Arx1meD is offline   Reply With Quote
Old 6th March 2021, 16:24   #45  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
Quote:
Originally Posted by Arx1meD View Post
I thought the same and checked the speed of the script with "scalef" and "scale_inputs". There was no time difference.
If use use_expr = 1, then the speed of the script is very slow. If use_expr = 0 or 2 there is no difference.
well, I am speaking in theory, theoretically scalef/scaleb should be faster than scale_inputs, Of course it must be one of them used not both in same time
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Reply


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 23:10.


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