View Single Post
Old 19th July 2013, 15:32   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Okey Dokey. I'll keep the 99 limit and implement rgb limiting. Will be implemented for both RGB32 and RGB24.
Incidentally for future reference, RT_RgbChanAve will be marginally faster than RT_RgbChanMedian for single pixel, same result.

This as you envisaged ?
Code:
Function RgbAmplifier (clip clip, int "Radius", float "Multiplier",int "Rmin",int "GMin",int "Bmin",int "RMax",int "GMax",int "BMax") {
    # Radius==1, switches OFF averaging, Radius==2 = Diameter of 3 frames
    myName="RgbAmplifier: "
    Radius=Default(Radius,2) Multiplier=Float(Default(Multiplier,2.0))
    RMin=Default(RMin,0) GMin=Default(GMin,0) BMin=Default(BMin,0) RMax=Default(RMax,255) GMax=Default(GMax,255) BMax=Default(BMax,255)
    Assert(Radius>=1 && Radius <= 99,"RgbAmplifier: Radius range 1->99 ("+String(Radius)+")")
    Assert(Multiplier>=0.0 && Multiplier<=10.0,"RgbAmplifier: 0.0 <= Multiplier <= 10.0  ("+String(Multiplier)+")")
    Assert(RMin<=255&&RMin>=0,myName+"RMin range 0 -> 255 ("+String(RMin)+")")
    Assert(GMin<=255&&GMin>=0,myName+"GMin range 0 -> 255 ("+String(GMin)+")")
    Assert(BMin<=255&&BMin>=0,myName+"BMin range 0 -> 255 ("+String(BMin)+")")
    Assert(RMax<=255&&RMax>=RMin,myName+"RMax range RMin -> 255 ("+String(RMax)+")")
    Assert(GMax<=255&&GMax>=GMin,myName+"GMax range GMin -> 255 ("+String(GMax)+")")
    Assert(BMax<=255&&BMax>=BMin,myName+"BMax range BMin -> 255 ("+String(BMax)+")")
    GScript("""
        WW=clip.Width() HH=clip.Height() FC=clip.Framecount()
        clipfinal=0
        for(i=0,FC-1) {
#           RT_Debug("Frame="+String(i))
            clip2=clip.trim(i,-1)
            rangemin = Max(i-(Radius-1),0)
            rangemax = Min(i+(Radius-1),FC-1)
            diameter = rangemax - rangemin + 1
            for(y=0,HH-1) {
                for(x=0,WW-1) {
                    red=0       green=0     blue=0
                    redavg=0    greenavg=0  blueavg=0
                    for(j=rangemin,rangemax){
                        col = clip.RT_RGB32AsInt(n=j, x=x, y=y)
                        b=RT_BitAND(col,$FF)    col=RT_BitLSR(col,8)
                        g=RT_BitAND(col,$FF)    col=RT_BitLSR(col,8)
                        r=RT_BitAND(col,$FF)
                        redavg      = redavg    + r
                        greenavg    = greenavg  + g
                        blueavg     = blueavg   + b
                        if(j==i) {
                            red     =   r
                            green   =   g
                            blue    =   b
                        }
                    }
                    if(r>=RMin&&r<=RMax && g>=GMin&&g<=GMax && b>=BMin&&b<=BMax) {
                        redavg = Float(redavg) / diameter
                        newred = Round(redavg + (Multiplier * ( red - redavg)))
                        newred = Max(Min(newred,255),0)
                        ###
                        greenavg = Float(greenavg) / diameter
						newgreen = Round(greenavg + (Multiplier * ( green - greenavg)))
                        newgreen = Max(Min(newgreen,255),0)
                        ###
                        blueavg = Float(blueavg) / diameter
						newblue = Round(blueavg + (Multiplier * ( blue - blueavg)))
                        newblue = Max(Min(newblue,255),0)
                        ###
                        clip2=clip2.Layer(clip2.BlankClip(pixel_type="RGB32", color=(newred*256+newgreen)*256+newblue)
                            \ .crop(0,0,1,1), x=x, y=y, level=257)
                    }
                }
            }
            clipfinal=(clipfinal.IsClip()) ? clipfinal++clip2 : clip2
        }
        return clipfinal
    """)
}

Avisource("D:\avs\test.avi").ConvertToRGB32()
trim(1000,-20)
crop(32,32,32,32)
A=RgbAmplifier(2,2.0)
StackHorizontal(A)
EDIT: Fixed color shift, convert to Gavino mod.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 24th July 2013 at 12:46.
StainlessS is offline   Reply With Quote