Sign in to follow this  
Sakana Oji

Color Intensifier and HDR - My first two plugins

Recommended Posts

Created with a little help from ReMake, BoltBait and others!

 

Color Intensifier is based on this tutorial by xmario, while HDR is based on applying an inverted, blurred and black and white overlay on the original image.

 

Download Color Intensifier here: ColorIntensifier.zip

 

Download HDR here: HDR.zip

 

Here is the code for Color Intensifier:

 

// Name: Color Intensifier
// Submenu: Color
// Author: Sakana Oji
// Title: Color Intensifier
// Version: 1.0
// Desc: Intensifies the colors of the picture
// Keywords: intensity|color
// URL: http://www.getpaint.net/redirect/plugins.html
// Help:
#region UICode
#endregion

// Setup for calling the Brightness and Contrast Adjustment function
BrightnessAndContrastAdjustment bacAdjustment = new BrightnessAndContrastAdjustment();
PropertyCollection bacProps;

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

// Setup for using Reflect blend op
private BinaryPixelOp reflectOp = LayerBlendModeUtil.CreateCompositionOp(LayerBlendMode.Reflect);

protected override void OnDispose(bool disposing)
{
    // Release any surfaces or effects you've created.
    if (bacAdjustment != null) bacAdjustment.Dispose();
    bacAdjustment = null;
    base.OnDispose(disposing);
}

void PreRender(Surface dst, Surface src)
{
    bacProps = bacAdjustment.CreatePropertyCollection();
    PropertyBasedEffectConfigToken bacParameters = new PropertyBasedEffectConfigToken(bacProps);
    bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, 0);
    bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, -1);
    bacAdjustment.SetRenderInfo(bacParameters, new RenderArgs(dst), new RenderArgs(src));
}

// Here is the main render loop function
void Render(Surface dst, Surface src, Rectangle rect)
{
    // Call the Brightness and Contrast Adjustment function
    bacAdjustment.Render(new Rectangle[1] {rect},0,1);

    // Now in the main render loop, the dst canvas has an adjusted version of the src canvas
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra CurrentPixel = dst[x,y];

            // TODO: Add additional pixel processing code here
            CurrentPixel = desaturateOp.Apply(CurrentPixel);

            CurrentPixel = invertOp.Apply(CurrentPixel);

            CurrentPixel = reflectOp.Apply(src[x,y], CurrentPixel);

            dst[x,y] = CurrentPixel;
        }
    }
}

 

And this code is for HDR:

 

// Name: HDR
// Submenu: Adjustments
// Author: Sakana Oji
// Title: HDR
// Version: 1.0
// Desc: Adds a HDR effect to the image
// Keywords: hdr|enhancement|enhance|blur
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 2; // [0,200] Radius
#endregion

// Setup for calling the Gaussian Blur effect
GaussianBlurEffect blurEffect = new GaussianBlurEffect();
PropertyCollection blurProps;

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

// Setup for using Overlay blend op
private BinaryPixelOp overlayOp = LayerBlendModeUtil.CreateCompositionOp(LayerBlendMode.Overlay);

protected override void OnDispose(bool disposing)
{
    // Release any surfaces or effects you've created.
    if (blurEffect != null) blurEffect.Dispose();
    blurEffect = null;
    base.OnDispose(disposing);
}

void PreRender(Surface dst, Surface src)
{
    blurProps = blurEffect.CreatePropertyCollection();
    PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps);
    BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1);
    blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(dst), new RenderArgs(src));
}

// Here is the main render loop function
void Render(Surface dst, Surface src, Rectangle rect)
{
    // Call the Gaussian Blur function
    blurEffect.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++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra CurrentPixel = dst[x,y];

            // TODO: Add additional pixel processing code here
            CurrentPixel = desaturateOp.Apply(CurrentPixel);

            CurrentPixel = invertOp.Apply(CurrentPixel);

            CurrentPixel = overlayOp.Apply(src[x,y], CurrentPixel);

            dst[x,y] = CurrentPixel;
        }
    }
}

 

Edited by Sakana Oji
Removed Takeafile link, removed Dropbox links and added zip attachments

Share this post


Link to post
Share on other sites

I have some feedback regarding ways to improve and simplify your code. I'm about the walk out the door, so I'll get back to later tonight.

 

41 minutes ago, Sakana Oji said:

while HDR is based on applying an inverted, blurred and black and white overlay on the original image.

 

How does that equate to HDR?

 

45 minutes ago, Sakana Oji said:

Download them as a 2-plugin pack: https://takeafile.com/?f=wananekike

 

No offense directed to you, but what a awful way to distribute your plugins. Please use a different service or host, or better yet, attach a ZIP file to the forum.

Share this post


Link to post
Share on other sites

Yup. I'm backing toe_head2001 with the request for an attached ZIP.

 

takeafile-error.png

 

Neither source code compiles as posted. Both give me this error in codeLab....

 

Quote

Exception has been thrown by the target of an invocation.

 

 

Share this post


Link to post
Share on other sites

You aren't doing any per-pixel processing in either effect, so you don't need the X,Y loops.

 

For example, your "HDR" plugin can go from this:

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Call the Gaussian Blur function
    blurEffect.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++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra CurrentPixel = dst[x,y];

            // TODO: Add additional pixel processing code here
            CurrentPixel = desaturateOp.Apply(CurrentPixel);

            CurrentPixel = invertOp.Apply(CurrentPixel);

            CurrentPixel = overlayOp.Apply(src[x,y], CurrentPixel);

            dst[x,y] = CurrentPixel;
        }
    }
}

To this:

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Call the Gaussian Blur function
    blurEffect.Render(new Rectangle[] {rect}, 0, 1);

    desaturateOp.Apply(dst, rect);

    invertOp.Apply(dst, rect);

    overlayOp.Apply(dst, src, dst, rect);
}

 

 

Also a note about the Dispose override. Please place objects within a diposing condition.

Yes, I know CodeLab wrote this code for you, but you used an old version. The newest version of CodeLab corrects this oversight.

protected override void OnDispose(bool disposing)
{
    if (disposing)
    {
        // Release any surfaces or effects you've created.
        if (blurEffect != null) blurEffect.Dispose();
        blurEffect = null;
    }
  
    base.OnDispose(disposing);
}

 

Share this post


Link to post
Share on other sites
12 hours ago, Ego Eram Reputo said:

Yup. I'm backing toe_head2001 with the request for an attached ZIP.

 

takeafile-error.png

 

Neither source code compiles as posted. Both give me this error in codeLab....

 

 

 

Maybe you have the error because you don't have the latest version of CodeLab - and you know what? I'm done with Takeafile now anyway. I'm heading back to Dropbox from now on.

Share this post


Link to post
Share on other sites

No. You posted Dropbox links to the zipped files. You can attach the files directly to the first post in this thread. This is the preferred method as users don't have to rely on any external host. Meaning the plugins will be available to forum users because they are actually attached to the forum.

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.

Guest
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