From f5afb40d66d86025ebdda97075f526436e5c7219 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Thu, 17 Jul 2008 20:11:13 +0000 Subject: [PATCH] added a desaturation method based on Luminance, and relative functions. --- vcg/complex/trimesh/update/color.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vcg/complex/trimesh/update/color.h b/vcg/complex/trimesh/update/color.h index 1158d79d..fd9b4a8c 100644 --- a/vcg/complex/trimesh/update/color.h +++ b/vcg/complex/trimesh/update/color.h @@ -601,7 +601,7 @@ static int Desaturation(UpdateMeshType &m, int method, const bool ProcessSelecte return counter; } -enum DesaturationMethods {M_LIGHTNESS = 0, M_MEAN = 1}; +enum DesaturationMethods {M_LIGHTNESS = 0, M_LUMINANCE = 1, M_MEAN = 2}; static Color4b ColorDesaturate(Color4b c, int method) { @@ -614,6 +614,10 @@ static Color4b ColorDesaturate(Color4b c, int method) int val = (int)ComputeMeanLightness(c); return Color4b( val, val, val, 255); } + case M_LUMINANCE:{ + int val = (int)ComputeLuminance(c); + return Color4b( val, val, val, 255); + } default: assert(0); } } @@ -621,6 +625,11 @@ static Color4b ColorDesaturate(Color4b c, int method) static float ComputeMeanLightness(Color4b c) { return float(c[0]+c[1]+c[2])/3.0f; +} + +static float ComputeLuminance(Color4b c) +{ + return float(0.2126f*c[0]+0.7152f*c[1]+0.0722f*c[2]); } static int Equalize(UpdateMeshType &m, unsigned int rgbMask, const bool ProcessSelected=false)