~eliasnaur/gio-patches

gio: Adding native YUV support for paint.ImageOp v1 PROPOSED

~dejadeja9
This is a patch set to add native YUV (YCbCr) support for paint.ImageOp
as a foundation for rendering videos in gio.
patch 1 will add a yuv2rgb
basic function and expose it to a new texture
patch 2 will expose an
UploadPixels() interface so that channel data can be uploaded to
textures per channel.
patch 3 will update gpu.go to use the new
interfaces.

Deja Deja (1):
  add yuv2rgb to the shader functions

 gpu/shaders/blit.frag               |  2 ++
 gpu/shaders/common.inc              | 13 +++++++++++++
 gpu/shaders/cover.frag              |  2 ++
 internal/cmd/convertshaders/main.go | 10 +++++++++-
 4 files changed, 26 insertions(+), 1 deletion(-)

-- 
2.26.2
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/11389/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio 1/1] add yuv2rgb to the shader functions Export this patch

~dejadeja9
From: Deja Deja <dejadejade9@outlook.com>

---
 gpu/shaders/blit.frag               |  2 ++
 gpu/shaders/common.inc              | 13 +++++++++++++
 gpu/shaders/cover.frag              |  2 ++
 internal/cmd/convertshaders/main.go | 10 +++++++++-
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gpu/shaders/blit.frag b/gpu/shaders/blit.frag
index 907f010..f9f0344 100644
--- a/gpu/shaders/blit.frag
+++ b/gpu/shaders/blit.frag
@@ -4,6 +4,8 @@

precision mediump float;

#include <common.inc>

layout(location=0) in vec2 vUV;

{{.Header}}
diff --git a/gpu/shaders/common.inc b/gpu/shaders/common.inc
index a1a3dd9..a846430 100644
--- a/gpu/shaders/common.inc
+++ b/gpu/shaders/common.inc
@@ -49,3 +49,16 @@ vec4 toClipSpace(vec4 pos) {
vec3 transform3x2(m3x2 t, vec3 v) {
	return vec3(dot(t.r0, v), dot(t.r1, v), dot(vec3(0.0, 0.0, 1.0), v));
}

vec4 yuv2rgb(in sampler2D ytex, in sampler2D utex, in sampler2D vtex, in vec2 vUV) {
	float r,g,b,y,u,v;
	y = (texture(ytex, vUV).r - .0625) * 1.1643;
	u = texture(utex, vUV).r - 0.5;
	v = texture(vtex, vUV).r - 0.5;

	r = y+1.5958*v;
	g = y-0.39173*u-0.81290*v;
	b = y+2.017*u;

	return vec4(r, g, b, 1.0);
}
diff --git a/gpu/shaders/cover.frag b/gpu/shaders/cover.frag
index 5a051f8..1c98173 100644
--- a/gpu/shaders/cover.frag
+++ b/gpu/shaders/cover.frag
@@ -4,6 +4,8 @@

precision mediump float;

#include "common.inc"

{{.Header}}

// Use high precision to be pixel accurate for
diff --git a/internal/cmd/convertshaders/main.go b/internal/cmd/convertshaders/main.go
index 250137e..915a8fd 100644
--- a/internal/cmd/convertshaders/main.go
+++ b/internal/cmd/convertshaders/main.go
@@ -70,7 +70,7 @@ func generate() error {
		if ext := filepath.Ext(shader); ext != ".vert" && ext != ".frag" {
			continue
		}
		const nvariants = 2
		const nvariants = 3
		var variants [nvariants]struct {
			backend.ShaderSources
			hlslSrc string
@@ -84,6 +84,14 @@ func generate() error {
				FetchColorExpr: `texture(tex, vUV)`,
				Header:         `layout(binding=0) uniform sampler2D tex;`,
			},
			{
				FetchColorExpr: `yuv2rgb(ytex, utex, vtex, vUV)`,
				Header: `
				layout(binding=0) uniform sampler2D ytex;
				layout(binding=1) uniform sampler2D utex;
				layout(binding=2) uniform sampler2D vtex;
				`,
			},
		}
		for i := range args {
			glsl100es, reflect, err := convertShader(tmp, glslcc, shader, "gles", "100", &args[i], false)
-- 
2.26.2