dmj5
Class DMJ_Colorize

Object
  extended by common:Generic
      extended by common:ColorTransfer
          extended by dmj5:DMJ_Colorize

class 
ColorTransfer:DMJ_Colorize

This applies a variety of color altering effects.


Ultra Fractal Source

Toggle UF Source Code Display

 class DMJ_Colorize(common.ulb:ColorTransfer) {
   ; This applies a variety of color altering effects.
 
 public:
   import "common.ulb"
 
   func DMJ_Colorize(Generic pparent)
     ColorTransfer.ColorTransfer(pparent)
     
     if (@p_effecttype == 2)
       m_Blend = new @f_mergemode(this)
     endif
     if (@p_effecttype == 5)
       m_Gradient = new @f_gradient(this)
     endif
   endfunc
   
   color func Iterate(color pcolor)
     color c = pcolor                ; our original color
     color vc = rgba(red(c),green(c),blue(c),1.0)  ; our original color, stripped of alpha
     float vg = 0.0                  ; grey value
 
     if (@p_effecttype == 0 || @p_effecttype == 5)  ; channel extract or gradient
       if (@p_sourcechannel == 0)    ; red
         vg = red(c)
         vc = rgba(vg,0,0,1)
       elseif (@p_sourcechannel == 1)  ; green
         vg = green(c)
         vc = rgba(0,vg,0,1)
       elseif (@p_sourcechannel == 2)  ; blue
         vg = blue(c)
         vc = rgba(0,0,vg,1)
       elseif (@p_sourcechannel == 3)  ; cyan
         vg = red(c)
         vc = rgba(vg,1,1,1)
       elseif (@p_sourcechannel == 4)  ; magenta
         vg = green(c)
         vc = rgba(1,vg,1,1)
       elseif (@p_sourcechannel == 5)  ; yellow
         vg = blue(c)
         vc = rgba(1,1,vg,1)
       elseif (@p_sourcechannel == 6)  ; grey
         vg = red(c)*0.3 + green(c)*0.59 + blue(c)*0.11
         vc = rgba(vg,vg,vg,1)
       elseif (@p_sourcechannel == 7)  ; hue
         vg = hue(c)
         vc = hsla(vg,1,0.5,1)
       elseif (@p_sourcechannel == 8)  ; saturation (appears as red)
         vg = sat(c)
         vc = hsla(0,vg,0.5,1)
       elseif (@p_sourcechannel == 9)  ; lightness (not the same as grey!)
         vg = lum(c)
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 10)  ; value (not the same as lightness or grey!)
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 11)  ; Y
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 12)  ; Cb
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 13)  ; Cr
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 14)  ; U
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 15)  ; V
         vg = 0            ; **** unimplemented
         vc = hsla(0,0,vg,1)
       elseif (@p_sourcechannel == 16)  ; alpha (appears as grey)
         vg = alpha(c)
         vc = rgba(vg,vg,vg,1)
       endif
 
       if (@p_effecttype == 0)      ; channel extract
         if (@p_targetchannel == 1)    ; extract as grey
           vc = rgba(vg,vg,vg,1)
         elseif (@p_targetchannel == 2)  ; extract as alpha (color)
           vc = rgba(red(vc),green(vc),blue(vc),vg)
         elseif (@p_targetchannel == 3)  ; extract as alpha (black)
           vc = rgba(0,0,0,vg)
         elseif (@p_targetchannel == 4)  ; extract as alpha (white)
           vc = rgba(1,1,1,vg)
         elseif (@p_targetchannel == 5)  ; extract as alpha (grey)
           vc = rgba(vg,vg,vg,vg)
         endif
 
       elseif (@p_effecttype == 5)    ; gradient
         vc = m_Gradient.getColor(vg)
       
       endif
 
     elseif (@p_effecttype == 1)      ; color filter
       vc = rgba(0,0,0,1)        ; **** unimplemented
 
     elseif (@p_effecttype == 2)      ; color merge
       if (@p_mergeorder == 0)
         vc = m_Blend.FullMerge(@p_mergecolor, c, @p_mergeopacity)
       else
         vc = m_Blend.FullMerge(c, @p_mergecolor, @p_mergeopacity)
       endif
 
     elseif (@p_effecttype == 3)      ; gamma correction
       if (@p_gammaoverall)
         vg = red(c)*0.3 + green(c)*0.59 + blue(c)*0.11  ; compute grey value
         float vgc = vg
         if (@p_gammareverse)
           vgc = vg^(1/@p_gamma)
         else
           vgc = vg^@p_gamma
         endif
         if (vg != 0)
           vg = vgc/vg        ; brightness ratio
         endif
         vc = rgba(red(c)*vg,green(c)*vg,blue(c)*vg,alpha(c)*vg)
       else
         if (@p_gammareverse)
           vc = rgba(red(c)^(1/@p_gamma),green(c)^(1/@p_gamma),blue(c)^(1/@p_gamma),alpha(c)^(1/@p_gamma))
         else
           vc = rgba(red(c)^@p_gamma,green(c)^@p_gamma,blue(c)^@p_gamma,alpha(c)^@p_gamma)
         endif
       endif
 
     elseif (@p_effecttype == 4)      ; solarization
       float r = Solarize(@p_solarizemode, @p_solarizethreshold, red(c))
       float g = Solarize(@p_solarizemode, @p_solarizethreshold, green(c))
       float b = Solarize(@p_solarizemode, @p_solarizethreshold, blue(c))
       float a = Solarize(@p_solarizemode, @p_solarizethreshold, alpha(c))
       vc = rgba(r,g,b,a)
 
     ; type 5 is handled with type 0 above
 
     elseif (@p_effecttype == 6)      ; threshold
       if (@p_thresholdgrey)
         vg = red(c)*0.3 + green(c)*0.59 + blue(c)*0.11  ; compute grey value
         vg = Threshold(@p_threshold, vg)
         vc = rgba(vg,vg,vg,vg)
       else
         float r = Threshold(@p_threshold, red(c))
         float g = Threshold(@p_threshold, green(c))
         float b = Threshold(@p_threshold, blue(c))
         float a = Threshold(@p_threshold, alpha(c))
         vc = rgba(r,g,b,a)
       endif
 
     elseif (@p_effecttype == 7)      ; posterize
       float r = floor(red(c) * @p_posterizelevels) / @p_posterizelevels
       float g = floor(green(c) * @p_posterizelevels) / @p_posterizelevels
       float b = floor(blue(c) * @p_posterizelevels) / @p_posterizelevels
       float a = floor(alpha(c) * @p_posterizelevels) / @p_posterizelevels
       vc = rgba(r,g,b,a)
 
     endif
 
     if (@p_preservealpha)
       vc = rgba(red(vc),green(vc),blue(vc),alpha(c))
     endif
     
     return vc
   endfunc
 
 protected:
   GradientWrapper m_Gradient
   ColorMerge m_Blend
 
   float func Solarize(const int pmethod, const float pthreshold, float pvalue)
     if (pmethod == 0)    ; stretch to fit
       if (pvalue < pthreshold)
         if (pthreshold == 0)
           pvalue = -1e10
         else
           pvalue = pvalue/pthreshold
         endif
       else
         if (pthreshold == 1)
           pvalue = -1e10
         else
           pvalue = (1-pvalue)/(1-pthreshold)
         endif
       endif
 
     elseif (pmethod == 1)  ; equal slope
       if (pthreshold == 0)
         pvalue = -1e10
       elseif (pvalue < pthreshold)
         pvalue = pvalue/pthreshold
       else
         pvalue = 2 - pvalue/pthreshold
       endif
 
     elseif (pmethod == 2)  ; repeating sawtooth
       if (pthreshold == 0)
         pvalue = -1e10
       else
         pvalue = pvalue % (pthreshold*2)
         if (pvalue < pthreshold)
           pvalue = pvalue/pthreshold
         else
           pvalue = 2 - pvalue/pthreshold
         endif
       endif
 
     endif
     
     return pvalue
   endfunc
 
   float func Threshold(float pthreshold, float pvalue)
     if (pvalue < pthreshold)
       return 0
     else
       return 1
     endif
     return pvalue
   endfunc
 
 default:
   title = "Colorize"
   
   int param v_dmj_colorize
     caption = "Version (DMJ_Colorize)"
     default = 100
     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_dmj_colorize < 100
   endparam
 
   param p_effecttype
     caption = "Coloring Type"
     default = 0
     enum = "channel extract" "color filter" "color merge" "gamma adjust" "solarize" "apply gradient" "threshold" "posterize"
     hint = "Selects the type of colorizing effect you want to use."
   endparam
   param p_sourcechannel
     caption = "Channel"
     default = 6
     enum = "red" "green" "blue" "cyan" "magenta" "yellow" "grey" "hue" "saturation" "lightness" "value" "Y" "Cb" "Cr" "U" "V" "alpha"
     hint = "Selects the channel data to extract."
     visible = (@p_effecttype == 0 || @p_effecttype == 5)
   endparam
   param p_targetchannel
     caption = "Extract As"
     default = 0
     enum = "color" "grey" "alpha (color)" "alpha (black)" "alpha (white)" "alpha (grey)"
     hint = "Selects how the extracted data should be expressed. 'Color' will try to show a native color representation. 'Grey' will show the data as a grey value, and 'alpha' will show the data as transparency values."
     visible = (@p_effecttype == 0)
   endparam
 
   color param p_mergecolor
     caption = "Merge Color"
     default = rgba(1,0,0.5,1)
     hint = "Sets the color to merge with."
     visible = (@p_effecttype == 2)
   endparam
   ColorMerge param f_mergemode
     caption = "Merge Mode"
     default = DefaultColorMerge
     hint = "Sets the method used to merge input colors with."
     visible = (@p_effecttype == 2)
   endparam
   float param p_mergeopacity
     caption = "Merge Opacity"
     default = 0.5
     hint = "Sets the opacity of the merge. 0 will give no change to colors; 1 will give full effect of the merge mode."
     visible = (@p_effecttype == 2)
   endparam
   int param p_mergeorder
     caption = "Merge Order"
     default = 1
     enum = "input onto fixed" "fixed onto input"
     hint = "Sets the order in which colors are merged. The fixed color is the one you choose here; the input color is provided by the formula you plug this class into."
     visible = (@p_effecttype == 2)
   endparam
 
   float param p_gamma
     caption = "Gamma Value"
     default = 2.2
     hint = "Sets the gamma correction value. Gamma is used to correct midtones in images that occur due to non-linear brightness."
     visible = (@p_effecttype == 3)
   endparam
   bool param p_gammareverse
     caption = "Reverse Correction"
     default = false
     hint = "If checked, the reverse correction will be applied. This will allow you to easily 'undo' a previously-applied correction."
     visible = (@p_effecttype == 3)
   endparam
   bool param p_gammaoverall
     caption = "Preserve Colors"
     default = false
     hint = "EXPERIMENTAL: Gamma correction is properly applied to each color channel individually. However, when this is done, colors may shift towards primary colors. If you are using gamma correction as a way to adjust midtones in your image (rather than to actually correct for non-linear color) you may want to enable this option, which will try to preserve the colors while applying gamma correction based on the overall brightness of each color."
     visible = (@p_effecttype == 3)
   endparam
 
   float param p_solarizethreshold
     caption = "Solarize Threshold"
     default = 0.5
     hint = "Sets the cutoff level for the solarize effect. Values below the threshold will be increased; values at the threshold will be set to the maximum; values above the threshold will decrease towards zero."
     visible = (@p_effecttype == 4)
   endparam
   int param p_solarizemode
     caption = "Solarize Mode"
     default = 0
     enum = "stretch to fit" "equal slope" "repeating sawtooth"
     hint = "Sets the style of solarization."
     visible = (@p_effecttype == 4)
   endparam
 
   GradientWrapper param f_gradient
     caption = "Gradient"
     default = DefaultGradient
     hint = "Selects the gradient class to use for providing the gradient colors."
     visible = (@p_effecttype == 5)
   endparam
 
   float param p_threshold
     caption = "Threshold"
     default = 0.5
     hint = "Sets the cutoff level. Everything above this value will be set to 1; everything below it will be set to zero."
     visible = (@p_effecttype == 6)
   endparam
   bool param p_thresholdgrey
     caption = "Black and White"
     default = false
     hint = "If checked, thresholding will be done based on grey value and black or white will be the result."
     visible = (@p_effecttype == 6)
   endparam
 
   int param p_posterizelevels
     caption = "Posterize Levels"
     default = 6
     min = 2
     hint = "Sets the number of resulting color levels."
     visible = (@p_effecttype == 7)
   endparam
 
   bool param p_preservealpha
     caption = "Preserve Alpha"
     default = true
     hint = "If checked, the original transparency data from the image will be preserved regardless of the other changes."
   endparam
 }
 


Constructor Summary
DMJ_Colorize()
           
DMJ_Colorize(Generic pparent)
           
 
Method Summary
 color Iterate(color pcolor)
          call this to process another value in the sequence
protected  float Solarize(int pmethod, float pthreshold, float pvalue)
           
protected  float Threshold(float pthreshold, float pvalue)
           
 
Methods inherited from class common:ColorTransfer
Init, IterateSilent
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

DMJ_Colorize

public DMJ_Colorize(Generic pparent)

DMJ_Colorize

public DMJ_Colorize()
Method Detail

Iterate

public color Iterate(color pcolor)
Description copied from class: ColorTransfer
call this to process another value in the sequence

Overrides:
Iterate in class ColorTransfer

Solarize

protected float Solarize(int pmethod,
                         float pthreshold,
                         float pvalue)

Threshold

protected float Threshold(float pthreshold,
                          float pvalue)