有一个 Xamarin.ios 组件叫做 GPUImage,它最初是用 Objective-C 编写的,现在使用绑定以便在 C# 中运行。
我似乎无法得到其类 GPUImageThreeInputFilter
的可工作子类,该类应该接受一个字符串,然后将其处理为 GLSL。 以下是该类的样子:
using Foundation;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace GPUImage.Filters
{
[Register ("GPUImageThreeInputFilter", true)]
public class GPUImageThreeInputFilter : GPUImageTwoInputFilter
{
//
// Static Fields
//
[CompilerGenerated]
private static readonly IntPtr class_ptr;
[CompilerGenerated]
private static NSString _ThreeInputTextureVertexShaderString;
//
// Static Properties
//
[Field ("kGPUImageThreeInputTextureVertexShaderString", "__Internal")]
public static NSString ThreeInputTextureVertexShaderString {
get;
}
//
// Properties
//
public override IntPtr ClassHandle {
get;
}
//
// Constructors
//
[Export ("init"), EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
public GPUImageThreeInputFilter ();
[EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
protected GPUImageThreeInputFilter (NSObjectFlag t);
[EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
protected internal GPUImageThreeInputFilter (IntPtr handle);
//
// Methods
//
[Export ("disableThirdFrameCheck"), CompilerGenerated]
public virtual void DisableThirdFrameCheck ();
}
}
我已经创建了这个类的子类:
public class ImageProcess : GPUImageThreeInputFilter
{
public static new NSString ThreeInputTextureVertexShaderString =
((NSString)(" varying highp vec2 textureCoordinate;" +
" varying highp vec2 textureCoordinate2;" +
" varying highp vec2 textureCoordinate3;" +
"" +
" uniform sampler2D inputImageTexture;" +
" uniform sampler2D inputImageTexture2;" +
" uniform sampler2D inputImageTexture3;" +
"" +
" void main()" +
" {" +
" lowp vec4 one = texture2D(inputImageTexture, textureCoordinate);" +
" lowp vec4 two = texture2D(inputImageTexture2, textureCoordinate2);" +
" lowp vec4 three = texture2D(inputImageTexture3, textureCoordinate3);" +
" lowp vec4 out;" +
" float maxone = one.r + one.g + one.b;" +
" float maxtwo = two.r + two.g + two.b;" +
" float maxthree = three.r + three.g + three.b;" +
" if (maxone >= maxtwo && maxone >= maxthree)" +
" {" +
" out.r = one.r;" +
" out.b = one.b;" +
" out.g = one.g;" +
" };" +
" if (maxtwo >= maxone && maxtwo >= maxthree)" +
" {" +
" out.r = two.r;" +
" out.b = two.b;" +
" out.g = two.g;" +
" };" +
" if (maxthree >= maxtwo && maxthree >= maxone)" +
" {" +
" out.r = three.r;" +
" out.b = three.b;" +
" out.g = three.g;" +
" };" +
" out.a = 1.0;" +
" gl_FragColor = out;" +
" }"));
}
子类的使用:
var firstFilter = new ImageProcess();
first.AddTarget(firstFilter); // first, second, and third
first.ProcessImage(); // are unique GPUImagePicture
second.AddTarget(firstFilter); // values (pictures) defined
second.ProcessImage(); // somewhere else.
third.AddTarget(firstFilter);
third.ProcessImage();
firstFilter.UseNextFrameForImageCapture();
firstFilter.AddTarget(output); // outputs the end result to
// the screen
子类应从三个图像中获取最亮的像素并返回一个图像。然而,它只返回了第一个图像,因为该字符串在子类中没有注册。所以,我的问题是,这样的子类应该长成什么样子,它接受的NSString应该放在哪里?我以前没有遇到过这样的类。谢谢。
更新:我暂时使用和重新编写了这里找到的方法,但是所有针对处理后颜色数组的调用都需要大约四到五分钟,而这个方法最多只需要几秒钟,所以我仍将尝试解决这个问题。