[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47837] trunk/blender/source/blender: add rgb_to_luma_y(), was being done inline in many places.

Campbell Barton ideasman42 at gmail.com
Wed Jun 13 17:05:50 CEST 2012


Revision: 47837
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47837
Author:   campbellbarton
Date:     2012-06-13 15:05:42 +0000 (Wed, 13 Jun 2012)
Log Message:
-----------
add rgb_to_luma_y(), was being done inline in many places.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_TonemapOperation.cpp
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_glare.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_tonemap.c
    trunk/blender/source/blender/render/intern/source/volumetric.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-06-13 15:05:42 UTC (rev 47837)
@@ -78,6 +78,8 @@
 unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]);
 float rgb_to_luma(const float rgb[3]);
 unsigned char rgb_to_luma_byte(const unsigned char rgb[3]);
+float rgb_to_luma_y(const float rgb[3]);
+float rgb_to_luma_rec709_byte(const unsigned char rgb[3]);
 
 /**************** Profile Transformations *****************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2012-06-13 15:05:42 UTC (rev 47837)
@@ -516,6 +516,17 @@
 	return (76 * (unsigned short) rgb[0] + 150 * (unsigned short) rgb[1] + 29 * (unsigned short) rgb[2]) / 255;
 }
 
+/* gamma-corrected RGB --> CIE XYZ
+ * for this function we only get the Y component
+ * see: http://software.intel.com/sites/products/documentation/hpc/ipp/ippi/ippi_ch6/ch6_color_models.html
+ *
+ * also known as:
+ * luminance rec. 709 */
+float rgb_to_luma_y(const float rgb[3])
+{
+	return 0.212671f * rgb[0] + 0.71516f * rgb[1] + 0.072169f * rgb[2];
+}
+
 /* ********************************* lift/gamma/gain / ASC-CDL conversion ********************************* */
 
 void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power)
@@ -648,9 +659,9 @@
 	g = inverse_srgb_companding(g) * 100.0f;
 	b = inverse_srgb_companding(b) * 100.0f;
 
-	*x = r * 0.4124 + g * 0.3576 + b * 0.1805;
-	*y = r * 0.2126 + g * 0.7152 + b * 0.0722;
-	*z = r * 0.0193 + g * 0.1192 + b * 0.9505;
+	*x = r * 0.412453f + g * 0.357580f + b * 0.180423f;
+	*y = r * 0.212671f + g * 0.715160f + b * 0.072169f;
+	*z = r * 0.019334f + g * 0.119193f + b * 0.950227f;
 }
 
 static float xyz_to_lab_component(float v)

Modified: trunk/blender/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp	2012-06-13 15:05:42 UTC (rev 47837)
@@ -89,12 +89,13 @@
 	gain *= (levelShadows*this->data->shadows.gain)+(levelMidtones*this->data->midtones.gain)+(levelHighlights*this->data->highlights.gain);
 	lift += (levelShadows*this->data->shadows.lift)+(levelMidtones*this->data->midtones.lift)+(levelHighlights*this->data->highlights.lift);
 	
+	float invgamma = 1.0f / gamma;
+	float luma = rgb_to_luma_y(inputImageColor);
+
 	r = inputImageColor[0];
 	g = inputImageColor[1];
 	b = inputImageColor[2];
-	
-	float invgamma = 1.0f / gamma;
-	float luma = 0.2126f * r + 0.7152f * g + 0.0722f * b;
+
 	r = (luma + saturation * (r - luma));
 	g = (luma + saturation * (g - luma));
 	b = (luma + saturation * (b - luma));

Modified: trunk/blender/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp	2012-06-13 15:05:42 UTC (rev 47837)
@@ -37,7 +37,7 @@
 void GlareThresholdOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
 {
 	this->inputProgram->read(color, x, y, sampler, inputBuffers);
-	if ((0.212671f * color[0] + 0.71516f * color[1] + 0.072169f * color[2]) >= threshold) {
+	if (rgb_to_luma_y(color) >= threshold) {
 		color[0] -= threshold, color[1] -= threshold, color[2] -= threshold;
 		color[0] = MAX2(color[0], 0.0f);
 		color[1] = MAX2(color[1], 0.0f);

Modified: trunk/blender/source/blender/compositor/operations/COM_TonemapOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_TonemapOperation.cpp	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/compositor/operations/COM_TonemapOperation.cpp	2012-06-13 15:05:42 UTC (rev 47837)
@@ -75,7 +75,7 @@
 	float output[4];
 	this->imageReader->read(output, x, y, inputBuffers, NULL);
 
-	const float L = 0.212671f * output[0] + 0.71516f * output[1] + 0.072169f * output[2];
+	const float L = rgb_to_luma_y(output);
 	float I_l = output[0] + ic * (L - output[0]);
 	float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]);
 	float I_a = I_l + ia * (I_g - I_l);
@@ -133,7 +133,7 @@
 		float Lav = 0.f;
 		float cav[4] = {0.0f,0.0f,0.0f,0.0f};
 		while (p--) {
-			float L = 0.212671f * bc[0] + 0.71516f * bc[1] + 0.072169f * bc[2];
+			float L = rgb_to_luma_y(bc);
 			Lav += L;
 			add_v3_v3(cav, bc);
 			lsum += logf(MAX2(L, 0.0f) + 1e-5f);

Modified: trunk/blender/source/blender/nodes/composite/nodes/node_composite_glare.c
===================================================================
--- trunk/blender/source/blender/nodes/composite/nodes/node_composite_glare.c	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/nodes/composite/nodes/node_composite_glare.c	2012-06-13 15:05:42 UTC (rev 47837)
@@ -107,7 +107,7 @@
 	float* cr = bsrc->rect;
 	for (y=0; y<bsrc->y; ++y)
 		for (x=0; x<bsrc->x; ++x, cr+=4) {
-			if ((0.212671f*cr[0] + 0.71516f*cr[1] + 0.072169f*cr[2]) >= threshold) {
+			if (rgb_to_luma_y(cr) >= threshold) {
 				cr[0] -= threshold, cr[1] -= threshold, cr[2] -= threshold;
 				cr[0] = MAX2(cr[0], 0.f);
 				cr[1] = MAX2(cr[1], 0.f);

Modified: trunk/blender/source/blender/nodes/composite/nodes/node_composite_tonemap.c
===================================================================
--- trunk/blender/source/blender/nodes/composite/nodes/node_composite_tonemap.c	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/nodes/composite/nodes/node_composite_tonemap.c	2012-06-13 15:05:42 UTC (rev 47837)
@@ -51,7 +51,7 @@
 	const float sc = 1.f/(src->x*src->y);
 	*Lav = 0.f;
 	while (p--) {
-		float L = 0.212671f*bc[0][0] + 0.71516f*bc[0][1] + 0.072169f*bc[0][2];
+		float L = rgb_to_luma_y(bc[0]);
 		*Lav += L;
 		fRGB_add(Cav, bc[0]);
 		lsum += (float)log((double)MAX2(L, 0.0) + 1e-5);
@@ -86,7 +86,7 @@
 			fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type];
 			fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type];
 			for (x=0; x<src->x; ++x) {
-				const float L = 0.212671f*sp[x][0] + 0.71516f*sp[x][1] + 0.072169f*sp[x][2];
+				const float L = rgb_to_luma_y(sp[x]);
 				float I_l = sp[x][0] + ic*(L - sp[x][0]);
 				float I_g = Cav[0] + ic*(Lav - Cav[0]);
 				float I_a = I_l + ia*(I_g - I_l);

Modified: trunk/blender/source/blender/render/intern/source/volumetric.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/volumetric.c	2012-06-13 14:51:07 UTC (rev 47836)
+++ trunk/blender/source/blender/render/intern/source/volumetric.c	2012-06-13 15:05:42 UTC (rev 47837)
@@ -68,12 +68,6 @@
 extern struct Render R;
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 
-/* luminance rec. 709 */
-BLI_INLINE float luminance(const float col[3])
-{
-	return (0.212671f * col[0] + 0.71516f * col[1] + 0.072169f * col[2]);
-}
-
 /* tracing */
 static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3])
 {
@@ -502,7 +496,7 @@
 		
 		if (shi->mat->vol.shadeflag & MA_VOL_RECV_EXT_SHADOW) {
 			mul_v3_fl(lacol, vol_get_shadow(shi, lar, co));
-			if (luminance(lacol) < 0.001f) return;
+			if (rgb_to_luma_y(lacol) < 0.001f) return;
 		}
 		
 		/* find minimum of volume bounds, or lamp coord */
@@ -536,7 +530,7 @@
 		}
 	}
 	
-	if (luminance(lacol) < 0.001f) return;
+	if (rgb_to_luma_y(lacol) < 0.001f) return;
 	
 	normalize_v3(lv);
 	p = vol_get_phasefunc(shi, shi->mat->vol.asymmetry, view, lv);
@@ -618,7 +612,7 @@
 			
 			if (t0 > t1 * 0.25f) {
 				/* only use depth cutoff after we've traced a little way into the volume */
-				if (luminance(tr) < shi->mat->vol.depth_cutoff) break;
+				if (rgb_to_luma_y(tr) < shi->mat->vol.depth_cutoff) break;
 			}
 			
 			vol_get_emission(shi, emit_col, p);
@@ -647,7 +641,7 @@
 	add_v3_v3(col, radiance);
 	
 	/* alpha <-- transmission luminance */
-	col[3] = 1.0f - luminance(tr);
+	col[3] = 1.0f - rgb_to_luma_y(tr);
 }
 
 /* the main entry point for volume shading */
@@ -787,7 +781,7 @@
 
 	
 	copy_v3_v3(shr->combined, tr);
-	shr->combined[3] = 1.0f - luminance(tr);
+	shr->combined[3] = 1.0f - rgb_to_luma_y(tr);
 	shr->alpha = shr->combined[3];
 }
 




More information about the Bf-blender-cvs mailing list