summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-21 10:07:36 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-21 10:07:36 +0100
commit107dcbadef6e68cbcacb687c537f38f3bfca043c (patch)
tree8c251ac1031d78363edadb8972f4f02170c188bd
parentd470f992cd2f655d823cdac9a3d83d3037f643f8 (diff)
downloadcv-107dcbadef6e68cbcacb687c537f38f3bfca043c.tar.gz
cv-107dcbadef6e68cbcacb687c537f38f3bfca043c.tar.bz2
cv-107dcbadef6e68cbcacb687c537f38f3bfca043c.zip
wimmel_gl: Use luminance textures
-rw-r--r--wimmel.frag3
-rw-r--r--wimmel_gl.c58
2 files changed, 33 insertions, 28 deletions
diff --git a/wimmel.frag b/wimmel.frag
index 42b0139..22adcf9 100644
--- a/wimmel.frag
+++ b/wimmel.frag
@@ -17,7 +17,8 @@ main()
vec4 orig = texture2D(tex, v_texcoord + vec2(i,j));
vec4 match = texture2D(tex2, vec2(i, j) / srect.zw);
- diff += int(any(greaterThan(abs(orig - match), vec4(0.2))));
+ if (abs(orig.r - match.r) > 0.08)
+ ++diff;
}
}
diff --git a/wimmel_gl.c b/wimmel_gl.c
index 631be54..0f271af 100644
--- a/wimmel_gl.c
+++ b/wimmel_gl.c
@@ -128,12 +128,35 @@ align(int value, int alignment)
return (value + alignment - 1) & ~(alignment - 1);
}
+guchar *
+monochrome(GdkPixbuf *p)
+{
+ int x, y, width, height, nch;
+ guchar *d, *data;
+
+ width = gdk_pixbuf_get_width(p);
+ height = gdk_pixbuf_get_height(p);
+ nch = gdk_pixbuf_get_n_channels(p);
+
+ data = malloc(width * height);
+ if (!data)
+ return NULL;
+
+ for (y = 0; y < height; ++y) {
+ d = gdk_pixbuf_get_pixels(p) + y * gdk_pixbuf_get_rowstride(p);
+ for (x = 0; x < width; ++x, d += nch) {
+ data[y*width + x] = MAX(d[0], MAX(d[1], d[2]));
+ }
+ }
+
+ return data;
+}
+
static void
create_texture(GdkPixbuf *pixbuf, GLuint *texture, int i)
{
- guchar *data, *buffer = NULL;
- int width, height, stride, nch, new_stride;
- GLenum format;
+ guchar *data;
+ int width, height;
glActiveTexture(GL_TEXTURE0 + i);
glGenTextures(1, texture);
@@ -143,34 +166,15 @@ create_texture(GdkPixbuf *pixbuf, GLuint *texture, int i)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- data = gdk_pixbuf_get_pixels(pixbuf);
-
- if (gdk_pixbuf_get_has_alpha(pixbuf))
- format = GL_RGBA;
- else
- format = GL_RGB;
-
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
- stride = gdk_pixbuf_get_rowstride(pixbuf);
- nch = gdk_pixbuf_get_n_channels(pixbuf);
-
- new_stride = align(nch * width, 4);
-
- if (stride != new_stride) {
- buffer = malloc(new_stride * height);
- for (int row = 0; row < height; ++row)
- memcpy(buffer + row * new_stride,
- data + row * stride,
- width * nch);
- data = buffer;
- }
+ data = monochrome(pixbuf);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
width, height, 0,
- format, GL_UNSIGNED_BYTE, data);
- if (buffer != NULL)
- free(buffer);
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
+ free(data);
}
static void