Part 2 of D1082 by Troy Sobotka, remove our functions that do luma
calculations and use the OCIO one instead.
This commit is contained in:
@@ -994,7 +994,7 @@ void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const ColorM
|
|||||||
copy_v3_v3(rgb, fp);
|
copy_v3_v3(rgb, fp);
|
||||||
IMB_colormanagement_processor_apply_v3(cm_processor, rgb);
|
IMB_colormanagement_processor_apply_v3(cm_processor, rgb);
|
||||||
|
|
||||||
hist->data_luma[i] = rgb_to_luma(rgb);
|
hist->data_luma[i] = IMB_colormanagement_get_luminance(rgb);
|
||||||
hist->data_r[i] = rgb[0];
|
hist->data_r[i] = rgb[0];
|
||||||
hist->data_g[i] = rgb[1];
|
hist->data_g[i] = rgb[1];
|
||||||
hist->data_b[i] = rgb[2];
|
hist->data_b[i] = rgb[2];
|
||||||
@@ -1002,7 +1002,7 @@ void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const ColorM
|
|||||||
}
|
}
|
||||||
else if (ibuf->rect) {
|
else if (ibuf->rect) {
|
||||||
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
|
cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
|
||||||
hist->data_luma[i] = (float)rgb_to_luma_byte(cp) / 255.0f;
|
hist->data_luma[i] = (float)IMB_colormanagement_get_luminance_byte(cp) / 255.0f;
|
||||||
hist->data_r[i] = (float)cp[0] / 255.0f;
|
hist->data_r[i] = (float)cp[0] / 255.0f;
|
||||||
hist->data_g[i] = (float)cp[1] / 255.0f;
|
hist->data_g[i] = (float)cp[1] / 255.0f;
|
||||||
hist->data_b[i] = (float)cp[2] / 255.0f;
|
hist->data_b[i] = (float)cp[2] / 255.0f;
|
||||||
@@ -1124,7 +1124,7 @@ void scopes_update(Scopes *scopes, ImBuf *ibuf, const ColorManagedViewSettings *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we still need luma for histogram */
|
/* we still need luma for histogram */
|
||||||
luma = rgb_to_luma(rgba);
|
luma = IMB_colormanagement_get_luminance(rgba);
|
||||||
|
|
||||||
/* check for min max */
|
/* check for min max */
|
||||||
if (ycc_mode == -1) {
|
if (ycc_mode == -1) {
|
||||||
|
|||||||
@@ -80,13 +80,6 @@ void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z);
|
|||||||
unsigned int rgb_to_cpack(float r, float g, float b);
|
unsigned int rgb_to_cpack(float r, float g, float b);
|
||||||
unsigned int hsv_to_cpack(float h, float s, float v);
|
unsigned int hsv_to_cpack(float h, float s, float v);
|
||||||
|
|
||||||
MINLINE float rgb_to_bw(const float rgb[3]);
|
|
||||||
MINLINE float rgb_to_grayscale(const float rgb[3]);
|
|
||||||
MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]);
|
|
||||||
MINLINE float rgb_to_luma(const float rgb[3]);
|
|
||||||
MINLINE unsigned char rgb_to_luma_byte(const unsigned char rgb[3]);
|
|
||||||
MINLINE float rgb_to_luma_y(const float rgb[3]);
|
|
||||||
|
|
||||||
/**************** Profile Transformations *****************/
|
/**************** Profile Transformations *****************/
|
||||||
|
|
||||||
float srgb_to_linearrgb(float c);
|
float srgb_to_linearrgb(float c);
|
||||||
|
|||||||
@@ -200,61 +200,6 @@ MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack)
|
|||||||
r_col[2] = ((pack) >> 16) & 0xFF;
|
r_col[2] = ((pack) >> 16) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO:
|
|
||||||
*
|
|
||||||
* regarding #rgb_to_bw vs #rgb_to_grayscale,
|
|
||||||
* it seems nobody knows why we have both functions which convert color to grays
|
|
||||||
* but with different influences, this is quite stupid, and should be resolved
|
|
||||||
* by someone who knows this stuff: see this thread
|
|
||||||
* http://lists.blender.org/pipermail/bf-committers/2012-June/037180.html
|
|
||||||
*
|
|
||||||
* Only conclusion is that rgb_to_grayscale is used more for compositing.
|
|
||||||
*/
|
|
||||||
MINLINE float rgb_to_bw(const float rgb[3])
|
|
||||||
{
|
|
||||||
return 0.35f * rgb[0] + 0.45f * rgb[1] + 0.2f * rgb[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* non-linear luma from ITU-R BT.601-2
|
|
||||||
* see: http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC11
|
|
||||||
* note: the values used for are not exact matches to those documented above,
|
|
||||||
* but they are from the same */
|
|
||||||
MINLINE float rgb_to_grayscale(const float rgb[3])
|
|
||||||
{
|
|
||||||
return 0.3f * rgb[0] + 0.58f * rgb[1] + 0.12f * rgb[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3])
|
|
||||||
{
|
|
||||||
return (unsigned char)(((76 * (unsigned short)rgb[0]) +
|
|
||||||
(148 * (unsigned short)rgb[1]) +
|
|
||||||
(31 * (unsigned short)rgb[2])) / 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* luma from defined by 'YCC_JFIF', see #rgb_to_ycc */
|
|
||||||
MINLINE float rgb_to_luma(const float rgb[3])
|
|
||||||
{
|
|
||||||
return 0.299f * rgb[0] + 0.587f * rgb[1] + 0.114f * rgb[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
MINLINE unsigned char rgb_to_luma_byte(const unsigned char rgb[3])
|
|
||||||
{
|
|
||||||
return (unsigned char)(((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 */
|
|
||||||
MINLINE float rgb_to_luma_y(const float rgb[3])
|
|
||||||
{
|
|
||||||
return 0.212671f * rgb[0] + 0.71516f * rgb[1] + 0.072169f * rgb[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], const int limit)
|
MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], const int limit)
|
||||||
{
|
{
|
||||||
const int r = (int)col_a[0] - (int)col_b[0];
|
const int r = (int)col_a[0] - (int)col_b[0];
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
CalculateMeanOperation::CalculateMeanOperation() : NodeOperation()
|
CalculateMeanOperation::CalculateMeanOperation() : NodeOperation()
|
||||||
{
|
{
|
||||||
@@ -96,7 +98,7 @@ void CalculateMeanOperation::calculateMean(MemoryBuffer *tile)
|
|||||||
switch (this->m_setting) {
|
switch (this->m_setting) {
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
sum += rgb_to_bw(&buffer[offset]);
|
sum += IMB_colormanagement_get_luminance(&buffer[offset]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
CalculateStandardDeviationOperation::CalculateStandardDeviationOperation() : CalculateMeanOperation()
|
CalculateStandardDeviationOperation::CalculateStandardDeviationOperation() : CalculateMeanOperation()
|
||||||
{
|
{
|
||||||
@@ -55,7 +57,7 @@ void *CalculateStandardDeviationOperation::initializeTileData(rcti *rect)
|
|||||||
switch (this->m_setting) {
|
switch (this->m_setting) {
|
||||||
case 1: /* rgb combined */
|
case 1: /* rgb combined */
|
||||||
{
|
{
|
||||||
float value = rgb_to_bw(&buffer[offset]);
|
float value = IMB_colormanagement_get_luminance(&buffer[offset]);
|
||||||
sum += (value - mean) * (value - mean);
|
sum += (value - mean) * (value - mean);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
#include "COM_ColorCorrectionOperation.h"
|
#include "COM_ColorCorrectionOperation.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
ColorCorrectionOperation::ColorCorrectionOperation() : NodeOperation()
|
ColorCorrectionOperation::ColorCorrectionOperation() : NodeOperation()
|
||||||
{
|
{
|
||||||
this->addInputSocket(COM_DT_COLOR);
|
this->addInputSocket(COM_DT_COLOR);
|
||||||
@@ -90,7 +94,7 @@ void ColorCorrectionOperation::executePixelSampled(float output[4], float x, flo
|
|||||||
lift += (levelShadows * this->m_data->shadows.lift) + (levelMidtones * this->m_data->midtones.lift) + (levelHighlights * this->m_data->highlights.lift);
|
lift += (levelShadows * this->m_data->shadows.lift) + (levelMidtones * this->m_data->midtones.lift) + (levelHighlights * this->m_data->highlights.lift);
|
||||||
|
|
||||||
float invgamma = 1.0f / gamma;
|
float invgamma = 1.0f / gamma;
|
||||||
float luma = rgb_to_luma_y(inputImageColor);
|
float luma = IMB_colormanagement_get_luminance(inputImageColor);
|
||||||
|
|
||||||
r = inputImageColor[0];
|
r = inputImageColor[0];
|
||||||
g = inputImageColor[1];
|
g = inputImageColor[1];
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include "COM_ConvertOperation.h"
|
#include "COM_ConvertOperation.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
ConvertBaseOperation::ConvertBaseOperation()
|
ConvertBaseOperation::ConvertBaseOperation()
|
||||||
{
|
{
|
||||||
@@ -84,7 +87,7 @@ void ConvertColorToBWOperation::executePixelSampled(float output[4], float x, fl
|
|||||||
{
|
{
|
||||||
float inputColor[4];
|
float inputColor[4];
|
||||||
this->m_inputOperation->readSampled(inputColor, x, y, sampler);
|
this->m_inputOperation->readSampled(inputColor, x, y, sampler);
|
||||||
output[0] = rgb_to_bw(inputColor);
|
output[0] = IMB_colormanagement_get_luminance(inputColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
#include "COM_GlareThresholdOperation.h"
|
#include "COM_GlareThresholdOperation.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
GlareThresholdOperation::GlareThresholdOperation() : NodeOperation()
|
GlareThresholdOperation::GlareThresholdOperation() : NodeOperation()
|
||||||
{
|
{
|
||||||
this->addInputSocket(COM_DT_COLOR, COM_SC_FIT);
|
this->addInputSocket(COM_DT_COLOR, COM_SC_FIT);
|
||||||
@@ -47,7 +51,7 @@ void GlareThresholdOperation::executePixelSampled(float output[4], float x, floa
|
|||||||
const float threshold = this->m_settings->threshold;
|
const float threshold = this->m_settings->threshold;
|
||||||
|
|
||||||
this->m_inputProgram->readSampled(output, x, y, sampler);
|
this->m_inputProgram->readSampled(output, x, y, sampler);
|
||||||
if (rgb_to_luma_y(output) >= threshold) {
|
if (IMB_colormanagement_get_luminance(output) >= threshold) {
|
||||||
output[0] -= threshold, output[1] -= threshold, output[2] -= threshold;
|
output[0] -= threshold, output[1] -= threshold, output[2] -= threshold;
|
||||||
output[0] = max(output[0], 0.0f);
|
output[0] = max(output[0], 0.0f);
|
||||||
output[1] = max(output[1], 0.0f);
|
output[1] = max(output[1], 0.0f);
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
}
|
||||||
|
|
||||||
TonemapOperation::TonemapOperation() : NodeOperation()
|
TonemapOperation::TonemapOperation() : NodeOperation()
|
||||||
{
|
{
|
||||||
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
|
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
|
||||||
@@ -69,7 +73,7 @@ void PhotoreceptorTonemapOperation::executePixel(float output[4], int x, int y,
|
|||||||
|
|
||||||
this->m_imageReader->read(output, x, y, NULL);
|
this->m_imageReader->read(output, x, y, NULL);
|
||||||
|
|
||||||
const float L = rgb_to_luma_y(output);
|
const float L = IMB_colormanagement_get_luminance(output);
|
||||||
float I_l = output[0] + ic * (L - output[0]);
|
float I_l = output[0] + ic * (L - output[0]);
|
||||||
float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]);
|
float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]);
|
||||||
float I_a = I_l + ia * (I_g - I_l);
|
float I_a = I_l + ia * (I_g - I_l);
|
||||||
@@ -125,7 +129,7 @@ void *TonemapOperation::initializeTileData(rcti *rect)
|
|||||||
float Lav = 0.f;
|
float Lav = 0.f;
|
||||||
float cav[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
float cav[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
while (p--) {
|
while (p--) {
|
||||||
float L = rgb_to_luma_y(bc);
|
float L = IMB_colormanagement_get_luminance(bc);
|
||||||
Lav += L;
|
Lav += L;
|
||||||
add_v3_v3(cav, bc);
|
add_v3_v3(cav, bc);
|
||||||
lsum += logf(MAX2(L, 0.0f) + 1e-5f);
|
lsum += logf(MAX2(L, 0.0f) + 1e-5f);
|
||||||
|
|||||||
@@ -1453,7 +1453,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
else if (cumap->cur == 3) {
|
else if (cumap->cur == 3) {
|
||||||
float lum = rgb_to_bw(cumap->sample);
|
float lum = IMB_colormanagement_get_luminance(cumap->sample);
|
||||||
glColor3ub(240, 240, 240);
|
glColor3ub(240, 240, 240);
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
|
|||||||
@@ -237,8 +237,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
|
|||||||
|
|
||||||
/* find the brightness difference between background and text colors */
|
/* find the brightness difference between background and text colors */
|
||||||
|
|
||||||
tone_bg = rgb_to_grayscale(background_color);
|
tone_bg = IMB_colormanagement_get_luminance(background_color);
|
||||||
/* tone_fg = rgb_to_grayscale(main_color); */
|
/* tone_fg = IMB_colormanagement_get_luminance(main_color); */
|
||||||
|
|
||||||
/* mix the colors */
|
/* mix the colors */
|
||||||
rgb_tint(value_color, 0.0f, 0.0f, tone_bg, 0.2f); /* light grey */
|
rgb_tint(value_color, 0.0f, 0.0f, tone_bg, 0.2f); /* light grey */
|
||||||
@@ -261,7 +261,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
|
|||||||
|
|
||||||
/* override text-style */
|
/* override text-style */
|
||||||
fstyle_header.shadow = 1;
|
fstyle_header.shadow = 1;
|
||||||
fstyle_header.shadowcolor = rgb_to_luma(tip_colors[UI_TIP_LC_MAIN]);
|
fstyle_header.shadowcolor = IMB_colormanagement_get_luminance(tip_colors[UI_TIP_LC_MAIN]);
|
||||||
fstyle_header.shadx = fstyle_header.shady = 0;
|
fstyle_header.shadx = fstyle_header.shady = 0;
|
||||||
fstyle_header.shadowalpha = 1.0f;
|
fstyle_header.shadowalpha = 1.0f;
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
#include "UI_interface.h"
|
#include "UI_interface.h"
|
||||||
#include "UI_interface_icons.h"
|
#include "UI_interface_icons.h"
|
||||||
|
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
#include "interface_intern.h"
|
#include "interface_intern.h"
|
||||||
|
|
||||||
@@ -3027,7 +3028,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
|
|||||||
float width = rect->xmax - rect->xmin;
|
float width = rect->xmax - rect->xmin;
|
||||||
float height = rect->ymax - rect->ymin;
|
float height = rect->ymax - rect->ymin;
|
||||||
/* find color luminance and change it slightly */
|
/* find color luminance and change it slightly */
|
||||||
float bw = rgb_to_bw(col);
|
float bw = IMB_colormanagement_get_luminance(col);
|
||||||
|
|
||||||
bw += (bw < 0.5f) ? 0.5f : -0.5f;
|
bw += (bw < 0.5f) ? 0.5f : -0.5f;
|
||||||
|
|
||||||
|
|||||||
@@ -889,7 +889,7 @@ static void paint_2d_lift_soften(ImagePaintState *s, ImBuf *ibuf, ImBuf *ibufb,
|
|||||||
|
|
||||||
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
||||||
* colored speckles appearing in final image, and also to check for threshold */
|
* colored speckles appearing in final image, and also to check for threshold */
|
||||||
outrgb[0] = outrgb[1] = outrgb[2] = rgb_to_grayscale(outrgb);
|
outrgb[0] = outrgb[1] = outrgb[2] = IMB_colormanagement_get_luminance(outrgb);
|
||||||
if (fabsf(outrgb[0]) > threshold) {
|
if (fabsf(outrgb[0]) > threshold) {
|
||||||
float mask = BKE_brush_alpha_get(s->scene, s->brush);
|
float mask = BKE_brush_alpha_get(s->scene, s->brush);
|
||||||
float alpha = rgba[3];
|
float alpha = rgba[3];
|
||||||
|
|||||||
@@ -4207,7 +4207,7 @@ static void do_projectpaint_soften_f(ProjPaintState *ps, ProjPixel *projPixel, f
|
|||||||
|
|
||||||
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
||||||
* colored speckles appearing in final image, and also to check for threshold */
|
* colored speckles appearing in final image, and also to check for threshold */
|
||||||
rgba[0] = rgba[1] = rgba[2] = rgb_to_grayscale(rgba);
|
rgba[0] = rgba[1] = rgba[2] = IMB_colormanagement_get_luminance(rgba);
|
||||||
if (fabsf(rgba[0]) > ps->brush->sharp_threshold) {
|
if (fabsf(rgba[0]) > ps->brush->sharp_threshold) {
|
||||||
float alpha = projPixel->pixel.f_pt[3];
|
float alpha = projPixel->pixel.f_pt[3];
|
||||||
projPixel->pixel.f_pt[3] = rgba[3] = mask;
|
projPixel->pixel.f_pt[3] = rgba[3] = mask;
|
||||||
@@ -4268,7 +4268,7 @@ static void do_projectpaint_soften(ProjPaintState *ps, ProjPixel *projPixel, flo
|
|||||||
sub_v3_v3v3(rgba, rgba_pixel, rgba);
|
sub_v3_v3v3(rgba, rgba_pixel, rgba);
|
||||||
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
/* now rgba_ub contains the edge result, but this should be converted to luminance to avoid
|
||||||
* colored speckles appearing in final image, and also to check for threshold */
|
* colored speckles appearing in final image, and also to check for threshold */
|
||||||
rgba[0] = rgba[1] = rgba[2] = rgb_to_grayscale(rgba);
|
rgba[0] = rgba[1] = rgba[2] = IMB_colormanagement_get_luminance(rgba);
|
||||||
if (fabsf(rgba[0]) > ps->brush->sharp_threshold) {
|
if (fabsf(rgba[0]) > ps->brush->sharp_threshold) {
|
||||||
float alpha = rgba_pixel[3];
|
float alpha = rgba_pixel[3];
|
||||||
rgba[3] = rgba_pixel[3] = mask;
|
rgba[3] = rgba_pixel[3] = mask;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "IMB_imbuf.h"
|
#include "IMB_imbuf.h"
|
||||||
#include "IMB_imbuf_types.h"
|
#include "IMB_imbuf_types.h"
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
#include "DNA_armature_types.h"
|
#include "DNA_armature_types.h"
|
||||||
#include "DNA_mesh_types.h"
|
#include "DNA_mesh_types.h"
|
||||||
@@ -768,7 +769,7 @@ BLI_INLINE unsigned int mcol_lighten(unsigned int col1, unsigned int col2, int f
|
|||||||
|
|
||||||
/* See if are lighter, if so mix, else don't do anything.
|
/* See if are lighter, if so mix, else don't do anything.
|
||||||
* if the paint col is darker then the original, then ignore */
|
* if the paint col is darker then the original, then ignore */
|
||||||
if (rgb_to_grayscale_byte(cp1) > rgb_to_grayscale_byte(cp2)) {
|
if (IMB_colormanagement_get_luminance_byte(cp1) > IMB_colormanagement_get_luminance_byte(cp2)) {
|
||||||
return col1;
|
return col1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,7 +802,7 @@ BLI_INLINE unsigned int mcol_darken(unsigned int col1, unsigned int col2, int fa
|
|||||||
|
|
||||||
/* See if were darker, if so mix, else don't do anything.
|
/* See if were darker, if so mix, else don't do anything.
|
||||||
* if the paint col is brighter then the original, then ignore */
|
* if the paint col is brighter then the original, then ignore */
|
||||||
if (rgb_to_grayscale_byte(cp1) < rgb_to_grayscale_byte(cp2)) {
|
if (IMB_colormanagement_get_luminance_byte(cp1) < IMB_colormanagement_get_luminance_byte(cp2)) {
|
||||||
return col1;
|
return col1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "BLI_math_color.h"
|
#include "BLI_math_color.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
#include "IMB_imbuf_types.h"
|
#include "IMB_imbuf_types.h"
|
||||||
#include "IMB_imbuf.h"
|
#include "IMB_imbuf.h"
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ static ImBuf *make_waveform_view_from_ibuf_byte(ImBuf *ibuf)
|
|||||||
|
|
||||||
for (x = 0; x < ibuf->x; x++) {
|
for (x = 0; x < ibuf->x; x++) {
|
||||||
const unsigned char *rgb = src + 4 * (ibuf->x * y + x);
|
const unsigned char *rgb = src + 4 * (ibuf->x * y + x);
|
||||||
float v = (float)rgb_to_luma_byte(rgb) / 255.0f;
|
float v = (float)IMB_colormanagement_get_luminance_byte(rgb) / 255.0f;
|
||||||
unsigned char *p = tgt;
|
unsigned char *p = tgt;
|
||||||
p += 4 * (w * ((int) (v * (h - 3)) + 1) + x + 1);
|
p += 4 * (w * ((int) (v * (h - 3)) + 1) + x + 1);
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ static ImBuf *make_waveform_view_from_ibuf_float(ImBuf *ibuf)
|
|||||||
|
|
||||||
for (x = 0; x < ibuf->x; x++) {
|
for (x = 0; x < ibuf->x; x++) {
|
||||||
const float *rgb = src + 4 * (ibuf->x * y + x);
|
const float *rgb = src + 4 * (ibuf->x * y + x);
|
||||||
float v = rgb_to_luma(rgb);
|
float v = IMB_colormanagement_get_luminance(rgb);
|
||||||
unsigned char *p = tgt;
|
unsigned char *p = tgt;
|
||||||
|
|
||||||
CLAMP(v, 0.0f, 1.0f);
|
CLAMP(v, 0.0f, 1.0f);
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *
|
|||||||
const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
|
const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
|
||||||
const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
|
const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
|
||||||
|
|
||||||
|
float IMB_colormanagement_get_luminance(const float rgb[3]);
|
||||||
|
unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]);
|
||||||
|
|
||||||
/* ** Color space transformation functions ** */
|
/* ** Color space transformation functions ** */
|
||||||
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
|
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
|
||||||
const char *from_colorspace, const char *to_colorspace, bool predivide);
|
const char *from_colorspace, const char *to_colorspace, bool predivide);
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ static int global_tot_display = 0;
|
|||||||
static int global_tot_view = 0;
|
static int global_tot_view = 0;
|
||||||
static int global_tot_looks = 0;
|
static int global_tot_looks = 0;
|
||||||
|
|
||||||
|
/* Set to ITU-BT.709 / sRGB primaries weight. Brute force stupid, but only
|
||||||
|
* option with no colormanagement in place.
|
||||||
|
*/
|
||||||
|
static float luma_coefficients[3] = { 0.2126729f, 0.7151522f, 0.0721750f };
|
||||||
|
|
||||||
/* lock used by pre-cached processors getters, so processor wouldn't
|
/* lock used by pre-cached processors getters, so processor wouldn't
|
||||||
* be created several times
|
* be created several times
|
||||||
* LOCK_COLORMANAGE can not be used since this mutex could be needed to
|
* LOCK_COLORMANAGE can not be used since this mutex could be needed to
|
||||||
@@ -545,6 +550,9 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
|
|||||||
|
|
||||||
colormanage_look_add(name, process_space, false);
|
colormanage_look_add(name, process_space, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load luminance coefficients. */
|
||||||
|
OCIO_configGetDefaultLumaCoefs(config, luma_coefficients);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void colormanage_free_config(void)
|
static void colormanage_free_config(void)
|
||||||
@@ -1222,6 +1230,34 @@ const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf)
|
|||||||
return ibuf->rect_colorspace->name;
|
return ibuf->rect_colorspace->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert a float RGB triplet to the correct luminance weighted average.
|
||||||
|
*
|
||||||
|
* Grayscale, or Luma is a distillation of RGB data values down to a weighted average
|
||||||
|
* based on the luminance positions of the red, green, and blue primaries.
|
||||||
|
* Given that the internal reference space may be arbitrarily set, any
|
||||||
|
* effort to glean the luminance coefficients must be aware of the reference
|
||||||
|
* space primaries.
|
||||||
|
*
|
||||||
|
* See http://wiki.blender.org/index.php/User:Nazg-gul/ColorManagement#Luminance
|
||||||
|
*/
|
||||||
|
|
||||||
|
float IMB_colormanagement_get_luminance(const float rgb[3])
|
||||||
|
{
|
||||||
|
return dot_v3v3(luma_coefficients, rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Byte equivalent of IMB_colormanagement_get_luminance(). */
|
||||||
|
unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
|
||||||
|
{
|
||||||
|
float rgbf[3];
|
||||||
|
|
||||||
|
rgbf[0] = (float) rgb[0] / 255.0f;
|
||||||
|
rgbf[1] = (float) rgb[1] / 255.0f;
|
||||||
|
rgbf[2] = (float) rgb[2] / 255.0f;
|
||||||
|
|
||||||
|
return FTOCHAR(dot_v3v3(luma_coefficients, rgbf));
|
||||||
|
}
|
||||||
|
|
||||||
/*********************** Threaded display buffer transform routines *************************/
|
/*********************** Threaded display buffer transform routines *************************/
|
||||||
|
|
||||||
typedef struct DisplayBufferThread {
|
typedef struct DisplayBufferThread {
|
||||||
|
|||||||
@@ -775,12 +775,12 @@ void IMB_color_to_bw(ImBuf *ibuf)
|
|||||||
|
|
||||||
if (rct_fl) {
|
if (rct_fl) {
|
||||||
for (i = ibuf->x * ibuf->y; i > 0; i--, rct_fl += 4)
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct_fl += 4)
|
||||||
rct_fl[0] = rct_fl[1] = rct_fl[2] = rgb_to_grayscale(rct_fl);
|
rct_fl[0] = rct_fl[1] = rct_fl[2] = IMB_colormanagement_get_luminance(rct_fl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rct) {
|
if (rct) {
|
||||||
for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4)
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4)
|
||||||
rct[0] = rct[1] = rct[2] = rgb_to_grayscale_byte(rct);
|
rct[0] = rct[1] = rct[2] = IMB_colormanagement_get_luminance_byte(rct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
|
|||||||
rgb[0] = chanel_colormanage_cb(from_straight[0]);
|
rgb[0] = chanel_colormanage_cb(from_straight[0]);
|
||||||
rgb[1] = chanel_colormanage_cb(from_straight[1]);
|
rgb[1] = chanel_colormanage_cb(from_straight[1]);
|
||||||
rgb[2] = chanel_colormanage_cb(from_straight[2]);
|
rgb[2] = chanel_colormanage_cb(from_straight[2]);
|
||||||
to16[0] = ftoshort(rgb_to_bw(rgb));
|
to16[0] = ftoshort(IMB_colormanagement_get_luminance(rgb));
|
||||||
to16++; from_float += 4;
|
to16++; from_float += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
|
|||||||
rgb[0] = chanel_colormanage_cb(from_float[0]);
|
rgb[0] = chanel_colormanage_cb(from_float[0]);
|
||||||
rgb[1] = chanel_colormanage_cb(from_float[1]);
|
rgb[1] = chanel_colormanage_cb(from_float[1]);
|
||||||
rgb[2] = chanel_colormanage_cb(from_float[2]);
|
rgb[2] = chanel_colormanage_cb(from_float[2]);
|
||||||
to16[0] = ftoshort(rgb_to_bw(rgb));
|
to16[0] = ftoshort(IMB_colormanagement_get_luminance(rgb));
|
||||||
to16++; from_float += 3;
|
to16++; from_float += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "node_shader_util.h"
|
#include "node_shader_util.h"
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
/* **************** VALTORGB ******************** */
|
/* **************** VALTORGB ******************** */
|
||||||
static bNodeSocketTemplate sh_node_valtorgb_in[] = {
|
static bNodeSocketTemplate sh_node_valtorgb_in[] = {
|
||||||
@@ -106,7 +107,7 @@ static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), bNo
|
|||||||
float col[3];
|
float col[3];
|
||||||
nodestack_get_vec(col, SOCK_VECTOR, in[0]);
|
nodestack_get_vec(col, SOCK_VECTOR, in[0]);
|
||||||
|
|
||||||
out[0]->vec[0] = rgb_to_bw(col);
|
out[0]->vec[0] = IMB_colormanagement_get_luminance(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
|
static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "node_texture_util.h"
|
#include "node_texture_util.h"
|
||||||
#include "NOD_texture.h"
|
#include "NOD_texture.h"
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
/* **************** VALTORGB ******************** */
|
/* **************** VALTORGB ******************** */
|
||||||
static bNodeSocketTemplate valtorgb_in[] = {
|
static bNodeSocketTemplate valtorgb_in[] = {
|
||||||
@@ -91,7 +92,7 @@ static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNode
|
|||||||
{
|
{
|
||||||
float cin[4];
|
float cin[4];
|
||||||
tex_input_rgba(cin, in[0], p, thread);
|
tex_input_rgba(cin, in[0], p, thread);
|
||||||
*out = rgb_to_bw(cin);
|
*out = IMB_colormanagement_get_luminance(cin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rgbtobw_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
|
static void rgbtobw_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
|
||||||
|
|||||||
@@ -1982,14 +1982,14 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
|
|||||||
|
|
||||||
/* use texres for the center sample, set rgbnor */
|
/* use texres for the center sample, set rgbnor */
|
||||||
rgbnor = multitex_mtex(shi, mtex, STll, dxt, dyt, texres, pool, skip_load_image);
|
rgbnor = multitex_mtex(shi, mtex, STll, dxt, dyt, texres, pool, skip_load_image);
|
||||||
Hll = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin;
|
Hll = (fromrgb) ? IMB_colormanagement_get_luminance(&texres->tr) : texres->tin;
|
||||||
|
|
||||||
/* use ttexr for the other 2 taps */
|
/* use ttexr for the other 2 taps */
|
||||||
multitex_mtex(shi, mtex, STlr, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STlr, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hlr = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hlr = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
|
|
||||||
multitex_mtex(shi, mtex, STul, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STul, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hul = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hul = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
|
|
||||||
dHdx = Hscale*(Hlr - Hll);
|
dHdx = Hscale*(Hlr - Hll);
|
||||||
dHdy = Hscale*(Hul - Hll);
|
dHdy = Hscale*(Hul - Hll);
|
||||||
@@ -2020,17 +2020,17 @@ static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, T
|
|||||||
|
|
||||||
/* use texres for the center sample, set rgbnor */
|
/* use texres for the center sample, set rgbnor */
|
||||||
rgbnor = multitex_mtex(shi, mtex, STc, dxt, dyt, texres, pool, skip_load_image);
|
rgbnor = multitex_mtex(shi, mtex, STc, dxt, dyt, texres, pool, skip_load_image);
|
||||||
/* Hc = (fromrgb) ? rgb_to_grayscale(&texres->tr) : texres->tin; */ /* UNUSED */
|
/* Hc = (fromrgb) ? IMB_colormanagement_get_luminance(&texres->tr) : texres->tin; */ /* UNUSED */
|
||||||
|
|
||||||
/* use ttexr for the other taps */
|
/* use ttexr for the other taps */
|
||||||
multitex_mtex(shi, mtex, STl, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STl, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hl = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hl = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
multitex_mtex(shi, mtex, STr, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STr, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hr = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hr = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
multitex_mtex(shi, mtex, STd, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STd, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hd = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hd = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
multitex_mtex(shi, mtex, STu, dxt, dyt, &ttexr, pool, skip_load_image);
|
multitex_mtex(shi, mtex, STu, dxt, dyt, &ttexr, pool, skip_load_image);
|
||||||
Hu = (fromrgb) ? rgb_to_grayscale(&ttexr.tr) : ttexr.tin;
|
Hu = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
|
||||||
|
|
||||||
dHdx = Hscale*(Hr - Hl);
|
dHdx = Hscale*(Hr - Hl);
|
||||||
dHdy = Hscale*(Hu - Hd);
|
dHdy = Hscale*(Hu - Hd);
|
||||||
@@ -2328,7 +2328,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
|||||||
/* texture output */
|
/* texture output */
|
||||||
|
|
||||||
if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
rgbnor -= TEX_RGB;
|
rgbnor -= TEX_RGB;
|
||||||
}
|
}
|
||||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||||
@@ -2568,7 +2568,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rgbnor & TEX_RGB) {
|
if (rgbnor & TEX_RGB) {
|
||||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
factt= (0.5f-texres.tin)*mtex->dispfac*stencilTin; facmm= 1.0f-factt;
|
factt= (0.5f-texres.tin)*mtex->dispfac*stencilTin; facmm= 1.0f-factt;
|
||||||
@@ -2596,7 +2596,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
|
|||||||
|
|
||||||
if (rgbnor & TEX_RGB) {
|
if (rgbnor & TEX_RGB) {
|
||||||
if (texres.talpha) texres.tin = texres.ta;
|
if (texres.talpha) texres.tin = texres.ta;
|
||||||
else texres.tin = rgb_to_grayscale(&texres.tr);
|
else texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtex->mapto & MAP_REF) {
|
if (mtex->mapto & MAP_REF) {
|
||||||
@@ -2767,7 +2767,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_
|
|||||||
/* texture output */
|
/* texture output */
|
||||||
|
|
||||||
if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||||
texres.tin = rgb_to_grayscale(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
rgbnor -= TEX_RGB;
|
rgbnor -= TEX_RGB;
|
||||||
}
|
}
|
||||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||||
@@ -2836,7 +2836,7 @@ void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_
|
|||||||
/* convert RGB to intensity if intensity info isn't provided */
|
/* convert RGB to intensity if intensity info isn't provided */
|
||||||
if (rgbnor & TEX_RGB) {
|
if (rgbnor & TEX_RGB) {
|
||||||
if (texres.talpha) texres.tin = texres.ta;
|
if (texres.talpha) texres.tin = texres.ta;
|
||||||
else texres.tin = rgb_to_grayscale(&texres.tr);
|
else texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) {
|
if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) {
|
||||||
@@ -2934,7 +2934,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
|
|||||||
|
|
||||||
/* texture output */
|
/* texture output */
|
||||||
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||||
texres.tin = rgb_to_bw(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
rgb= 0;
|
rgb= 0;
|
||||||
}
|
}
|
||||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||||
@@ -3006,7 +3006,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
|
|||||||
texres.tin = texres.ta;
|
texres.tin = texres.ta;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
texres.tin = rgb_to_bw(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3140,7 +3140,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h
|
|||||||
|
|
||||||
/* texture output */
|
/* texture output */
|
||||||
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||||
texres.tin = rgb_to_bw(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
rgb= 0;
|
rgb= 0;
|
||||||
}
|
}
|
||||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||||
@@ -3215,7 +3215,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mtex->mapto & WOMAP_BLEND) {
|
if (mtex->mapto & WOMAP_BLEND) {
|
||||||
if (rgb) texres.tin = rgb_to_bw(&texres.tr);
|
if (rgb) texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
|
|
||||||
*blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype);
|
*blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype);
|
||||||
}
|
}
|
||||||
@@ -3356,7 +3356,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r
|
|||||||
|
|
||||||
/* texture output */
|
/* texture output */
|
||||||
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
|
||||||
texres.tin = rgb_to_bw(&texres.tr);
|
texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
|
||||||
rgb= 0;
|
rgb= 0;
|
||||||
}
|
}
|
||||||
if (mtex->texflag & MTEX_NEGATIVE) {
|
if (mtex->texflag & MTEX_NEGATIVE) {
|
||||||
@@ -3455,7 +3455,7 @@ int externtex(MTex *mtex, const float vec[3], float *tin, float *tr, float *tg,
|
|||||||
rgb = multitex(tex, texvec, dxt, dyt, 0, &texr, thread, mtex->which_output, pool, skip_load_image);
|
rgb = multitex(tex, texvec, dxt, dyt, 0, &texr, thread, mtex->which_output, pool, skip_load_image);
|
||||||
|
|
||||||
if (rgb) {
|
if (rgb) {
|
||||||
texr.tin = rgb_to_bw(&texr.tr);
|
texr.tin = IMB_colormanagement_get_luminance(&texr.tr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
texr.tr= mtex->r;
|
texr.tr= mtex->r;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
#include "shading.h" /* own include */
|
#include "shading.h" /* own include */
|
||||||
|
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
/* could enable at some point but for now there are far too many conversions */
|
/* could enable at some point but for now there are far too many conversions */
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
# pragma GCC diagnostic ignored "-Wdouble-promotion"
|
# pragma GCC diagnostic ignored "-Wdouble-promotion"
|
||||||
@@ -948,7 +950,7 @@ static void ramp_diffuse_result(float *diff, ShadeInput *shi)
|
|||||||
|
|
||||||
if (ma->ramp_col) {
|
if (ma->ramp_col) {
|
||||||
if (ma->rampin_col==MA_RAMP_IN_RESULT) {
|
if (ma->rampin_col==MA_RAMP_IN_RESULT) {
|
||||||
float fac = rgb_to_grayscale(diff);
|
float fac = IMB_colormanagement_get_luminance(diff);
|
||||||
do_colorband(ma->ramp_col, fac, col);
|
do_colorband(ma->ramp_col, fac, col);
|
||||||
|
|
||||||
/* blending method */
|
/* blending method */
|
||||||
@@ -980,7 +982,7 @@ static void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, floa
|
|||||||
/* input */
|
/* input */
|
||||||
switch (ma->rampin_col) {
|
switch (ma->rampin_col) {
|
||||||
case MA_RAMP_IN_ENERGY:
|
case MA_RAMP_IN_ENERGY:
|
||||||
/* should use 'rgb_to_grayscale' but we only have a vector version */
|
/* should use 'IMB_colormanagement_get_luminance' but we only have a vector version */
|
||||||
fac= 0.3f*r + 0.58f*g + 0.12f*b;
|
fac= 0.3f*r + 0.58f*g + 0.12f*b;
|
||||||
break;
|
break;
|
||||||
case MA_RAMP_IN_SHADER:
|
case MA_RAMP_IN_SHADER:
|
||||||
@@ -1023,7 +1025,7 @@ static void ramp_spec_result(float spec_col[3], ShadeInput *shi)
|
|||||||
|
|
||||||
if (ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) {
|
if (ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) {
|
||||||
float col[4];
|
float col[4];
|
||||||
float fac = rgb_to_grayscale(spec_col);
|
float fac = IMB_colormanagement_get_luminance(spec_col);
|
||||||
|
|
||||||
do_colorband(ma->ramp_spec, fac, col);
|
do_colorband(ma->ramp_spec, fac, col);
|
||||||
|
|
||||||
@@ -1619,10 +1621,10 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
|
|||||||
|
|
||||||
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
||||||
/* Old "Shadows Only" */
|
/* Old "Shadows Only" */
|
||||||
accum+= (1.0f-visifac) + (visifac)*rgb_to_grayscale(shadfac)*shadfac[3];
|
accum+= (1.0f-visifac) + (visifac)*IMB_colormanagement_get_luminance(shadfac)*shadfac[3];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shaded += rgb_to_grayscale(shadfac)*shadfac[3] * visifac * lar->energy;
|
shaded += IMB_colormanagement_get_luminance(shadfac)*shadfac[3] * visifac * lar->energy;
|
||||||
|
|
||||||
if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
|
if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
|
||||||
lightness += visifac * lar->energy;
|
lightness += visifac * lar->energy;
|
||||||
@@ -1671,26 +1673,26 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
|
|||||||
|
|
||||||
if (R.wrld.aomix==WO_AOADD) {
|
if (R.wrld.aomix==WO_AOADD) {
|
||||||
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
||||||
f= f*(1.0f - rgb_to_grayscale(shi->ao));
|
f= f*(1.0f - IMB_colormanagement_get_luminance(shi->ao));
|
||||||
shr->alpha= (shr->alpha + f)*f;
|
shr->alpha= (shr->alpha + f)*f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shr->alpha -= f*rgb_to_grayscale(shi->ao);
|
shr->alpha -= f*IMB_colormanagement_get_luminance(shi->ao);
|
||||||
if (shr->alpha<0.0f) shr->alpha=0.0f;
|
if (shr->alpha<0.0f) shr->alpha=0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* AO Multiply */
|
else /* AO Multiply */
|
||||||
shr->alpha= (1.0f - f)*shr->alpha + f*(1.0f - (1.0f - shr->alpha)*rgb_to_grayscale(shi->ao));
|
shr->alpha= (1.0f - f)*shr->alpha + f*(1.0f - (1.0f - shr->alpha)*IMB_colormanagement_get_luminance(shi->ao));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R.wrld.mode & WO_ENV_LIGHT) {
|
if (R.wrld.mode & WO_ENV_LIGHT) {
|
||||||
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
if (shi->mat->shadowonly_flag == MA_SO_OLD) {
|
||||||
f= R.wrld.ao_env_energy*shi->amb*(1.0f - rgb_to_grayscale(shi->env));
|
f= R.wrld.ao_env_energy*shi->amb*(1.0f - IMB_colormanagement_get_luminance(shi->env));
|
||||||
shr->alpha= (shr->alpha + f)*f;
|
shr->alpha= (shr->alpha + f)*f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
f= R.wrld.ao_env_energy*shi->amb;
|
f= R.wrld.ao_env_energy*shi->amb;
|
||||||
shr->alpha -= f*rgb_to_grayscale(shi->env);
|
shr->alpha -= f*IMB_colormanagement_get_luminance(shi->env);
|
||||||
if (shr->alpha<0.0f) shr->alpha=0.0f;
|
if (shr->alpha<0.0f) shr->alpha=0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
|
|
||||||
#include "RE_shader_ext.h"
|
#include "RE_shader_ext.h"
|
||||||
|
|
||||||
|
#include "IMB_colormanagement.h"
|
||||||
|
|
||||||
#include "DNA_material_types.h"
|
#include "DNA_material_types.h"
|
||||||
#include "DNA_group_types.h"
|
#include "DNA_group_types.h"
|
||||||
#include "DNA_lamp_types.h"
|
#include "DNA_lamp_types.h"
|
||||||
@@ -504,7 +506,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) {
|
if (shi->mat->vol.shadeflag & MA_VOL_RECV_EXT_SHADOW) {
|
||||||
mul_v3_fl(lacol, vol_get_shadow(shi, lar, co));
|
mul_v3_fl(lacol, vol_get_shadow(shi, lar, co));
|
||||||
if (rgb_to_luma_y(lacol) < 0.001f) return;
|
if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find minimum of volume bounds, or lamp coord */
|
/* find minimum of volume bounds, or lamp coord */
|
||||||
@@ -538,7 +540,7 @@ static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rgb_to_luma_y(lacol) < 0.001f) return;
|
if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return;
|
||||||
|
|
||||||
normalize_v3(lv);
|
normalize_v3(lv);
|
||||||
p = vol_get_phasefunc(shi, shi->mat->vol.asymmetry, view, lv);
|
p = vol_get_phasefunc(shi, shi->mat->vol.asymmetry, view, lv);
|
||||||
@@ -620,7 +622,7 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co
|
|||||||
|
|
||||||
if (t0 > t1 * 0.25f) {
|
if (t0 > t1 * 0.25f) {
|
||||||
/* only use depth cutoff after we've traced a little way into the volume */
|
/* only use depth cutoff after we've traced a little way into the volume */
|
||||||
if (rgb_to_luma_y(tr) < shi->mat->vol.depth_cutoff) break;
|
if (IMB_colormanagement_get_luminance(tr) < shi->mat->vol.depth_cutoff) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vol_get_emission(shi, emit_col, p);
|
vol_get_emission(shi, emit_col, p);
|
||||||
@@ -649,7 +651,7 @@ static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co
|
|||||||
add_v3_v3(col, radiance);
|
add_v3_v3(col, radiance);
|
||||||
|
|
||||||
/* alpha <-- transmission luminance */
|
/* alpha <-- transmission luminance */
|
||||||
col[3] = 1.0f - rgb_to_luma_y(tr);
|
col[3] = 1.0f - IMB_colormanagement_get_luminance(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the main entry point for volume shading */
|
/* the main entry point for volume shading */
|
||||||
@@ -790,7 +792,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct
|
|||||||
|
|
||||||
|
|
||||||
copy_v3_v3(shr->combined, tr);
|
copy_v3_v3(shr->combined, tr);
|
||||||
shr->combined[3] = 1.0f - rgb_to_luma_y(tr);
|
shr->combined[3] = 1.0f - IMB_colormanagement_get_luminance(tr);
|
||||||
shr->alpha = shr->combined[3];
|
shr->alpha = shr->combined[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user