Jump to content

How to access all effects programatically


Recommended Posts

Is it possible to get a list of all effects, including effects which are user-installed, and access or execute them in some way? I know that Pyrochild has a random effect plugin that presumably works this way. I want to make a plugin that saves the current image, executes a desired effect of the user's choice, then overwrites the result for the red/green/blue/hue/sat/val/alpha channels, in order to simulate channel locks. I think there's an Effect Lab that also accesses effects, but I don't know if it can access user-installed effects or not.

 

Also, the list of effects should be obtained in a fair way like Rick wants.

Thanks in advance.

Link to comment
Share on other sites

There isn't a supported way to do this. Internally there's an EffectsCollection class but this functionality was never intentionally provided for plugins to use.

 

pyrochild's effect might still be using it since it was compiled a long time ago (or it might just be broken now), or he may have replicated that functionality himself.

 

Composability has not been a strong point of the effect system.

  • Upvote 2

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

ScriptLab gathers effect types this way:

        public static IEnumerable<Type> GatherEffects()
        {
            List<Assembly> assemblies = new List<Assembly>();
            List<Type> ec = new List<Type>();

            // PaintDotNet.Effects.dll
            assemblies.Add(Assembly.GetAssembly(typeof(Effect)));

            // TARGETDIR\Effects\*.dll
            string homeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string effectsDir = Path.Combine(homeDir, "Effects");
            bool dirExists;

            try
            {
                dirExists = Directory.Exists(effectsDir);
            }

            catch
            {
                dirExists = false;
            }

            if (dirExists)
            {
                string fileSpec = "*.dll";
                string[] filePaths = Directory.GetFiles(effectsDir, fileSpec);

                foreach (string filePath in filePaths)
                {
                    Assembly pluginAssembly = null;

                    try
                    {
                        pluginAssembly = Assembly.LoadFrom(filePath);
                        assemblies.Add(pluginAssembly);
                    }
                    catch { }
                }
            }

            foreach (Assembly a in assemblies)
            {
                try
                {
                    foreach (Type t in a.GetTypes())
                    {
                        if (t.IsSubclassOf(typeof(Effect)) && !t.IsAbstract && !t.IsObsolete(false))
                        {
                            ec.Add(t);
                        }
                    }
                }
                catch { }
            }
            return ec;
        }
I think this code was copied from Paint.NET's source code back when the source was available (and modified since), so it's not accessing PdN's internal EffectsCollection code.

After instantiating an Effect from the Type collection, you need to check for effect.Category == EffectCategory.DoNotDisplay.

There's an effect with that category that you can display - the RotateZoomEffect. It's marked as DoNotDisplay so it can be manually placed in the Layers menu instead of Effects.

If you want to render an effect multithreaded like Paint.NET does you'll need to check for effect.CheckForEffectFlags(EffectFlags.SingleRenderCall) and effect.CheckForEffectFlags(EffectFlags.SingleThreaded). Or just always render on 1 thread but performance will suffer compared to running an effect natively.

  • Upvote 4

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

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.

 Share

×
×
  • Create New...