I have been researching the CustomEffectBase
class on the Nokia Imaging SDK, and I've worked with adding these in the RealtimeFilterDemo sample they have, but I'd like to add an effect to their Filter Explorer Demo as well. I am not sure how to do this. I have created a custom effect using the CustomEffectBase
InvertCustomEffect.cs
public class InvertCustomEffect : CustomEffectBase
{
public InvertCustomEffect(IImageProvider source) : base(source)
{
}
protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
{
var sourcePixels = sourcePixelRegion.ImagePixels;
var targetPixels = targetPixelRegion.ImagePixels;
sourcePixelRegion.ForEachRow((index, width, position) =>
{
for (int x = 0; x < width; ++x, ++index)
{
uint pixel = sourcePixels[index];
uint blue = pixel & 0x000000ff; // blue color component
uint green = (pixel & 0x0000ff00) >> 8; // green color component
uint red = (pixel & 0x00ff0000) >> 16; // red color component
uint average = (uint)(0.0722 * blue + 0.7152 * green + 0.2126 * red); // weighted average component
uint grayscale = 0xff000000 | average | (average << 8) | (average << 16); // use average for each color component
targetPixels[index] = ~grayscale; // use inverse grayscale
}
});
}
}
which is a basic grayscale inverted effect. In the Filter Explorer project, there is a Model called FilterModel.cs in which the effect to be performed is input. The problem is, the standard effects that come with the SDK have arguments such as ints and doubles which are just parameters to adjust the effects, but the class I created which extends the CustomEffectBase requires IImageProvider source
as an argument. This is where I am stuck, and I do not know how to implement this within the Filter Explorer project and progress from here?
FilterModel.cs
public class InvertGrayscaleFilterModel : FilterModel
{
public InvertGrayscaleFilterModel()
{
Name = "Invert Grayscale";
}
[XmlIgnore]
public override Queue<IFilter> Components
{
get
{
Queue<IFilter> components = new Queue<IFilter>();
components.Enqueue(new FilterAppTest.Filters.InvertCustomEffect()); //error requiring IImageProvider source
return components;
}
}
}