Sign in to follow this  
toe_head2001

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.

 

Spoiler

// Name: Rubber Stamp
// Submenu: Object
// Author: toe_head2001
// Title:
// Version: 1.0
// Desc: Rubber Stamp Effect
// Keywords: rubber|stamp
// URL: https://forums.getpaint.net/index.php?showtopic=111225
#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} 
#endregion

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.Dispose();
        emptySurface = null;
    }
  
    if (cloudSurface != null)
    {
        cloudSurface.Dispose();
        cloudSurface = null;
    }

    if (cloudsEffect != null)
    {
        cloudsEffect.Dispose();
        cloudsEffect = null;
    }

    base.OnDispose(disposing);
}

 

 

 

Edited by toe_head2001
  • Like 2
  • Upvote 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this