RedAverage

From Avisynth wiki
Jump to: navigation, search
Abstract
Author redfordxx
Version v1.4.3
Download RedAverage___(1.4.3_-_2011-12-02).7z
Category Averaging
License GPL
Discussion Doom9 Thread


Contents

[edit] Description

Averaging plugin, includes these filters:

  • RAverageM - masked average
  • RAverageW - weighted average
  • RMerge - yet another merge filter


[edit] Requirements


[edit] Syntax and Parameters

[edit] RAverageM

Computes value of masked average of clips: result=c1*m1+c2*m2+...cn*mn+bias

RAverageM (clip1, mask1, clip2, mask2, ... clipn,maskn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out")


clip   =
Input clips; clip followed by a mask clip. An even number of clips is required.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing. By default, all planes are processed.
  • 3 : process plane
  • other numbers disable processing


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


[edit] RAverageW

Computes value of weighted average of clips: result=c1*w1+c2*w2+...cn*wn+bias

RAverageW (clip1, weight1, clip2, weight2, ... clipn, weightn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode", int "errlevel", bool "silent")


clip   =
float   =
Input clips and weights; clip followed by a weight. An even number of clips and weights is required.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing. By default, all planes are processed.
  • 3 : process plane
  • other numbers disable processing


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


int  mode = -1
Bitwise 4, 8 for enabling method 4, 8. 0 results in unoptimized C++.
  • mode=8 : requires SSE2, has higher precision than 4 but depending on hardware, probably will be slower
  • mode=4 : requires SSSE3, is faster, however has certain limitations in precision (if you don't have silent true, you will be warned) (8bit in only atm, 8 or 16 out).
Basically method 4 is fully precise, when weights are nice power-of-two-numbers, specifically: w_i=a_i*2^k (a_i are integers and k is integer, all signed... Moreover sum[max(a_i,0)]<128 and sum[min(a_i,0)]>-128
...in other words, weights must be scalable to signed byte;-)
  • mode=0 : plain C++, slow, fully precise (I think) and supports fully 8 & 16bit clips in and out.
Concerning 16bit support and conversion when the in and out have different bitdepth, the values are relative to full scale. That introduces multiplication or division by 256 in case of change of bitdepth. So: 8bitvalue*weight*256=16bitvalue.


int  errlevel = 0
Sets the maximum rounding error you are willing to accept as a tradeoff to faster method.


bool  silent = false
If true, certain error messages (mostly about rounding error) are suppressed.


[edit] RMerge

Merges two clips based on mask, as expected. However, there are some new things. First, again, 16bit support, and 2 different modes.


RMerge(clip1, clip2, mask clip, int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")
RMerge(clip1, clip2, mask clip, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")


clip   =
clip   =
clip   =
Input clips; 2 clips to be merged followed by a mask clip.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing:
  • 1 : do nothing (garbage)
  • 2 : copy plane from first clip
  • 3 : process
  • 4 : copy plane from second clip


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.
  • Only lsb_in=lsb_out=false and mode=255 are SSSE3 optimized. Anything else goes plain C++.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


int  mode = 255
Then there are two modes in case 8bit input which decide, whether the mask is applied slightly differently to correct the problem of incomplete range of the mask:
  • mode=255 ...this is standard merge formula: r=c1*(256-m)+c2*m
  • mode=256 ...this is adjusted merge formula: r=c1*(256-n)+c2*n where n= ( m<=128 ? m : m+(m-128)/128 )
  • lsb_in=true ...this is 16bit merge formula: r=c1*(65536-m)+c2*m
  • Then, r is scaled and rounded to results r8 or r16, depending on output bitdepth.
  • The goal of mode 256 is to allow merge values in full range and if m=255, then r8=c2 ... (...and not r8=(c1+c2*255+128)/256 like usually and in mode 255)


[edit] Examples

TODO

[edit] Changelog

Version      Date            Changes
v1.4.3 2011/12/02 - serious bugfix, thanx to Bloax for pointing out v1.4.2 - bugfix of RMerge SSSE3, switched clips in RMerge to match the mt_merge formula, minor improvements v1.4.1 - SSSE3 optimization of RMerge in 8bit v1.4.0 - introduction of of new filter RMerge v1.3.1 - full 16bit support for RAverageW mode 8 (SSE2) and minor speed improvements v1.3.9 - added 16bit support for RAverageW, however not always SIMD optimized. Multiple algorithms available, different in speed and precision. Thorough estimation of rounding error at the beginning added, so that the most suitable algo is chosen. Ugly source included. v1.3.5 2011/11/20 - something I am not afraid to publish, but I am afraid to publish the messy src


[edit] Archived Downloads

Version Download Mirror
v1.4.3 RedAverage___(1.4.3_-_2011-12-02).7z RedAverage___(1.4.3_-_2011-12-02).7z


[edit] External Links




Back to External Filters


Personal tools