我一直在研究CustomEffectBase
Nokia Imaging SDK 上的课程,并且我已经在他们拥有的 RealtimeFilterDemo 示例中添加了这些,但我也想在他们的 Filter Explorer Demo 中添加一个效果。我不知道该怎么做。我使用 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
}
});
}
}
这是一个基本的灰度反转效果。在Filter Explorer项目中,有一个名为FilterModel.cs的Model,其中输入了要执行的效果。问题是,SDK 附带的标准效果具有参数,例如 int 和 doubles,它们只是调整效果的参数,但我创建的扩展 CustomEffectBase 的类需要IImageProvider source
作为参数。这就是我卡住的地方,我不知道如何在 Filter Explorer 项目中实现它并从这里取得进展?
过滤器模型.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;
}
}
}