about summary refs log tree commit diff
path: root/src/engine/client/gfx.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-29 15:38:20 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-29 15:38:20 +0000
commitdc612d4fe478f52d66858f368a0a4dcee3e0c1b3 (patch)
treea03942d4461fcb4010b829de185899a6d4d46aa7 /src/engine/client/gfx.cpp
parentf8d037ee4877810ea113505fd5cf618677ebfa12 (diff)
downloadzcatch-dc612d4fe478f52d66858f368a0a4dcee3e0c1b3.tar.gz
zcatch-dc612d4fe478f52d66858f368a0a4dcee3e0c1b3.zip
fixed better downsampling
Diffstat (limited to 'src/engine/client/gfx.cpp')
-rw-r--r--src/engine/client/gfx.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp
index f5983598..397b25dc 100644
--- a/src/engine/client/gfx.cpp
+++ b/src/engine/client/gfx.cpp
@@ -306,6 +306,14 @@ void gfx_blend_additive()
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 }
 
+static unsigned char sample(int w, int h, const unsigned char *data, int u, int v, int offset)
+{
+	return (data[(v*w+u)*4+offset]+
+	data[(v*w+u+1)*4+offset]+
+	data[((v+1)*w+u)*4+offset]+
+	data[((v+1)*w+u+1)*4+offset])/4;
+}
+
 int gfx_load_texture_raw(int w, int h, int format, const void *data)
 {
 	// grab texture
@@ -316,23 +324,21 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data)
 	// resample if needed
 	unsigned char *texdata = (unsigned char *)data;
 	unsigned char *tmpdata = 0;
-	if(config.gfx_texture_quality==0)
+	if(1 || config.gfx_texture_quality==0)
 	{
 		if(w > 16 && h > 16 && format == IMG_RGBA)
 		{
-			int amount = 2;
-			int pitch = w*4;
-			w/=amount;
-			h/=amount;
+			w/=2;
+			h/=2;
 			unsigned char *tmpdata = (unsigned char *)mem_alloc(w*h*4, 1);
 			int c = 0;
 			for(int y = 0; y < h; y++)
 				for(int x = 0; x < w; x++, c++)
 				{
-					tmpdata[c*4] = texdata[(y*amount*pitch+x*amount*4)];
-					tmpdata[c*4+1] = texdata[(y*amount*pitch+x*amount*4)+1];
-					tmpdata[c*4+2] = texdata[(y*amount*pitch+x*amount*4)+2];
-					tmpdata[c*4+3] = texdata[(y*amount*pitch+x*amount*4)+3];
+					tmpdata[c*4] = sample(w*2, h*2, texdata, x*2,y*2, 0);
+					tmpdata[c*4+1] = sample(w*2, h*2, texdata, x*2,y*2, 1);
+					tmpdata[c*4+2] = sample(w*2, h*2, texdata, x*2,y*2, 2);
+					tmpdata[c*4+3] = sample(w*2, h*2, texdata, x*2,y*2, 3);
 				}
 			texdata = tmpdata;
 		}