[Bf-blender-cvs] [9bfc5fc] blender-v2.76a-release: Fix T44048: freestyle lines in Cycles are in the wrong color space.

Brecht Van Lommel noreply at git.blender.org
Thu Oct 29 11:38:56 CET 2015


Commit: 9bfc5fc7b5e73cc8f6d96d754299a3f1d2ffc62a
Author: Brecht Van Lommel
Date:   Sat Oct 10 18:44:19 2015 +0200
Branches: blender-v2.76a-release
https://developer.blender.org/rB9bfc5fc7b5e73cc8f6d96d754299a3f1d2ffc62a

Fix T44048: freestyle lines in Cycles are in the wrong color space.

===================================================================

M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/makesdna/DNA_meshdata_types.h

===================================================================

diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 64ef49d..7c10591 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -55,6 +55,8 @@ extern "C" {
 
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_math_color.h"
+#include "BLI_math_vector.h"
 #include "BLI_utildefines.h"
 
 #include "RE_pipeline.h"
@@ -113,7 +115,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
 	BLI_strncpy(freestyle_scene->r.engine, old_scene->r.engine, sizeof(freestyle_scene->r.engine));
 	freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA; 
 	freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG;
-	BKE_scene_disable_color_management(freestyle_scene);
 
 	if (G.debug & G_DEBUG_FREESTYLE) {
 		printf("%s: %d thread(s)\n", __func__, BKE_render_num_threads(&freestyle_scene->r));
@@ -871,38 +872,24 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
 						}
 					}
 
-					// colors and alpha transparency
+					// colors and alpha transparency. vertex colors are in sRGB
+					// space by convention, so convert from linear
+					float rgba[3][4];
+
+					for (int i = 0; i < 3; i++) {
+						copy_v3fl_v3db(rgba[i], &svRep[i]->color()[0]);
+						rgba[i][3] = svRep[i]->alpha();
+					}
+
 					if (is_odd) {
-						colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
-						colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
-						colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
-						colors[0].a = (short)(255.0f * svRep[2]->alpha());
-
-						colors[1].r = (short)(255.0f * svRep[0]->color()[0]);
-						colors[1].g = (short)(255.0f * svRep[0]->color()[1]);
-						colors[1].b = (short)(255.0f * svRep[0]->color()[2]);
-						colors[1].a = (short)(255.0f * svRep[0]->alpha());
-
-						colors[2].r = (short)(255.0f * svRep[1]->color()[0]);
-						colors[2].g = (short)(255.0f * svRep[1]->color()[1]);
-						colors[2].b = (short)(255.0f * svRep[1]->color()[2]);
-						colors[2].a = (short)(255.0f * svRep[1]->alpha());
+						linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]);
+						linearrgb_to_srgb_uchar4(&colors[1].r, rgba[0]);
+						linearrgb_to_srgb_uchar4(&colors[2].r, rgba[1]);
 					}
 					else {
-						colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
-						colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
-						colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
-						colors[0].a = (short)(255.0f * svRep[2]->alpha());
-
-						colors[1].r = (short)(255.0f * svRep[1]->color()[0]);
-						colors[1].g = (short)(255.0f * svRep[1]->color()[1]);
-						colors[1].b = (short)(255.0f * svRep[1]->color()[2]);
-						colors[1].a = (short)(255.0f * svRep[1]->alpha());
-
-						colors[2].r = (short)(255.0f * svRep[0]->color()[0]);
-						colors[2].g = (short)(255.0f * svRep[0]->color()[1]);
-						colors[2].b = (short)(255.0f * svRep[0]->color()[2]);
-						colors[2].a = (short)(255.0f * svRep[0]->alpha());
+						linearrgb_to_srgb_uchar4(&colors[0].r, rgba[2]);
+						linearrgb_to_srgb_uchar4(&colors[1].r, rgba[1]);
+						linearrgb_to_srgb_uchar4(&colors[2].r, rgba[0]);
 					}
 					transp[0].r = transp[0].g = transp[0].b = colors[0].a;
 					transp[1].r = transp[1].g = transp[1].b = colors[1].a;
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index 59e6f28..621807d 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -71,7 +71,7 @@ typedef struct MVert {
  * at the moment alpha is abused for vertex painting and not used for transparency, note that red and blue are swapped
  */
 typedef struct MCol {
-	char a, r, g, b;
+	unsigned char a, r, g, b;
 } MCol;
 
 /* new face structure, replaces MFace, which is now only used for storing tessellations.*/
@@ -224,7 +224,7 @@ enum {
  * \note red and blue are _not_ swapped, as they are with #MCol
  */
 typedef struct MLoopCol {
-	char r, g, b, a;
+	unsigned char r, g, b, a;
 } MLoopCol;
 
 #define MESH_MLOOPCOL_FROM_MCOL(_mloopcol, _mcol) \




More information about the Bf-blender-cvs mailing list