Jump to content

What is and isn't possible when writing plugins


Simon Brown

Recommended Posts

 

Non plugin authors often don't know what is and isn't possible when writing plugins - so hopefully this should be helpful to users wishing to suggest plugins.

"Classic" Effects (those deriving from Effect or PropertyBasedEffect)

  • Effects can only access the current layer.
    • However, BitmapEffects and GpuEffects can access all layers.
  • Effects can only access the current image.
  • Effects cannot know or change the blend mode or transparency of a layer.
    • However, BitmapEffects and GpuEffects can.
  • Effects can blend two images using transparency and blend modes.
  • Effects can read the whole layer, even if part of it is selected.
  • If part of a layer is selected, effects can only change that part.
    • However, BitmapEffects and GpuEffects can write outside the selection if they specify the appropriate flag in their OnInitializeRenderInfo() method
  • Although effects can't be tools or anything, they can show a new dialog to draw on.
  • Effects can save files, but only with the information they have (see above) and they can't make the file they save the current FileName.
  • Effects have no control over the UI other than the ability to add items and categories to the effects and adjustments menus.
  • Effects can not change the shape of the selection or which pixels are selected.
  • Most effects need to be heavily modified before they can run outside Paint.NET.
  • Effects can open files and read them from your harddrive or Internet URL.
  • Effects can read the Windows clipboard.

As of paint.net 4.0.6:

  • Effects can read all of the color values in the current and default palette
  • Effects can add a [?] button to the effect's IndirectUI for adding a help file

As of paint.net 5.0:

  • BitmapEffect and GpuEffect are the new, modernized effect base classes.
    • They can read from any layer.
    • They can know the name, blend mode, and transparency of each layer.
    • They can write outside the selection if they specify the appropriate flag in their OnInitializeRenderInfo() method.
    • GpuEffect runs on the GPU, and is significantly faster for many things.
    • They can read the image's ("document's") metadata (EXIF, XMP, and IPTC).

FileTypes (Opening)

  • FileTypes don't know the location of the image they're opening.
  • FileTypes can create as many layers as they want and change opacity and blend modes.
  • FileTypes must open some image.
  • FileTypes have no control over the open dialog.

FileTypes (Saving)

  • FileTypes don't know the location of the image they're saving to.
  • FileTypes can read all layers, opacity and blend modes.
  • FileTypes have to save a file unless the user clicks "cancel," even if it is empty - this is frowned upon by Rick.
  • FileTypes have no control over the save dialog.

I hope this helps.

  • Upvote 1
KaHuc.png
Link to comment
Share on other sites

Nice work. I'll definitely link to this when people post crazy ideas. :-)

A few notes you might want to make, though:

Plugins can put menu options in the Effects and Adjustments menu.

Plugins can not make any changes to the Paint.NET user interface outside their dialog and their menu entry.

Plugins can not run without Paint.NET, although they are able to connect to programs that can (such as Batch Processor and wrappers).

Also, if I'm not mistaken, Rick frowns on saving an empty file with a filetype plugin (such as with the upload-to idea).

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

Link to comment
Share on other sites

  • 4 weeks later...

Is it possible to let an effect save one layer and then let the user runs the effect over the next layer and let the effect combine them some how? (not that I actually know how this could be done)

yhsjjie.png

History repeats itself, because nobody was paying attention the first time.

Link to comment
Share on other sites

Unless the user gives it that information ofcourse.

yhsjjie.png

History repeats itself, because nobody was paying attention the first time.

Link to comment
Share on other sites

  • 1 month later...

A couple more comments on file types;

Filetypes have no control over the open/save dialog but can present their own dialog as well.

When opening, a file type plugin can return null or a 0 size document (don't know which is preferred) if the user cancels a custom dialog.

I have not found any good way to cancel a file type save dialog. I always end up with a zero byte file on disk.

The Paint.net jpg dialog allows a cancel, but plugins don't seem to be able to be consistent with this :(

Don't know what plugin to use? Try looking in the plugin gallery

Link to comment
Share on other sites

  • 9 months later...
  • 5 years later...
  • toe_head2001 pinned this topic
  • 2 years later...
14 minutes ago, sbhambra said:

Can a plugin save flattened images using combinations of layers? I see that plugins cannot create layers.

 

A FileType plugin can. An Effect plugin can not.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

  • 1 year later...

Hi there!

Are effects able to read out a selection's dimensions in inch or millimeter and resize an image to a certain dimensions? Or: can effects read out the selection's dimensions in pixel and the resolution of the whole image in dpi and calculate a factor for resizing?

Background: I need to resize companies' logos to prepare them to get converted into embroidery programms. So certain elements (for example text) must not be below a height of 5 millimeters. For example: I want to make a selection around the letter "M" (which has a height of 16 millimeters) inside a random logo and enter the desired height of 5 millimeters -> the whole image will be reseized to 31,25% to meet the requirement of the selected letter "M" being 5 millimeters in height.

Thanks in advance for answering
Oli

  • Thanks 1
Link to comment
Share on other sites

Since paint.net 4.2.16 DocumentResolution in the EffectEnvironmentParameters class contains the resolution of a document.

But plugins are not able to change the dimension of a layer (or the image).

If you like to scale the pixels of the whole image and keep the current dpi value then you can do this via Image->Canvas Size.

If you like to scale the dpi value and keep the pixels then set the new dpi value in Image->Resize.

The status bar provides you information about the size of the selection. You can change its unit via the small popup in the status bar (px, cm, in).

midoras signature.gif

Link to comment
Share on other sites

14 hours ago, Oli said:

So I will have to stick to my calculator until I find a better possibility.

 

One possible approach that occurs to me to write a plugin that copies the image scaled to the desired size onto the clipboard, where it can be pasted into a new image. I have no idea if that works out for what you want to accomplish.

Link to comment
Share on other sites

If you're going to use the clipboard in your plugin, be sure to make use of the `IClipboardService`, e.g. `this.Services.GetService<IClipboardService>()`. There are a lot of gotchas and hazards in using the clipboard, and the service gets rid of them for you.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

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.

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.

×
×
  • Create New...