c_cpp 用于显示图像的BlinkScript内核,由任意纹理输入的数组过滤。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 用于显示图像的BlinkScript内核,由任意纹理输入的数组过滤。相关的知识,希望对你有一定的参考价值。

/*
Author: Mitchell Kehn
*/
kernel DotMatrixDisplay : ImageComputationKernel <ePixelWise>
{
    Image <eRead, eAccessRandom, eEdgeClamped> src;
    Image <eRead, eAccessRandom, eEdgeNone> tex;
    Image <eWrite> dst;

    local:
        float2 texSize;
        float2 format;
        float2 patternSize;

    param:
        float2 gap;
        float2 translate;
        bool pixelateOnly;
        int center_bias;
        bool smoothSubsample;

    void init() {
        format = float2(src.bounds.x2, src.bounds.y2);
        texSize = float2(tex.bounds.x2, tex.bounds.y2);
        patternSize = texSize + gap;
    }

    void define() {
        defineParam(translate, "translate", float2(0, 0));
    }

    void process(int2 pos) {
        float2 pos2d = float2(pos.x, pos.y);

        float2 texSamplePos = fmod(fmod((pos2d - translate), patternSize) + patternSize, patternSize);  // position within texture for sample

        float2 srcSamplePos = pos2d - texSamplePos + texSize/2;

        // sample the color behind this texture tile
        float4 colorsample;
        if (smoothSubsample) {
            colorsample = (bilinear(src, srcSamplePos.x, srcSamplePos.y) * (1 + center_bias)
                              + bilinear(src, srcSamplePos.x - texSize.x/2, srcSamplePos.y - texSize.y/2)
                              + bilinear(src, srcSamplePos.x - texSize.x/2, srcSamplePos.y + texSize.y/2)
                              + bilinear(src, srcSamplePos.x + texSize.x/2, srcSamplePos.y - texSize.y/2)
                              + bilinear(src, srcSamplePos.x + texSize.x/2, srcSamplePos.y + texSize.y/2)
                          )/(5 + center_bias);

        }  else {
            colorsample = bilinear(src, srcSamplePos.x, srcSamplePos.y);
        }


        if (pixelateOnly) {  // only show the pixelated color
            dst() = colorsample;

        }  else {  // show texture multiplied by the pixelated color
            if ((texSamplePos.x < texSize.x) && (texSamplePos.y < texSize.y)) {
                dst() = bilinear(tex, texSamplePos.x, texSamplePos.y) * colorsample;
            }  else {dst() = 0;}
        }
    }
};

以上是关于c_cpp 用于显示图像的BlinkScript内核,由任意纹理输入的数组过滤。的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 用于在图像上绘制面部标记的示例

c_cpp UIButton类别用于垂直居中标题标签和图像。文本标签位于图像下方。

c_cpp UIButton类别用于垂直居中标题标签和图像。文本标签位于图像下方。

c_cpp 【2】图像显示

c_cpp 【16】图像的载入,显示和输出

常用术语