common
Class ColorMerge

Object
  extended by common:Generic
      extended by common:ColorMerge
Direct Known Subclasses:
DefaultColorMerge, DMJ_FastNormalMerge

class 
Generic:ColorMerge

This is a generic color blending class. It accepts two colors and produces a merged result.


Ultra Fractal Source

Toggle UF Source Code Display

 class ColorMerge(Generic) {
   ; This is a generic color blending class. It accepts two
   ; colors and produces a merged result.
   
 public:
   ; Constructor
   ;
   ; @param pparent a reference to the object creating the new object; typically, 'this'
   func ColorMerge(Generic pparent)
     Generic.Generic(pparent)
   endfunc
   
   ; Color merging function
   ;
   ; @param pbottom color on the bottom
   ; @param ptop color on the top
   ; @return merged color; alpha value should be from the top color or composing won't work right
   color func Merge(color pbottom, color ptop)
     return ptop
   endfunc
 
   ; Opaque test function
   ; <p>
   ; In some cases, formulas want to know if, given a particular
   ; color, merging it onto another color will leave any of the
   ; other color visible (i.e. does all the color come from the
   ; top color). This function should return true in that case.
   ; The default implementation always returns false; if you
   ; write a merging class which can identify opaque colors, you
   ; should override this function. (Note this isn't as simple
   ; as just looking at the top color's opacity; in non-Normal
   ; merge modes the bottom color still influences the output.)
   ;
   ; @param ptop top color to test
   ; @return true if top color is fully opaque
   bool func IsOpaque(color ptop)
     return false
   endfunc
   
   ; Static composing/blending helper function
   ; <p>
   ; The explicit formula provided in the UF help for doing a
   ; color blend is:
   ; <p>
   ; compose(b, blend(t, mergeX(b, t), alpha(b)), o)
   ; <p>
   ; This at first seems overly complicated, but in fact is
   ; necessary to account for alpha in both the bottom and
   ; top colors. This function wraps up the compose and blend
   ; steps so you don't have to remember the correct formula.
   ; To use this, you will need to have the top color both
   ; before and after the merge function has been applied.
   ; <p>
   ; This is a static function, so you can call it without
   ; creating a ColorMerge object. Just call ColorMerge.Stack()
   ; directly.
   ;
   ; @param pbottom color on the bottom
   ; @param ptop color on the top (pre-merge)
   ; @param pmerged color on the top (post-merge)
   ; @param popacity opacity; 0 indicates all bottom, 1 indicates all top
   static color func Stack(color pbottom, color ptop, color pmerged, float popacity)
     return compose(pbottom, blend(ptop, pmerged, alpha(pbottom)), popacity)
   endfunc
   
   ; Composing/blending helper function
   ; <p>
   ; Like Stack(), this is a helper function to make it easier
   ; to merge colors layer-style. However, Stack() still requires
   ; you to produce the merged color. FullMerge() will do the
   ; merging for you, but you have to use a ColorMerge object
   ; (not just call a static function).
   ;
   ; @param pbottom color on the bottom
   ; @param ptop color on the top (pre-merge)
   ; @param popacity opacity; 0 indicates all bottom, 1 indicates all top
   color func FullMerge(color pbottom, color ptop, float popacity)
     return Stack(pbottom, ptop, Merge(pbottom, ptop), popacity)
   endfunc
 
 default:
   int param v_colormerge
     caption = "Version (ColorMerge)"
     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_colormerge < 100
   endparam
 }
 


Constructor Summary
ColorMerge()
           
ColorMerge(Generic pparent)
          Constructor
 
Method Summary
 color FullMerge(color pbottom, color ptop, float popacity)
          Composing/blending helper function
 boolean IsOpaque(color ptop)
          Opaque test function
 color Merge(color pbottom, color ptop)
          Color merging function
static color Stack(color pbottom, color ptop, color pmerged, float popacity)
          Static composing/blending helper function
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

ColorMerge

public ColorMerge(Generic pparent)
Constructor

Parameters:
pparent - a reference to the object creating the new object; typically, 'this'

ColorMerge

public ColorMerge()
Method Detail

Merge

public color Merge(color pbottom,
                   color ptop)
Color merging function

Parameters:
pbottom - color on the bottom
ptop - color on the top
Returns:
merged color; alpha value should be from the top color or composing won't work right

IsOpaque

public boolean IsOpaque(color ptop)
Opaque test function

In some cases, formulas want to know if, given a particular color, merging it onto another color will leave any of the other color visible (i.e. does all the color come from the top color). This function should return true in that case. The default implementation always returns false; if you write a merging class which can identify opaque colors, you should override this function. (Note this isn't as simple as just looking at the top color's opacity; in non-Normal merge modes the bottom color still influences the output.)

Parameters:
ptop - top color to test
Returns:
true if top color is fully opaque

Stack

public static color Stack(color pbottom,
                          color ptop,
                          color pmerged,
                          float popacity)
Static composing/blending helper function

The explicit formula provided in the UF help for doing a color blend is:

compose(b, blend(t, mergeX(b, t), alpha(b)), o)

This at first seems overly complicated, but in fact is necessary to account for alpha in both the bottom and top colors. This function wraps up the compose and blend steps so you don't have to remember the correct formula. To use this, you will need to have the top color both before and after the merge function has been applied.

This is a static function, so you can call it without creating a ColorMerge object. Just call ColorMerge.Stack() directly.

Parameters:
pbottom - color on the bottom
ptop - color on the top (pre-merge)
pmerged - color on the top (post-merge)
popacity - opacity; 0 indicates all bottom, 1 indicates all top

FullMerge

public color FullMerge(color pbottom,
                       color ptop,
                       float popacity)
Composing/blending helper function

Like Stack(), this is a helper function to make it easier to merge colors layer-style. However, Stack() still requires you to produce the merged color. FullMerge() will do the merging for you, but you have to use a ColorMerge object (not just call a static function).

Parameters:
pbottom - color on the bottom
ptop - color on the top (pre-merge)
popacity - opacity; 0 indicates all bottom, 1 indicates all top