Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-13 19:05:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-13 19:05:42 +0400
commit1dec23d33a86c0412852ef510fc5b5b619284697 (patch)
tree22250958b09cf33ac1e6ea764709194da4307b13 /source/blender
parente22aa7bc38c5d38a0714bed8a2a1869383cd5e5a (diff)
add rgb_to_luma_y(), was being done inline in many places.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_math_color.h2
-rw-r--r--source/blender/blenlib/intern/math_color.c17
-rw-r--r--source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp7
-rw-r--r--source/blender/compositor/operations/COM_GlareThresholdOperation.cpp2
-rw-r--r--source/blender/compositor/operations/COM_TonemapOperation.cpp4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_glare.c2
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_tonemap.c4
-rw-r--r--source/blender/render/intern/source/volumetric.c16
8 files changed, 31 insertions, 23 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 44f54c41129..24c237f1130 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -78,6 +78,8 @@ float rgb_to_grayscale(const float rgb[3]);
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 *****************/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 5b034bd2872..f1529671492 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -516,6 +516,17 @@ unsigned char rgb_to_luma_byte(const unsigned char rgb[3])
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 @@ void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z)
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)
diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp
index 82a71f6a7a8..8ff58be7980 100644
--- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp
+++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp
@@ -89,12 +89,13 @@ void ColorCorrectionOperation::executePixel(float *output, float x, float y, Pix
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));
diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp b/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp
index 4ca5f575cfe..ea76e7551ad 100644
--- a/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp
@@ -37,7 +37,7 @@ void GlareThresholdOperation::initExecution()
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);
diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cpp b/source/blender/compositor/operations/COM_TonemapOperation.cpp
index 9a02d6a58ca..b281fb938fd 100644
--- a/source/blender/compositor/operations/COM_TonemapOperation.cpp
+++ b/source/blender/compositor/operations/COM_TonemapOperation.cpp
@@ -75,7 +75,7 @@ void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, Mem
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 @@ void *TonemapOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuff
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);
diff --git a/source/blender/nodes/composite/nodes/node_composite_glare.c b/source/blender/nodes/composite/nodes/node_composite_glare.c
index 1e32d6f0461..9b1505e9333 100644
--- a/source/blender/nodes/composite/nodes/node_composite_glare.c
+++ b/source/blender/nodes/composite/nodes/node_composite_glare.c
@@ -107,7 +107,7 @@ static CompBuf* BTP(CompBuf* src, float threshold, int scaledown)
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);
diff --git a/source/blender/nodes/composite/nodes/node_composite_tonemap.c b/source/blender/nodes/composite/nodes/node_composite_tonemap.c
index a9d071ececc..6196825c9b3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_tonemap.c
+++ b/source/blender/nodes/composite/nodes/node_composite_tonemap.c
@@ -51,7 +51,7 @@ static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav)
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 @@ static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src)
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);
diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c
index 75748696a72..e4c4e905aa6 100644
--- a/source/blender/render/intern/source/volumetric.c
+++ b/source/blender/render/intern/source/volumetric.c
@@ -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 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const
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 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const
}
}
- 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 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co
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 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co
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 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct
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];
}