使用GPUImage
我试图用不透明度复制Photoshop Lighten Blend Mode。不幸的是,使用GPUImageLightenBlendFilter
alpha通道无效。
布拉德确认alpha可能存在问题: GPUImage's GPUImageOpacityFilter not behaving as expected, doesn't change alpha channel
我使用尊重alpha值的CoreImage
成功复制了PS混合。
CIImage *ciImage1 = [[CIImage alloc] initWithImage:input1];
CIImage *ciImage2 = [[CIImage alloc] initWithImage:input2];
// Alpha adjustment for input1
CIFilter *alphaFilter = [CIFilter filterWithName:@"CIColorMatrix"];
CGFloat rgba[4] = { 0.0, 0.0, 0.0, 0.5 };
CIVector *alphaVector = [CIVector vectorWithValues:rgba count:4];
[alphaFilter setValue:alphaVector forKey:@"inputAVector"];
[alphaFilter setValue:ciImage1 forKey:kCIInputImageKey];
// Lighten blend
CIFilter *blendFilter = [CIFilter filterWithName:@"CILightenBlendMode"];
[blendFilter setValue:alphaFilter.outputImage forKey:kCIInputImageKey];
[blendFilter setValue:ciImage2 forKey:kCIInputBackgroundImageKey];
我尝试了GPUImage
的2个版本(他们正在使用不同的方法调整input1
的alpha值。)
GPUImagePicture *input1 = [[GPUImagePicture alloc] initWithImage:input1];
GPUImagePicture *input2 = [[GPUImagePicture alloc] initWithImage:input2];
// Alpha adjustment for input1
GPUImageOpacityFilter *alphaFilter = [GPUImageOpacityFilter new];
alphaFilter.opacity = 0.5;
[input1 addTarget:alphaFilter];
// Lighten blend
GPUImageLightenBlendFilter *blendFilter = [GPUImageLightenBlendFilter new];
[alphaFilter addTarget:blendFilter];
[input2 addTarget:blendFilter];
或:
GPUImagePicture *input1 = [[GPUImagePicture alloc] initWithImage:input1];
GPUImagePicture *input2 = [[GPUImagePicture alloc] initWithImage:input2];
// Alpha adjustment for input1
GPUImageColorMatrixFilter *alphaFilter = [GPUImageColorMatrixFilter new];
alphaFilter.colorMatrix = (GPUMatrix4x4) {
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.5 }
};
[input1 addTarget:alphaFilter];
// Lighten blend
GPUImageLightenBlendFilter *blendFilter = [GPUImageLightenBlendFilter new];
[alphaFilter addTarget:blendFilter];
[input2 addTarget:blendFilter];
两个GPUImage
实现都返回输出,就像input1
的alpha为1.0
一样。
我在互联网上查看了不同来源的Lighten Blending Mode文档,他们都使用这个公式:
max(blend, base)
查看GPUImageLightenBlendFilter
实施中的着色器,它也使用相同的公式:
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);
gl_FragColor = max(textureColor, textureColor2);
然而,似乎Photoshop和CoreImage
对alpha有一些额外的操作(可能类似于Gimp:https://github.com/GNOME/gimp/blob/783bbab8a889d4eba80b6a83f2e529937a73a471/app/operations/gimpoperationlightenonlymode.c)。
任何人都有想法如何在GPUImageLightenBlendFilter
公式中包含Alpha通道?
答案 0 :(得分:0)