【发布时间】:2016-10-04 22:15:15
【问题描述】:
GPUImage 的 LookupFilter 使用 512x512 的 RGB 像素图。当过滤器执行时,它会在此图像的修改版本与原始版本之间进行比较,并推断图像过滤器。
过滤器代码非常简单。这是一个摘录,因此您可以看到发生了什么:
void main()
{
highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
highp float blueColor = textureColor.b * 63.0;
highp vec2 quad1;
quad1.y = floor(floor(blueColor) / 8.0);
quad1.x = floor(blueColor) - (quad1.y * 8.0);
highp vec2 quad2;
quad2.y = floor(ceil(blueColor) / 8.0);
quad2.x = ceil(blueColor) - (quad2.y * 8.0);
highp vec2 texPos1;
texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);
texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);
highp vec2 texPos2;
texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);
texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);
lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1);
lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);
lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));
gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity);
}
);
看到过滤器映射依赖于 512x512 图像的位置吗?
我正在寻找将颜色深度提高 4 倍的方法,改用 1024x1024 源图像,但我不确定这个查找滤镜图像最初是如何生成的。
可以在代码中生成这样的东西吗?如果可以,我意识到这是一个非常广泛的问题,但我该怎么做呢?如果无法在代码中生成,我有什么选择?
——
更新:
原来原始 LUT 生成代码一直包含在头文件中。这里有问题的部分来自头文件:
查找纹理组织为 64x64 像素的 8x8 四边形,代表所有可能的 RGB 颜色:
64x64 如何是所有可能的 RGB 通道的映射? 64³ = 262,144,但这仅占 RGB 假定的 24 位容量的 1/64,即 64³ (16,777,216)。这里发生了什么?我错过了这个 LUT 的工作方式吗?我们如何仅用 1/64 的数据计算所有可能的 RGB 颜色?
for (int by = 0; by < 8; by++) {
for (int bx = 0; bx < 8; bx++) {
for (int g = 0; g < 64; g++) {
for (int r = 0; r < 64; r++) {
image.setPixel(r + bx * 64, g + by * 64, qRgb((int)(r * 255.0 / 63.0 + 0.5),
(int)(g * 255.0 / 63.0 + 0.5),
(int)((bx + by * 8.0) * 255.0 / 63.0 + 0.5)));
}
}
}
}
【问题讨论】:
标签: ios macos opengl-es gpuimage