reb
Class REB_ImageTrapsColoring

Object
  extended by common:Generic
      extended by common:Coloring
          extended by common:DirectColoring
              extended by reb:REB_ImageTrapsColoring

class 
DirectColoring:REB_ImageTrapsColoring

An Orbit Traps variant with the addition of trapped image import.

The formula provides for the import of images which are trapped according to the trap shape, trap mode and trap coloring used. Internally the the regular trap coloring and the image trap coloring are treated as separate layers which can be merged by the usual merge options. The image import plugin is a ColorTrap type, and any other ColorTrap type can be used in its slot.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_ImageTrapsColoring(common.ulb:DirectColoring) {
 ; An Orbit Traps variant with the addition of trapped image import.
 ; <p>
 ; The formula provides for the import of images which are trapped according to
 ; the trap shape, trap mode and trap coloring used. Internally the the regular
 ; trap coloring and the image trap coloring are treated as separate layers which
 ; can be merged by the usual merge options. The image import plugin is a ColorTrap
 ; type, and any other ColorTrap type can be used in its slot.  
 $define debug
 public:
   import "common.ulb"
   import "dmj5.ulb"
 
   ; constructor
   func REB_ImageTrapsColoring(Generic pparent)
     DirectColoring.DirectColoring(pparent)
     m_TrapSelect = new @f_trapselect(this)
     fTransform = new @transform(this)
     m_TrapShape = new @f_trapshape(this)
     m_ImageTrapMode = new @f_trapmode(this)
     fTransfer = new @transfer(this)
     fDTransfer = new @dtransfer(this)
     m_ImageTrapColoring = new @f_trapcoloring(this)
     m_TrapShape.SetThreshold(@p_threshold)
     m_ImageTrapMode.SetThreshold(@p_threshold)
     if  @f_trapcolor != ColorTrapNoColor
       float athresh = @p_athreshold+0.001
       m_ImageTrapMode.SetAThreshold(athresh)
     else
       m_ImageTrapMode.SetAThreshold(@p_athreshold)
     endif
     m_TrapTexture = new @f_traptexture(this)
     m_MergeColor = new @f_colormerge(this)
     m_TrapColor = new @f_trapcolor(this)
     m_img = new @f_image(0)
     m_empty = m_img.GetEmpty()
   endfunc
   
   ; Initialize the coloring formula
   func Init(complex pz, complex ppixel)
     DirectColoring.Init(pz,ppixel)
     m_TrapSelectSequence = m_TrapSelect.InitDefault()
     fTransform.init(pz)
     fTransfer.init(pz)
     m_ImageTrapMode.Init(pz)
     m_TrapShape.Init(pz)
     m_TrapTexture.Init(pz)
     m_TrapColor.Init(pz)
   endfunc
   
   ; call for each iterated point
   func Iterate(complex pz)
     DirectColoring.Iterate(pz)
     m_TrapSelectSequence = m_TrapSelect.Iterate(m_TrapSelectSequence)
     if ((@f_trapselect == DMJ_TrapSelect && m_TrapSelectSequence > 0.5) \
        || m_TrapSelectSequence > @p_trapselectthreshold)
       complex m_zr = fTransform.Iterate(pz)
       float pdistance = m_TrapShape.iterate(m_zr)
       complex pdcomplex = 0
       if @v_imagetraps >= 103
         pdcomplex = m_TrapShape.GetTransformedPoint()
         if @dtype == "Manhattan"
           pdistance = abs(real(m_zr-pdcomplex))^real(@mp) + \
                       abs(imag(m_zr-pdcomplex))^imag(@mp)
         elseif @dtype == "Bray Curtis"
           pdistance = pdistance*(abs(real(m_zr-pdcomplex)) + abs(imag(m_zr-pdcomplex)))/ \
                       ((abs(real(m_zr+pdcomplex)) + abs(imag(m_zr+pdcomplex))))
         elseif @dtype == "Canberra"
           pdistance = pdistance*abs(real(m_zr-pdcomplex))/(abs(real(m_zr)) + abs(real(pdcomplex))) + \
                       abs(imag(m_zr-pdcomplex))/(abs(imag(m_zr)) + abs(imag(pdcomplex)))
         elseif @dtype == "Minkovsky"
           pdistance = (abs(real(m_zr-pdcomplex))^@ex + \
                       abs(imag(m_zr-pdcomplex))^@ex)^(1/@ex)
         elseif @dtype == "Chebychev"
           pdistance = abs(real(m_zr-pdcomplex))
           if pdistance < abs(imag(m_zr-pdcomplex))
             pdistance = abs(imag(m_zr-pdcomplex))
           endif
         endif
       endif
       complex tx = m_TrapShape.GetTransformedPoint()
       if @shapeflavor == 1
         pdistance = pdistance + cabs(tx)
       endif
       fdTransfer.SetTransformed(tx)
       fdTransfer.SetUnTransformed(m_zr)
       pdistance = fTransfer.Iterate(pdistance)
       pdistance = fdTransfer.Iterate(pdistance)
       if @v_imagetraps < 101
         m_img = new @f_image(0)
         m_empty = m_img.GetEmpty()
       endif
       color pcolor = @colorempty
       if @v_imagetraps >= 101
         if @f_trapcolor == ColorTrapNoColor
           m_empty = true
         else
           pcolor = m_TrapColor.Iterate(m_zr)
           m_empty = false
         endif
       else
         if !m_empty
          complex m_zi = (0,1)^(@iangle/90.0)
          complex m_zs = (0,1)^(@sangle/90.0)
          complex pzrs = pz
          ; offset
          if !@itile
            pzrs = pzrs+@ioffset
          endif
          ; aspect ratio
          pzrs = real(pzrs) + flip(imag(pzrs)*@iaspect)
          ; rotation
          pzrs = pzrs*m_zi
          ; skew
          pzrs = real(pzrs)*m_zs + flip(imag(pzrs))
 
          float width =  m_img.getWidth()
          float height = m_img.getHeight()
          if @itile
            pzrs = (pzrs+#width/2+flip(#height/2))*@scale*#width
            complex c = @adjx-2*((real(pzrs) % (width-1))/width) + \
             flip(@adjy-2*((imag(pzrs) % (height-1))/height))
            pcolor = m_img.getColor(c)
          else
            pcolor = m_img.getColor(pzrs*@scale)
          endif
          else
            pcolor = @colorempty
         endif
       endif
       float ptexture = 0
       if !@p_textureposttransform
 ;         ptexture = m_TrapTexture.Iterate(m_zr)
          ptexture = m_TrapTexture.Iterate(pz)
          if @texflavor == 1
            ptexture = cabs(m_trapTexture.GetTransformedPoint())
          elseif @texflavor == 2
            ptexture = ptexture + cabs(m_trapTexture.GetTransformedPoint())
          endif
          ptexture = ptexture*@p_texturestrength
        else
         ptexture = m_TrapShape.GetTextureValue()
         ptexture = ptexture + m_TrapTexture.Iterate(tx)
         ptexture = (ptexture + m_TrapTexture.GetTextureValue()) * @p_texturestrength
       endif  
       if @weighttodist && (@f_traptexture != DMJ_TrapShapeFlat)
         ptexture = ptexture/(@dweight + 1/(1e-10+pdistance^@dpower))
       endif
       if @weighttothresh && (@f_traptexture != DMJ_TrapShapeFlat)
         ptexture = ptexture*((@p_Threshold-pdistance)/@p_Threshold)^@tpower
         if ptexture < 0
           ptexture = 0
         endif
       endif
       if !fTransform.IsSolid()
         m_ImageTrapMode.Iterate(m_zr, tx, pdistance,ptexture,pcolor)
       else
         m_ImageTrapMode.IterateSilent()
       endif
     else
       fTransform.IterateSilent()
       m_TrapShape.IterateSilent()
       fTransfer.IterateSilent()
       fdTransfer.IterateSilent()
       m_ImageTrapMode.IterateSilent()
       m_TrapTexture.IterateSilent()
     endif
   endfunc
   
   ; call in the final section of the ucl to get final coloring results.
   color func Result(complex pz)
     m_ImageTrapMode.Result()
     color final_color = m_ImageTrapColoring.CResult(m_ImageTrapMode)
     if @v_imagetraps >= 102  && @v_imageTraps < 105
       if @ahue
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       hue(final_color))
       elseif @alum
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       lum(final_color))
       elseif @asat
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       sat(final_color))
       endif
     endif
     if @v_imageTraps >= 105
       if @ahue
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       hue(final_color)*alpha(final_color/6))
       endif
       if @alum
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       lum(final_color)*alpha(final_color))
       endif
       if @asat
         final_color = hsla(hue(final_color), sat(final_color), lum(final_color), \
                       sat(final_color)*alpha(final_color))
       endif
     endif
     color merge_color = gradient(m_ImageTrapColoring.Result(m_ImageTrapMode))
     m_Solid = @usesolid && m_ImageTrapMode.IsSolid()
     float opacity = 0
     color temp = rgba(0,0,0,0)
     if @nmerge == 1 || m_empty
       temp = merge_color
       merge_color = final_color
       final_color = temp
     endif
     if !m_empty
       opacity = @opacity
     else
       opacity = 1
     endif
     color rcolor = m_MergeColor.FullMerge(merge_color, final_color, opacity)
     if @v_imageTraps >= 105
       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(rcolor)-br
       float gr = green(rcolor)-br
       float bl = blue(rcolor)-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
       rcolor = rgba(rd,gr,bl,alpha(rcolor))
       rd = red(rcolor)^cr
       gr = green(rcolor)^cr
       bl = blue(rcolor)^cr
       rcolor = rgba(rd,gr,bl,alpha(rcolor))
       float satval = sat(rcolor)-st
       if satval > 1
         satval = 1
       endif
       if satval < 0
         satval = 0
       endif
       rcolor = hsla(hue(rcolor), satval, lum(rcolor), alpha(rcolor))
       float hueval = (hue(rcolor)+hu) % 6
       rcolor = hsla(hueval, sat(rcolor), lum(rcolor), alpha(rcolor))
     endif
     if @p_poster
       float rd = floor(red(rcolor)*@p_chan)/@p_chan + 0.5/@p_chan
       float gr = floor(green(rcolor)*@p_chan)/@p_chan + 0.5/@p_chan
       float bl = floor(blue(rcolor)*@p_chan)/@p_chan  + 0.5/@p_chan
       rcolor = rgba(rd,gr,bl,alpha(rcolor))
     endif
     if @p_gray
        float gry = 0.3 * red(rcolor)+ 0.59 * green(rcolor) + 0.11 * blue(rcolor)
        rcolor = rgba(gry,gry,gry,alpha(rcolor))
     endif
     if @p_solar
       float rd = red(rcolor)
       float gr = green(rcolor)
       float bl = blue(rcolor)
       if rd > @p_thresh
         rd = 1-rd
       endif
       if gr > @p_thresh
         gr = 1-gr
       endif
       if bl > @p_thresh
         bl = 1-bl
       endif
       rcolor = rgba(rd,gr,bl,alpha(rcolor))
     endif
     if @p_bw
       float gry = 0.3 * red(rcolor)+ 0.59 * green(rcolor) + 0.11 * blue(rcolor)
       if gry < @p_bwt
         rcolor = rgba(0,0,0,alpha(rcolor))
       else
         rcolor = rgba(1,1,1,alpha(rcolor))
       endif
     endif
     return rcolor
   endfunc
   
   ; Is the coloring solid? - used by the coloring ucl.
   bool func IsSolid()
     return m_Solid
   endfunc
   
 protected:
   Generator m_TrapSelect
   TrapShape m_TrapShape
   UserTransform fTransform
   Transfer fTransfer
   TransferDistanceVariants fDTransfer
   ImageTrapMode m_ImageTrapMode
   ImageTrapColoring m_ImageTrapColoring
   TrapShape m_TrapTexture
 
   ImageImport m_img
   ColorTrap m_TrapColor
   DefaultColorMerge m_MergeColor
 
   int m_image_width
   int m_image_height
   float m_ratio
   bool m_empty
   float m_TrapSelectSequence
 
 default:
   title = "Image Traps"
   int param v_imagetraps
     caption = "Version (Image Traps)"
     default = 105
     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_imagetraps < 105
   endparam
   heading
     text = "This coloring formula combines classical orbit traps with color \
            objects, including images."
   endheading
   float param version
     caption = "version parameter"
     default = 1.0
     visible = false
   endparam
   heading
     caption = "Trap Parameters"
   endheading
   Generator param f_trapselect
     caption = "Trap Iteration"
     default = DMJ_TrapSelect
     expanded = false
   endparam
   float param p_trapselectthreshold
     caption = "Threshold"
     default = 0.5
     hint = "When using a Generator other than a TrapSelect type, values could range anywhere from 0 to 1. This threshold sets which values will be interpreted as 'do not trap' and which will be interpreted as 'trap'."
     visible = (@f_trapselect != DMJ_TrapSelect)
   endparam
   UserTransform param transform
     caption = "Trap Position"
     default = TrapTransformMod
     expanded = false
     hint = "Transforms the orbit values from the fractal formula before they \
             are passed to the trap shape."
   endparam
   TrapShape param f_trapshape
     caption = "Trap Shape"
     default = REB_TrapShapeBifolium
   endparam
   param shapeflavor
     caption = "Shape flavor"
     default = 0
     enum = "flavor 1" "flavor 2"
   endparam
   param dtype
     caption = "Distance metric"
     default = 3
     enum = "Bray Curtis" "Canberra" "Chebychev" "Euclidian" \
            "Manhattan" "Minkovsky"
     visible = @v_imagetraps >= 103
   endparam
   complex param mp
     caption = "Manhattan power"
     default = (1,1)
     visible = @v_imagetraps >= 103 && @dtype == "Manhattan"
   endparam
   float param ex
     caption = "Minkovsky param"
     default = 0.5
     visible = @v_imagetraps >= 103 && @dtype == "Minkovsky"
   endparam
   Transfer param transfer
     caption = "Trap Transfer"
     expanded = false
     default = TrapTransfer
     hint = "Provides additional options to scale and transform the distance \
             that the trap shape returns."
   endparam
   TransferDistanceVariants param dtransfer
     caption = "Custom Transfer"
     expanded = false
     default = TransferDistanceVariants
     hint = "Provides additional options to scale and transform the distance \
             that the trap shape returns."
   endparam
   ImageTrapMode param f_trapmode
     caption = "Trap Mode"
     default = ImageTrapModeClosest
     endparam
   float param p_threshold
     caption = "Trap Threshold"
     default = 0.25
     hint = "This is the overall size or thickness of the trap area. (Some trap modes may not use the threshold value.)"
     visible = (@f_trapmode == ImageTrapModeWithThreshold)
   endparam
   float param p_athreshold
     caption = "Alpha Threshold"
     default = 0.0
     hint = "This is the overall size or thickness of the trap area. (Some trap modes may not use the threshold value.)"
     visible = (@f_trapmode == ImageTrapModeWithThreshold)
   endparam
   bool param usesolid
     caption = "Use Solid Color"
     default = false
   endparam
   TrapShape param f_traptexture
     caption = "Trap Texture"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change the shape of the trap but may change its coloring."
   endparam
   bool param p_textureposttransform
     caption = "Use Transformed Coordinate"
     default = false
     hint = "If checked, texturing will be based on the final transformed coordinate used in the trap shape (i.e. it will follow the trap shape, rather than being separate from it)."
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   bool param weighttodist
     caption = "Weight by Distance"
     default = false
     visible = !@weighttothresh && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   bool param weighttothresh
     caption = "Weight by Threshold"
     default = false
     visible = !@weighttodist && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   float param p_texturestrength
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers will increase the effect of the texture. A value of 0 will remove the effects of the texture."
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   float param dweight
     caption = "Distance weight"
     default = 1.0
     visible = @weighttodist && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   float param dpower
     caption = "Distance power"
     default = 1.0
     visible = @weighttodist && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   float param tpower
     caption = "Threshold power"
     default = 1.0
     visible = @weighttothresh && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   param texflavor
     caption = "Texture flavor"
     default = 0
     enum = "flavor 1" "flavor 2" "flavor 3"
     visible = (@f_traptexture != DMJ_TrapShapeFlat)&& !@p_textureposttransform
   endparam
   ImageTrapColoring param f_trapcoloring
     caption = "Trap Color Mode"
     default = ImageTrapColoringDistance
   endparam
   heading
     caption = "Images and Colorings"
   endheading
   ColorTrap param f_trapcolor
     caption = "Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @v_imagetraps >= 101
   endparam
   ImageImport param f_image
     caption = "Image"
     default = ImageImport
     visible = @v_imagetraps < 101
   endparam
   float param scale
     caption = "Image scale"
     default = 1
     min = 0
     hint = "Changes the scale of the image."
     visible = @v_imagetraps < 101
   endparam
   float param adjx
     caption = "Tile adj x"
     default = 0.99
     min = 0.9
     max = 1.1
     visible = @v_imagetraps < 101
   endparam
   float param adjy
     caption = "Tile adj y"
     default = 0.999
     min = 0.9
     max = 1.1
     visible = @v_imagetraps < 101
   endparam
   complex param ioffset
     caption = "Image offset"
     default = (0,0)
     visible = !@itile && @v_imagetraps < 101
   endparam
   float param iaspect
     caption = "Image aspect"
     default = 1.0
     visible = @v_imagetraps < 101
   endparam
   float param iangle
     caption = "Image rotation"
     default = 0
     hint = "Rotates the image"
     visible = @v_imagetraps < 101
   endparam
   float param sangle
     caption = "Image skew"
     default = 0
     hint = "Skews the image"
     visible = @v_imagetraps < 101
   endparam
   bool param itile
     caption = "Tile the image"
     default = false
     visible = @v_imagetraps < 101
   endparam
   color param colorempty
     caption = "No Image Color"
     default = rgba(1,1,1,0)
     visible = @f_trapcolor == ColorTrapNoColor
   endparam
   heading
     caption = "Color Merging"
   endheading
   DefaultColorMerge param f_colormerge
     caption = "Color Merge"
     default = DefaultColorMerge
   endparam
   param nmerge
     caption = "Merge order"
     default = 0
     enum = "Image on Top" "Image on Bottom"
   endparam
   float param opacity
     caption = "Merge Opacity"
     default = 1.0
   endparam
   heading
     text = "Make image transparent by: "
     visible = @v_imagetraps >= 102 && @f_trapcolor != ColorTrapNoColor
   endheading
   bool param ahue
     caption = "Hue value"
     default = false
     visible = ((@v_imagetraps >= 102 && @v_imagetraps < 105 && !@alum && !@asat) || \
               @v_imagetraps >= 105) && @f_trapcolor != ColorTrapNoColor
   endparam
   bool param alum
     caption = "Luminance value"
     default = false
     visible = ((@v_imagetraps >= 102 && @v_imagetraps < 105 && !@ahue && !@asat) || \
               @v_imagetraps >= 105) && @f_trapcolor != ColorTrapNoColor
   endparam
   bool param asat
     caption = "Saturation value"
     default = false
     visible = ((@v_imagetraps >= 102 && @v_imagetraps < 105 && !@alum && !@ahue) || \
               @v_imagetraps >= 105) && @f_trapcolor != ColorTrapNoColor
   endparam
   heading
     caption = "Special Effects"
   endheading
   float param p_bright
     caption = "Brightness"
     default = 0.5
     min = 0
     max = 1
     visible = @v_imagetraps >= 105
   endparam
   float param p_contrast
     caption = "Contrast"
     default = 0.5
     min = 0
     max = 1
     visible = @v_imagetraps >= 105
   endparam
   float param p_sat
     caption = "Saturation"
     default = 0.5
     min = 0
     max = 1
     visible = @v_imagetraps >= 105
   endparam
   float param p_hue
     caption = "Hue"
     default = 0.0
     min = 0
     max = 1
     visible = @v_imagetraps >= 105
   endparam
   bool param p_gray
     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_ImageTrapsColoring()
           
REB_ImageTrapsColoring(Generic pparent)
          constructor
 
Method Summary
 void Init(complex pz, complex ppixel)
          Initialize the coloring formula
 boolean IsSolid()
          Is the coloring solid? - used by the coloring ucl.
 void Iterate(complex pz)
          call for each iterated point
 color Result(complex pz)
          call in the final section of the ucl to get final coloring results.
 
Methods inherited from class common:Coloring
GetPixel, IsGradient
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_ImageTrapsColoring

public REB_ImageTrapsColoring(Generic pparent)
constructor


REB_ImageTrapsColoring

public REB_ImageTrapsColoring()
Method Detail

Init

public void Init(complex pz,
                 complex ppixel)
Initialize the coloring formula

Overrides:
Init in class DirectColoring
Parameters:
pz - first value for the sequence; for a normal coloring formula, this will be #z
ppixel - seed value for the sequence; for a normal coloring formula, this will be #pixel

Iterate

public void Iterate(complex pz)
call for each iterated point

Overrides:
Iterate in class DirectColoring
Parameters:
pz - next value in the sequence; corresponds to #z in a coloring formula

Result

public color Result(complex pz)
call in the final section of the ucl to get final coloring results.

Overrides:
Result in class DirectColoring
Returns:
the gradient index (corresponding to #index in a coloring formula)

IsSolid

public boolean IsSolid()
Is the coloring solid? - used by the coloring ucl.

Overrides:
IsSolid in class DirectColoring
Returns:
whether the sequence produced a solid-color value