about summary refs log tree commit diff
path: root/src/game/client/gc_skin.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-17 01:41:11 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-17 01:41:11 +0000
commit22360b5d795164df0c7a80a88f5b7cb1c230e6f0 (patch)
treedf7a55964ebd5a054689ed53ad7b1c56b4284314 /src/game/client/gc_skin.cpp
parent412958bae395c50892ce390b84e309ce827e9b13 (diff)
downloadzcatch-22360b5d795164df0c7a80a88f5b7cb1c230e6f0.tar.gz
zcatch-22360b5d795164df0c7a80a88f5b7cb1c230e6f0.zip
blood color depending on skin fixed
Diffstat (limited to 'src/game/client/gc_skin.cpp')
-rw-r--r--src/game/client/gc_skin.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/game/client/gc_skin.cpp b/src/game/client/gc_skin.cpp
index e3ed8b7c..7198665f 100644
--- a/src/game/client/gc_skin.cpp
+++ b/src/game/client/gc_skin.cpp
@@ -1,6 +1,7 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 #include <string.h>
 #include <stdio.h>
+#include <math.h>
 #include <engine/e_system.h>
 #include <engine/e_client_interface.h>
 #include "gc_skin.h"
@@ -33,8 +34,28 @@ static void skinscan(const char *name, int is_dir, void *user)
 	
 	skins[num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format);
 	
-	// create colorless version
+	int body_size = 96; // body size
 	unsigned char *d = (unsigned char *)info.data;
+	int pitch = info.width*4;
+
+	// dig out blood color
+	{
+		int colors[3] = {0};
+		for(int y = 0; y < body_size; y++)
+			for(int x = 0; x < body_size; x++)
+			{
+				if(d[y*pitch+x*4+3] > 128)
+				{
+					colors[0] += d[y*pitch+x*4+0];
+					colors[1] += d[y*pitch+x*4+1];
+					colors[2] += d[y*pitch+x*4+2];
+				}
+			}
+			
+		skins[num_skins].blood_color = normalize(vec3(colors[0], colors[1], colors[2]));
+	}
+	
+	// create colorless version
 	int step = info.format == IMG_RGBA ? 4 : 3;
 	
 	for(int i = 0; i < info.width*info.height; i++)
@@ -44,20 +65,11 @@ static void skinscan(const char *name, int is_dir, void *user)
 		d[i*step+1] = v;
 		d[i*step+2] = v;
 	}
+
 	
 	if(1)
 	{
-		int bs = 96; // body size
-		int pitch = info.width*4;
 		int freq[256] = {0};
-
-		for(int y = 0; y < bs; y++)
-			for(int x = 0; x < bs; x++)
-			{
-				if(d[y*pitch+x*4+3] > 128)
-					freq[d[y*pitch+x*4]]++;
-			}
-				
 		int org_weight = 0;
 		int new_weight = 192;
 		for(int i = 1; i < 256; i++)
@@ -68,8 +80,8 @@ static void skinscan(const char *name, int is_dir, void *user)
 
 		int inv_org_weight = 255-org_weight;
 		int inv_new_weight = 255-new_weight;
-		for(int y = 0; y < bs; y++)
-			for(int x = 0; x < bs; x++)
+		for(int y = 0; y < body_size; y++)
+			for(int x = 0; x < body_size; x++)
 			{
 				int v = d[y*pitch+x*4];
 				if(v <= org_weight)