[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25065] trunk/blender: Changes to Color Management

Matt Ebb matt at mke3.net
Wed Dec 2 08:56:36 CET 2009


Revision: 25065
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25065
Author:   broken
Date:     2009-12-02 08:56:34 +0100 (Wed, 02 Dec 2009)

Log Message:
-----------
Changes to Color Management

After testing and feedback, I've decided to slightly modify the way color 
management works internally. While the previous method worked well for 
rendering, was a smaller transition and had some advantages over this
new method, it was a bit more ambiguous, and was making things difficult 
for other areas such as compositing.

This implementation now considers all color data (with only a couple of 
exceptions such as brush colors) to be stored in linear RGB color space, 
rather than sRGB as previously. This brings it in line with Nuke, which also 
operates this way, quite successfully. Color swatches, pickers, color ramp 
display are now gamma corrected to display gamma so you can see what 
you're doing, but the numbers themselves are considered linear. This 
makes understanding blending modes more clear (a 0.5 value on overlay 
will not change the result now) as well as making color swatches act more 
predictably in the compositor, however bringing over color values from 
applications like photoshop or gimp, that operate in a gamma space, 
will give identical results.

This commit will convert over existing files saved by earlier 2.5 versions to 
work generally the same, though there may be some slight differences with 
things like textures. Now that we're set on changing other areas of shading, 
this won't be too disruptive overall.

I've made a diagram explaining the pipeline here:
http://mke3.net/blender/devel/2.5/25_linear_workflow_pipeline.png

and some docs here:
http://www.blender.org/development/release-logs/blender-250/color-management/

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_material.py
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/BKE_colortools.h
    trunk/blender/source/blender/blenkernel/intern/colortools.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/interface/interface_utils.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c
    trunk/blender/source/blender/gpu/intern/gpu_draw.c
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_brush.c
    trunk/blender/source/blender/makesrna/intern/rna_color.c
    trunk/blender/source/blender/makesrna/intern/rna_material.c
    trunk/blender/source/blender/makesrna/intern/rna_rna.c
    trunk/blender/source/blender/render/intern/source/convertblender.c
    trunk/blender/source/blender/render/intern/source/pixelshading.c
    trunk/blender/source/blender/render/intern/source/shadeinput.c
    trunk/blender/source/blender/render/intern/source/sss.c
    trunk/blender/source/blender/render/intern/source/texture.c

Modified: trunk/blender/release/scripts/ui/properties_material.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_material.py	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/release/scripts/ui/properties_material.py	2009-12-02 07:56:34 UTC (rev 25065)
@@ -495,7 +495,7 @@
         col.prop(sss, "ior")
         col.prop(sss, "scale")
         col.prop(sss, "color", text="")
-        col.prop(sss, "radius", text="RGB Radius")
+        col.prop(sss, "radius", text="RGB Radius", expand=True)
 
         if wide_ui:
             col = split.column()

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2009-12-02 07:56:34 UTC (rev 25065)
@@ -43,7 +43,7 @@
 struct ReportList;
 
 #define BLENDER_VERSION			250
-#define BLENDER_SUBVERSION		7
+#define BLENDER_SUBVERSION		8
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/BKE_colortools.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_colortools.h	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenkernel/BKE_colortools.h	2009-12-02 07:56:34 UTC (rev 25065)
@@ -34,12 +34,6 @@
 struct ImBuf;
 struct rctf;
 
-void 				gamma_correct_rec709(float *c, float gamma);
-void				gamma_correct(float *c, float gamma);
-float				srgb_to_linearrgb(float c);
-float				linearrgb_to_srgb(float c);
-void				color_manage_linearize(float *col_to, float *col_from);
-
 void				floatbuf_to_srgb_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w);
 void				floatbuf_to_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w);
 

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2009-12-02 07:56:34 UTC (rev 25065)
@@ -58,53 +58,7 @@
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
-/* ********************************* color transforms ********************************* */
 
-/*Transform linear RGB values to nonlinear RGB values. Rec.
-  709 is ITU-R Recommendation BT. 709 (1990) ``Basic
-  Parameter Values for the HDTV Standard for the Studio and
-  for International Programme Exchange'', formerly CCIR Rec.
-  709.*/
-void gamma_correct_rec709(float *c, float gamma)
-{
-	/* Rec. 709 gamma correction. */
-	const float cc = 0.018f;
-	
-	if (*c < cc)
-	    *c *= ((1.099f * (float)powf(cc, gamma)) - 0.099f) * (1.0f/cc);
-	else 
-	    *c = (1.099f * (float)powf(*c, gamma)) - 0.099f;
-}
-
-void gamma_correct(float *c, float gamma)
-{
-	*c = powf((*c), gamma);
-}
-
-float srgb_to_linearrgb(float c)
-{
-	if (c < 0.04045f)
-		return (c < 0.0f)? 0.0f: c*(1.0f/12.92f);
-	else
-		return powf((c + 0.055f)*(1.0f/1.055f), 2.4f);
-}
-
-float linearrgb_to_srgb(float c)
-{
-	if (c < 0.0031308f)
-		return (c < 0.0f)? 0.0f: c * 12.92f;
-	else
-		return  1.055f * powf(c, 1.0f/2.4f) - 0.055f;
-}
-
-/* utility function convert an RGB triplet from sRGB to linear RGB color space */
-void color_manage_linearize(float *col_to, float *col_from)
-{
-	col_to[0] = srgb_to_linearrgb(col_from[0]);
-	col_to[1] = srgb_to_linearrgb(col_from[1]);
-	col_to[2] = srgb_to_linearrgb(col_from[2]);
-}
-
 void floatbuf_to_srgb_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w)
 {
 	int x, y;

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2009-12-02 07:56:34 UTC (rev 25065)
@@ -795,7 +795,7 @@
 	la->sun_intensity = 1.0f;
 	la->skyblendtype= MA_RAMP_ADD;
 	la->skyblendfac= 1.0f;
-	la->sky_colorspace= BLI_CS_CIE;
+	la->sky_colorspace= BLI_XYZ_CIE;
 	la->sky_exposure= 1.0f;
 	
 	curvemapping_initialize(la->curfalloff);

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2009-12-02 07:56:34 UTC (rev 25065)
@@ -32,10 +32,16 @@
 extern "C" {
 #endif
 
-#define BLI_CS_SMPTE	0
-#define BLI_CS_REC709	1
-#define BLI_CS_CIE		2
+/* primaries */
+#define BLI_XYZ_SMPTE	0
+#define BLI_XYZ_REC709_SRGB	1
+#define BLI_XYZ_CIE		2
 
+/* built-in profiles */
+#define BLI_PR_NONE		0
+#define BLI_PR_SRGB		1
+#define BLI_PR_REC709	2
+	
 /******************* Conversion to RGB ********************/
 
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
@@ -53,6 +59,16 @@
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 
+/***************** Profile Transformations ********************/
+
+void gamma_correct(float *c, float gamma);
+float rec709_to_linearrgb(float c);
+float linearrgb_to_rec709(float c);
+float srgb_to_linearrgb(float c);
+float linearrgb_to_srgb(float c);
+void srgb_to_linearrgb_v3_v3(float *col_to, float *col_from);
+void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from);
+	
 /************************** Other *************************/
 
 int constrain_rgb(float *r, float *g, float *b);

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2009-12-02 07:56:34 UTC (rev 25065)
@@ -208,17 +208,17 @@
 void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)
 {
 	switch (colorspace) { 
-	case BLI_CS_SMPTE:
+	case BLI_XYZ_SMPTE:
 		*r = (3.50570f	 * xc) + (-1.73964f	 * yc) + (-0.544011f * zc);
 		*g = (-1.06906f	 * xc) + (1.97781f	 * yc) + (0.0351720f * zc);
 		*b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f	 * zc);
 		break;
-	case BLI_CS_REC709:
+	case BLI_XYZ_REC709_SRGB:
 		*r = (3.240476f	 * xc) + (-1.537150f * yc) + (-0.498535f * zc);
 		*g = (-0.969256f * xc) + (1.875992f  * yc) + (0.041556f  * zc);
 		*b = (0.055648f	 * xc) + (-0.204043f * yc) + (1.057311f  * zc);
 		break;
-	case BLI_CS_CIE:
+	case BLI_XYZ_CIE:
 		*r = (2.28783848734076f	* xc) + (-0.833367677835217f	* yc) + (-0.454470795871421f	* zc);
 		*g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc);
 		*b = (0.00572040983140966f	* xc) + (-0.0159068485104036f	* yc) + (1.0101864083734f	* zc);
@@ -274,6 +274,61 @@
 	*b /= 255.0f;
 }
 
+/* ********************************* color transforms ********************************* */
+
+
+void gamma_correct(float *c, float gamma)
+{
+	*c = powf((*c), gamma);
+}
+
+float rec709_to_linearrgb(float c)
+{
+	if (c < 0.081f)
+		return (c < 0.0f)? 0.0f: c * (1.0f/4.5f);
+	else
+		return powf((c + 0.099f)*(1.0f/1.099f), (1.0f/0.45f));
+}
+
+float linearrgb_to_rec709(float c)
+{
+	if (c < 0.018f)
+		return (c < 0.0f)? 0.0f: c * 4.5f;
+	else
+		return 1.099f * powf(c, 0.45f) - 0.099f;
+}
+
+float srgb_to_linearrgb(float c)
+{
+	if (c < 0.04045f)
+		return (c < 0.0f)? 0.0f: c * (1.0f/12.92f);
+	else
+		return powf((c + 0.055f)*(1.0f/1.055f), 2.4f);
+}
+
+float linearrgb_to_srgb(float c)
+{
+	if (c < 0.0031308f)
+		return (c < 0.0f)? 0.0f: c * 12.92f;
+	else
+		return  1.055f * powf(c, 1.0f/2.4f) - 0.055f;
+}
+
+void srgb_to_linearrgb_v3_v3(float *col_to, float *col_from)
+{
+	col_to[0] = srgb_to_linearrgb(col_from[0]);
+	col_to[1] = srgb_to_linearrgb(col_from[1]);
+	col_to[2] = srgb_to_linearrgb(col_from[2]);
+}
+
+void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from)
+{
+	col_to[0] = linearrgb_to_srgb(col_from[0]);
+	col_to[1] = linearrgb_to_srgb(col_from[1]);
+	col_to[2] = linearrgb_to_srgb(col_from[2]);
+}
+
+
 void minmax_rgb(short c[])
 {
 	if(c[0]>255) c[0]=255;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-12-02 04:12:16 UTC (rev 25064)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-12-02 07:56:34 UTC (rev 25065)
@@ -10064,7 +10064,7 @@
 		}
 	}
 
-	/* put 2.50 compatibility code here until next subversion bump */
+	if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8))
 	{
 		{
 			Scene *sce= main->scene.first;
@@ -10108,7 +10108,47 @@
 				ob=ob->id.next;
 			}
 		}
+		
+		/* only convert old 2.50 files with color management */
+		if (main->versionfile == 250) {
+			Scene *sce=main->scene.first;
+			Material *ma=main->mat.first;
+			World *wo=main->world.first;
+			int convert=0;
+			
+			/* convert to new color management system:
+			 while previously colors were stored as srgb, 
+			 now they are stored as linear internally, 
+			 with screen gamma correction in certain places in the UI. */
+
+			/* don't know what scene is active, so we'll convert if any scene has it enabled... */
+			while (sce) {
+				if(sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
+					convert=1;
+				sce=sce->id.next;
+			}
+			
+			if (convert) {
+				while(ma) {
+					srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
+					srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
+					srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
+					srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
+					ma=ma->id.next;
+				}
+				
+				while(wo) {
+					srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
+					srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
+					srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
+					wo=wo->id.next;
+				}
+			}
+		}
 	}
+	
+	/* put 2.50 compatibility code here until next subversion bump */
+	
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */

Modified: trunk/blender/source/blender/editors/interface/interface.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list