首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用着色器的RGB到YUV

使用着色器的RGB到YUV
EN

Stack Overflow用户
提问于 2015-10-26 06:45:37
回答 1查看 2.3K关注 0票数 1

我想使用片段着色器将RGB转换为YUV420P使用着色器。

1、计算出当前纹理颜色的坐标。

2,我计算了4Y,并把它放在当前的颜色。

我的代码:

代码语言:javascript
复制
    precision mediump float;
    varying vec2 vTextureCoord;
    uniform sampler2D tex;
    uniform float width;
    uniform float height;
    uniform float offset;
    uniform vec3 scal;

    void main(void) {
        vec2 nowTxtPos = vTextureCoord;
        vec2 size = vec2(width, height);
    // y
        if(nowTxtPos.y<0.25){
    // y1 postion
            vec2 now_pos = nowTxtPos * size;
            vec2 basePos = now_pos * vec2(4.0,4.0);
            float addY = float(int(basePos.x / width));
            basePos.x = basePos.x - addY * width;
            basePos.y += addY;

            float y1,y2,y3,y4;
            vec2 samplingPos = basePos / size;
            vec4 texel = texture2D(tex, samplingPos);
            y1 = dot(texel.rgb, scal);
            y1 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y2 = dot(texel.rgb, scal);
            y2 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y3 = dot(texel.rgb, scal);
            y3 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y4 = dot(texel.rgb, scal);
            y4 += offset;

            gl_FragColor = vec4(y1, y2, y3, y4);
        }
    }

图片(YUV420P):

图片

放大后图片

它有别名。我也不知道原因。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-29 03:36:17

我已经解决了。因为计算精度不够。

在这里编辑:

精度中等浮子;“->”精度高浮子;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33339874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档