Jump to content

Chalkboard (needs work... ok, hopeless)


Recommended Posts








*tinker* *tinker* *tinker*


*give up*


// Author: BoltBait
// Submenu: Artistic
// Name: Chalkboard
// URL: http://www.BoltBait.com/pdn
// Title: BoltBait's Chalkboard v1.0
#region UICode
int Amount1 = 10; // [0,100] Radius
int Amount2 = -10; // [-100,100] Brightness
int Amount3 = 10; // [-100,100] Contrast
double Amount4 = 0.9; // [0,1] Strength
bool Amount5 = false; // [0,1] Invert Mask

// Setup for using pixel op
private UnaryPixelOps.Desaturate desaturateOp = new UnaryPixelOps.Desaturate();
private UnaryPixelOps.Invert invertOp = new UnaryPixelOps.Invert();

// Setup for using Darken blend op
private UserBlendOps.MultiplyBlendOp multiplyOp = new UserBlendOps.MultiplyBlendOp();

// Here is the main render loop function
unsafe void Render(Surface dst, Surface src, Rectangle rect)
    // Setup for calling the Gaussian Blur effect
    GaussianBlurEffect blurEffect = new GaussianBlurEffect();
    PropertyCollection blurProps = blurEffect.CreatePropertyCollection();
    PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps);
    BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1);
    blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(dst), new RenderArgs(src));
    // Call the Gaussian Blur function
    blurEffect.Render(new Rectangle[1] {rect},0,1);

    // Setup for calling the Brightness and Contrast function
    BrightnessAndContrastAdjustment bacAdjustment = new BrightnessAndContrastAdjustment();
    PropertyCollection cProps = bacAdjustment.CreatePropertyCollection();
    PropertyBasedEffectConfigToken cParameters = new PropertyBasedEffectConfigToken(cProps);
    cParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, Amount2);
    cParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, Amount3);
    bacAdjustment.SetRenderInfo(cParameters, new RenderArgs(dst), new RenderArgs(dst));
    // Call the Brightness and Contrast function
    bacAdjustment.Render(new Rectangle[1] {rect},0,1); 
    // Now in the main render loop, the dst canvas has a blurred version of the src canvas
    for (int y = rect.Top; y < rect.Bottom; y++)
        ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y);
        ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
        for (int x = rect.Left; x < rect.Right; x++)
            ColorBgra CurrentPixel = *srcPtr;
            ColorBgra DestPixel = *dstPtr;

            // Desaturate pixels
            CurrentPixel = desaturateOp.Apply(CurrentPixel);
            DestPixel = desaturateOp.Apply(DestPixel);

            // Calculate difference in src and blurred dest pixel
            DestPixel.R = (byte)Math.Abs(CurrentPixel.R - DestPixel.R);
            DestPixel.G = (byte)Math.Abs(CurrentPixel.G - DestPixel.G);
            DestPixel.B = (byte)Math.Abs(CurrentPixel.B - DestPixel.B);

            // Invert mask
            if (Amount5) DestPixel = invertOp.Apply(DestPixel);
            // Apply strength
            DestPixel.A = (byte)((double)DestPixel.A * Amount4);
            // Shade final pixel
            CurrentPixel = multiplyOp.Apply(*srcPtr, DestPixel);
            *dstPtr = CurrentPixel;
Link to comment
Share on other sites

Trying to replicate an image drawn in chalk?  Like these?



Link to comment
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.

  • Create New...