reb
Class REB_ConvolutionWrapper

Object
  extended by common:Generic
      extended by common:ColorTrap
          extended by reb:REB_ConvolutionWrapper

class 
ColorTrap:REB_ConvolutionWrapper

This wrapper allows you to use any color trap and any convolution filter to produce blurred or sharpened (or other) trap effects. This is largely based upon BlurTrapWrapper of Damien Jones and modified to work with Image Traps, Exponential Smoothing (REB version), Fiber and Things, and Lighting with Textures Direct.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_ConvolutionWrapper(common.ulb:ColorTrap) {
   ; This wrapper allows you to use any color trap and any convolution
   ; filter to produce blurred or sharpened (or other) trap effects.
   ; This is largely based upon BlurTrapWrapper of Damien Jones and modified
   ; to work with Image Traps, Exponential Smoothing (REB version), Fiber and
   ; Things, and Lighting with Textures Direct.
 public:
   import "common.ulb"
   import "dmj5.ulb"
   
   func REB_ConvolutionWrapper(Generic pparent)
     ColorTrap.ColorTrap(pparent)
 
     m_Filter = new @f_filter(this)
     m_Samples = length(m_Filter.m_Offsets)
     setLength(m_TrapShapes, m_Samples)
     int j = 0
     while (j < m_Samples)
       m_TrapShapes[j] = new @f_trapshape(this)
       j = j + 1
     endwhile
   endfunc
   
   func Init(complex pz)
     ColorTrap.Init(pz)
 
     int j = 0
     while (j < m_Samples)
       m_TrapShapes[j].Init(pz)
       j = j + 1
     endwhile
     if (@p_filterreset == 0 && DMJ_VariableConvolutionFilter(m_Filter) != 0)
       m_Filter.Init(pz)
     endif
   endfunc
 
   color func Iterate(complex pz)
     ColorTrap.Iterate(pz)
     color return_color = rgba(0,0,0,0)
     if (@p_filterreset == 1 && DMJ_VariableConvolutionFilter(m_Filter) != 0)
       m_Filter.Init(pz)
     endif
 
     float r = 0.0
     float g = 0.0
     float b = 0.0
     float a = 0.0
     float w = 0
     float o = 0
     float g = 0
     color c = rgba(0,0,0,0)
     
     int j = 0
     while (j < m_Samples)
       c = m_TrapShapes[j].Iterate(pz+m_Filter.m_Offsets[j])
       if @v_REB_ConvolutionWrapper >= 101
         float br = (0.5-@p_bright)*2
         int sign = 0
         if br < 0
           sign = -1
         else
           sign = 1
         endif
         br = br^2*sign
         float cr = (@p_contrast-0.5)*2
         if cr < 0
           sign = -1
         else
           sign = 1
         endif
         cr = cr^2*sign+1
         float st = (0.5-@p_sat)*2
         if st < 0
           sign = -1
         else
           sign = 1
         endif
         st = st^2*sign*2
         float hu = @p_hue*6
         float rd = red(c)-br
         float gr = green(c)-br
         float bl = blue(c)-br
         if rd > 1
           rd = 1
         endif
         if gr > 1
           gr = 1
         endif
         if bl > 1
           bl = 1
         endif
         if rd < 0
           rd = 0
         endif
         if gr < 0
           gr = 0
         endif
         if bl < 0
           bl = 0
         endif
         c = rgba(rd,gr,bl,alpha(c))
         rd = red(c)^cr
         gr = green(c)^cr
         bl = blue(c)^cr
         c = rgba(rd,gr,bl,alpha(c))
         float satval = sat(c)-st
         if satval > 1
           satval = 1
         endif
         if satval < 0
           satval = 0
         endif
         c = hsla(hue(c), satval, lum(c), alpha(c))
         float hueval = (hue(c)+hu) % 6
         c = hsla(hueval, sat(c), lum(c), alpha(c))
       endif
       if @p_poster
         float rd = floor(red(c)*@p_chan)/@p_chan + 0.5/@p_chan
         float gr = floor(green(c)*@p_chan)/@p_chan + 0.5/@p_chan
         float bl = floor(blue(c)*@p_chan)/@p_chan  + 0.5/@p_chan
         c = rgba(rd,gr,bl,alpha(c))
       endif
       if @p_gscale
          float gry = 0.3 * red(c)+ 0.59 * green(c) + 0.11 * blue(c)
          c = rgba(gry,gry,gry,alpha(c))
       endif
       if @p_solar
         float rd = red(c)
         float gr = green(c)
         float bl = blue(c)
         if rd > @p_thresh
           rd = 1-rd
         endif
         if gr > @p_thresh
           gr = 1-gr
         endif
         if bl > @p_thresh
           bl = 1-bl
         endif
         c = rgba(rd,gr,bl,alpha(c))
       endif
       if @p_bw
         float gry = 0.3 * red(c)+ 0.59 * green(c) + 0.11 * blue(c)
         if gry < @p_bwt
           c = rgba(0,0,0,alpha(c))
         else
           c = rgba(1,1,1,alpha(c))
         endif
       endif
       
       w = m_Filter.m_Weights[j]
        r = r + red(c) * w
        g = g + green(c) * w
        b = b + blue(c) * w
        if @p_alpha
          a = a + alpha(c) * w
        endif
       j = j + 1
     endwhile
     w = m_Filter.m_Multiplier
     o = m_Filter.m_Bias
     r = r * w + o
     g = g * w + o
     b = b * w + o
     if @p_alpha
       a = a * w + o
       return_color = rgba(r,g,b,a)
     else
       return_color = rgb(r,g,b)
     endif    
     return return_color
   endfunc
 
 
 protected:
   DMJ_ConvolutionFilter m_Filter
   int m_Samples
   ColorTrap m_TrapShapes[]
   float sortred[100]
   float sortgreen[100]
   float sortblue[100]
 
 default:
   title = "Convolution Color Wrapper"
   
   int param v_REB_ConvolutionWrapper
     caption = "Version (REB_ConvolutionWrapper)"
     default = 101
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_REB_ConvolutionWrapper < 101
   endparam
 
   ColorTrap param f_trapshape
     caption = "Trap Shape"
     default = ColorTrapShapeBlock
     hint = "Sets the trap shape that the convolution filter will be applied to."
   endparam
   DMJ_ConvolutionFilter param f_filter
     caption = "Convolution Filter"
     default = REB_NullFilter
     hint = "Sets the filter that will be applied."
   endparam
   int param p_filterreset
     caption = "Reset Filter"
     default = 1
     enum = "first iteration" "every iteration"
     hint = "Some convolution filters are position-dependent: the filter's effect varies from one part of the complex plane to another. For this kind of filter, you may choose whether to recompute the filter's effect only at the first iteration or on every iteration."
     visible = (@f_filter == DMJ_VariableConvolutionFilter)
   endparam
   bool param p_alpha
     caption = "Use alpha values"
     default = false
     visible = @f_filter != REB_NullFilter
   endparam
   heading
     caption = "Special Effects"
   endheading
   float param p_bright
     caption = "Brightness"
     default = 0.5
     min = 0
     max = 1
     visible = @v_REB_ConvolutionWrapper >= 101
   endparam
   float param p_contrast
     caption = "Contrast"
     default = 0.5
     min = 0
     max = 1
     visible = @v_REB_ConvolutionWrapper >= 101
   endparam
   float param p_sat
     caption = "Saturation"
     default = 0.5
     min = 0
     max = 1
     visible = @v_REB_ConvolutionWrapper >= 101
   endparam
   float param p_hue
     caption = "Hue"
     default = 0.0
     min = 0
     max = 1
     visible = @v_REB_ConvolutionWrapper >= 101
   endparam
   bool param p_gscale
     caption = "Grayscale"
     default = false
   endparam
   bool param p_solar
     caption = "Solarize"
     default = false
   endparam
   float param p_thresh
     caption = "Threshold"
     default = 0.5
     visible = @p_solar
   endparam
   bool param p_poster
     caption = "Posterize"
     default = false
   endparam
   int param p_chan
     caption = "Colors per channel"
     default = 4
     min = 2
     visible = @p_poster
   endparam
   bool param p_bw
     caption = "Black and White"
     default = false
   endparam
   float param p_bwt
     caption = "Threshold"
     default = 0.5
     min = 0
     max = 1
     visible = @p_bw
   endparam
 }
 


Constructor Summary
REB_ConvolutionWrapper()
           
REB_ConvolutionWrapper(Generic pparent)
           
 
Method Summary
 void Init(complex pz)
          call this before each sequence of values to be trapped
 color Iterate(complex pz)
          call this to produce a result you should always override this function
 
Methods inherited from class common:ColorTrap
IterateSilent
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_ConvolutionWrapper

public REB_ConvolutionWrapper(Generic pparent)

REB_ConvolutionWrapper

public REB_ConvolutionWrapper()
Method Detail

Init

public void Init(complex pz)
Description copied from class: ColorTrap
call this before each sequence of values to be trapped

Overrides:
Init in class ColorTrap

Iterate

public color Iterate(complex pz)
Description copied from class: ColorTrap
call this to produce a result you should always override this function

Overrides:
Iterate in class ColorTrap