Sign in to follow this  

Rubber Stamp v1.0 (April 15, 2017)

Recommended Posts

Dear Seerose, <3:cake:  thank you so much for the wonderful picture and your kind words! You're always soooooooooooo nice ;)

And you already discovered the video about Rubber Stamp on YT, although I didn't post a link here ... :monocole:

  • Upvote 1

Share this post

Link to post
Share on other sites

To demonstrate some of the new features of CodeLab v3, I converted my 'Rubber Stamp' Visual Studio project to a CodeLab script.

New features specifically demonstrated here are:  the PreRender method, Slider Decorations (on Amount3), and Prop Rules (on Amount6).  Previously, those three things had to be done in Visual Studio.


Hopefully it will be of some interest to a few people.



// Name: Rubber Stamp
// Submenu: Object
// Author: toe_head2001
// Title:
// Version: 1.0
// Desc: Rubber Stamp Effect
// Keywords: rubber|stamp
// URL:
#region UICode
IntSliderControl Amount1 = 50; // [0,100] Scale
DoubleSliderControl Amount2 = 1; // [0,1] Roughness
IntSliderControl Amount3 = 85; // [0,255,4] Minimum Opacity
ReseedButtonControl Amount4 = 0; // [255] Reseed
CheckboxControl Amount5 = false; // [0,1] Use Custom Color
ColorWheelControl Amount6 = ColorBgra.FromBgr(0,0,0); // [PrimaryColor] {Amount5} 

readonly BinaryPixelOp normalOp = LayerBlendModeUtil.CreateCompositionOp(LayerBlendMode.Normal);
readonly CloudsEffect cloudsEffect = new CloudsEffect();
PropertyCollection cloudsProps;
Surface emptySurface;
Surface cloudSurface;

void PreRender(Surface dst, Surface src)
    if (emptySurface == null)
        emptySurface = new Surface(src.Size);
    if (cloudSurface == null)
        cloudSurface = new Surface(src.Size);

    cloudsProps = cloudsEffect.CreatePropertyCollection();
    PropertyBasedEffectConfigToken CloudsParameters = new PropertyBasedEffectConfigToken(cloudsProps);
    CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Scale, Amount1);
    CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Power, Amount2);
    CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Seed, (int)Amount4);
    using (EffectEnvironmentParameters environParameters = new EffectEnvironmentParameters(ColorBgra.Black, Color.FromArgb(Amount3, Color.Black), 0, EnvironmentParameters.GetSelection(src.Bounds), emptySurface))
        cloudsEffect.EnvironmentParameters = environParameters;
    cloudsEffect.SetRenderInfo(CloudsParameters, new RenderArgs(cloudSurface), new RenderArgs(emptySurface));

void Render(Surface dst, Surface src, Rectangle rect)
    cloudsEffect.Render(new Rectangle[1] { rect }, 0, 1);

    ColorBgra currentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
            currentPixel = (Amount5) ? Amount6 : src[x, y];
            currentPixel.A = Int32Util.ClampToByte(cloudSurface[x, y].A + src[x, y].A - byte.MaxValue);

            dst[x, y] = currentPixel;

protected override void OnDispose(bool disposing)
    // Release any surfaces or effects you've created.
    if (emptySurface != null)
        emptySurface = null;
    if (cloudSurface != null)
        cloudSurface = null;

    if (cloudsEffect != null)
        cloudsEffect = null;





Edited by toe_head2001
  • Like 2
  • Upvote 3

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this