|
CPU-based modifiers in EIE most likely will not look too foreign to those who have written image processing code before. Each image in EIE is 32-bit, with BGRA pixels. A CPU-based modifier will be given a pointer to the image data and be allowed to iterate through and modify pixels.
Like all other types of plug-ins in EIE, CPU-based modifiers are built by creating classes in a C# class library that inherit from base classes define in the EIE.Base namespace. In the case of CPU modifiers, the class should inherit from Base.CPUModifier and implement the abstract methods.
The best way to illustrate this is by example. The following C# class declaration defines a modifier that inverts the colors in the image:
using System;
using System.Collections.Generic;
using System.Text;
namespace EIE.Modifiers
{
internal class Invert : Base.CPUModifier
{
public override unsafe EIEReturnCode Execute(
uint* imgData,
int imgWidth, int imgHeight, byte[] sel, Document doc,
int imageIndex, Base.Modifier.ExecuteFlags flags)
{
int i;
int pxlCount = imgWidth * imgHeight;
byte a;
for (i = 0; i < pxlCount; i++)
{
// Backup the current alpha value
a = ((byte*)imgData)[3];
// (see notes below code)
ImageUtility.SelectionWeigh(imgData, ~(*imgData), sel[i]);
// Restore the alpha value
((byte*)imgData)[3] = a;
// Advance to the next pixel in the image
imgData++;
}
return EIEReturnCode.Success;
}
public override string Title
{
get
{
return "Invert colors";
}
}
}
}
|
Every pixel must be modified in accordance with its corresponding selection value. In this example the SelectionWeigh utility function does the appropriate weighted average given a pointer to the current pixel, the new pixel, and the selection value for that pixel.
Selection values for pixels in EIE are not booleans, they are 8-bit unsigned integers. This allows for more advanced selection and modification features in the editor. But, as you can see above, it introduces the requirement of appropriately averaging pixels in CPU-based modifiers. The available utility function is provided to make this easier.
Note that this example does not prompt the user for any configuration options. If you wish to do this, override the virtual "OptionsPrompt" method defined in Base.CPUModifier. This can be used to get options from the user. Make sure that you store options from the prompt in variables and use them in each Execute function. Do not do a dialog prompt from the Execute function as this will cause the prompt to come up multiple times when the user has multiple frames/layers selected in the image list.
Since multiple images can be selected at one time in EIE, the modifier system is set up so that it will prompt one time, and then apply the modifier to all selected images using the options from the prompt. This is why there is a options prompt function that is separated from the execution function.
|