[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21649] branches/blender2.5/blender: Colour Management
Matt Ebb
matt at mke3.net
Fri Jul 17 04:43:18 CEST 2009
Revision: 21649
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21649
Author: broken
Date: 2009-07-17 04:43:15 +0200 (Fri, 17 Jul 2009)
Log Message:
-----------
Colour Management
- 1st stage: Linear Workflow
This implements automatic linear workflow in Blender's renderer. With the
new Colour Management option on in the Render buttons, all inputs to the
renderer and compositor are converted to linear colour space before
rendering, and gamma corrected afterwards. In essence, this makes all
manual gamma correction with nodes, etc unnecessary, since it's done
automatically through the pipeline.
It's all explained much better in the notes/doc here, so please have a look:
http://wiki.blender.org/index.php/Dev:Source/Blender/Architecture/Colour_Management
And an example of the sort of difference it makes:
http://mke3.net/blender/devel/rendering/b25_colormanagement_test01.jpg
This also enables Colour Management in the default B.blend, and changes the
default lamp falloff to inverse square, which is more correct, and much
easier to use now it's all gamma corrected properly.
Next step is to look into profiles/soft proofing for the compositor.
Thanks to brecht for reviewing and fixing some oversights!
Modified Paths:
--------------
branches/blender2.5/blender/release/datafiles/preview.blend
branches/blender2.5/blender/release/ui/buttons_scene.py
branches/blender2.5/blender/source/blender/blenkernel/BKE_colortools.h
branches/blender2.5/blender/source/blender/blenkernel/intern/colortools.c
branches/blender2.5/blender/source/blender/blenkernel/intern/object.c
branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c
branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
branches/blender2.5/blender/source/blender/editors/datafiles/B.blend.c
branches/blender2.5/blender/source/blender/editors/datafiles/preview.blend.c
branches/blender2.5/blender/source/blender/editors/include/BIF_glutil.h
branches/blender2.5/blender/source/blender/editors/preview/previewrender.c
branches/blender2.5/blender/source/blender/editors/screen/glutil.c
branches/blender2.5/blender/source/blender/editors/screen/screen_ops.c
branches/blender2.5/blender/source/blender/editors/space_image/image_draw.c
branches/blender2.5/blender/source/blender/editors/space_image/image_render.c
branches/blender2.5/blender/source/blender/imbuf/IMB_imbuf_types.h
branches/blender2.5/blender/source/blender/imbuf/intern/divers.c
branches/blender2.5/blender/source/blender/makesdna/DNA_scene_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_scene.c
branches/blender2.5/blender/source/blender/nodes/intern/CMP_nodes/CMP_image.c
branches/blender2.5/blender/source/blender/render/intern/include/shading.h
branches/blender2.5/blender/source/blender/render/intern/source/convertblender.c
branches/blender2.5/blender/source/blender/render/intern/source/pipeline.c
branches/blender2.5/blender/source/blender/render/intern/source/pixelshading.c
branches/blender2.5/blender/source/blender/render/intern/source/rayshade.c
branches/blender2.5/blender/source/blender/render/intern/source/rendercore.c
branches/blender2.5/blender/source/blender/render/intern/source/shadeinput.c
branches/blender2.5/blender/source/blender/render/intern/source/sss.c
branches/blender2.5/blender/source/blender/render/intern/source/strand.c
branches/blender2.5/blender/source/blender/render/intern/source/texture.c
Modified: branches/blender2.5/blender/release/datafiles/preview.blend
===================================================================
(Binary files differ)
Modified: branches/blender2.5/blender/release/ui/buttons_scene.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_scene.py 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/release/ui/buttons_scene.py 2009-07-17 02:43:15 UTC (rev 21649)
@@ -118,6 +118,7 @@
col = split.column()
col.itemR(rd, "render_envmaps", text="Environment Map")
col.itemR(rd, "render_raytracing", text="Ray Tracing")
+ col.itemR(rd, "color_management")
col.itemR(rd, "alpha_mode", text="Alpha")
class RENDER_PT_performance(RenderButtonsPanel):
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_colortools.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_colortools.h 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_colortools.h 2009-07-17 02:43:15 UTC (rev 21649)
@@ -33,7 +33,16 @@
struct CurveMap;
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);
+
struct CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, float maxy);
void curvemapping_free(struct CurveMapping *cumap);
struct CurveMapping *curvemapping_copy(struct CurveMapping *cumap);
@@ -60,5 +69,6 @@
void curvemapping_table_RGBA(struct CurveMapping *cumap, float **array, int *size);
void colorcorrection_do_ibuf(struct ImBuf *ibuf, const char *profile);
+
#endif
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/colortools.c 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/colortools.c 2009-07-17 02:43:15 UTC (rev 21649)
@@ -58,6 +58,91 @@
#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. */
+ float cc = 0.018f;
+
+ if (*c < cc)
+ *c *= ((1.099f * (float)pow(cc, gamma)) - 0.099f) / cc;
+ else
+ *c = (1.099f * (float)pow(*c, gamma)) - 0.099f;
+}
+
+void gamma_correct(float *c, float gamma)
+{
+ *c = pow((*c), gamma);
+}
+
+float srgb_to_linearrgb(float c)
+{
+ if (c < 0.04045f)
+ return (c < 0.f)?0.f:c / 12.92;
+ else
+ return pow((c + 0.055)/1.055, 2.4);
+}
+
+float linearrgb_to_srgb(float c)
+{
+ if (c < 0.0031308)
+ return (c < 0.f)?0.f:c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0/2.4) - 0.055;
+}
+
+/* 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;
+ float *rf= rectf;
+ float srgb[3];
+ unsigned char *rc= rectc;
+
+ for(y=y1; y<y2; y++) {
+ for(x=x1; x<x2; x++, rf+=4, rc+=4) {
+ srgb[0]= linearrgb_to_srgb(rf[0]);
+ srgb[1]= linearrgb_to_srgb(rf[1]);
+ srgb[2]= linearrgb_to_srgb(rf[2]);
+
+ rc[0]= FTOCHAR(srgb[0]);
+ rc[1]= FTOCHAR(srgb[1]);
+ rc[2]= FTOCHAR(srgb[2]);
+ rc[3]= FTOCHAR(rf[3]);
+ }
+ }
+}
+
+void floatbuf_to_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w)
+{
+ int x, y;
+ float *rf= rectf;
+ unsigned char *rc= rectc;
+
+ for(y=y1; y<y2; y++) {
+ for(x=x1; x<x2; x++, rf+=4, rc+=4) {
+ rc[0]= FTOCHAR(rf[0]);
+ rc[1]= FTOCHAR(rf[1]);
+ rc[2]= FTOCHAR(rf[2]);
+ rc[3]= FTOCHAR(rf[3]);
+ }
+ }
+}
+
+
/* ********************************* color curve ********************* */
/* ***************** operations on full struct ************* */
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/object.c 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/object.c 2009-07-17 02:43:15 UTC (rev 21649)
@@ -715,7 +715,7 @@
la->r= la->g= la->b= la->k= 1.0f;
la->haint= la->energy= 1.0f;
- la->dist= 20.0f;
+ la->dist= 25.0f;
la->spotsize= 45.0f;
la->spotblend= 0.15f;
la->att2= 1.0f;
@@ -734,7 +734,7 @@
la->ray_samp_method = LA_SAMP_HALTON;
la->adapt_thresh = 0.001f;
la->preview=NULL;
- la->falloff_type = LA_FALLOFF_INVLINEAR;
+ la->falloff_type = LA_FALLOFF_INVSQUARE;
la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
la->sun_effect_type = 0;
la->horizon_brightness = 1.0;
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c 2009-07-17 02:43:15 UTC (rev 21649)
@@ -223,6 +223,7 @@
sce->r.frs_sec= 25;
sce->r.frs_sec_base= 1;
sce->r.ocres = 128;
+ sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
sce->r.bake_mode= 1; /* prevent to include render stuff here */
sce->r.bake_filter= 8;
Modified: branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h 2009-07-17 02:43:15 UTC (rev 21649)
@@ -339,7 +339,6 @@
void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace);
int constrain_rgb(float *r, float *g, float *b);
-void gamma_correct_rgb(float *r, float *g, float *b);
unsigned int hsv_to_cpack(float h, float s, float v);
unsigned int rgb_to_cpack(float r, float g, float b);
void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
Modified: branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c 2009-07-17 02:43:15 UTC (rev 21649)
@@ -3542,36 +3542,13 @@
if (w > 0) {
*r += w; *g += w; *b += w;
- return 1; /* Colour modified to fit RGB gamut */
+ return 1; /* Color modified to fit RGB gamut */
}
- return 0; /* Colour within RGB gamut */
+ return 0; /* Color within RGB gamut */
}
-/*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.*/
-static void gamma_correct(float *c)
-{
- /* Rec. 709 gamma correction. */
- float cc = 0.018f;
-
- if (*c < cc)
- *c *= ((1.099f * (float)pow(cc, 0.45)) - 0.099f) / cc;
- else
- *c = (1.099f * (float)pow(*c, 0.45)) - 0.099f;
-}
-void gamma_correct_rgb(float *r, float *g, float *b)
-{
- gamma_correct(r);
- gamma_correct(g);
- gamma_correct(b);
-}
-
-
/* we define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so.
for that reason it is sensitive for endianness... with this function it works correctly
*/
Modified: branches/blender2.5/blender/source/blender/editors/datafiles/B.blend.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/datafiles/B.blend.c 2009-07-17 02:31:28 UTC (rev 21648)
+++ branches/blender2.5/blender/source/blender/editors/datafiles/B.blend.c 2009-07-17 02:43:15 UTC (rev 21649)
@@ -1,619 +1,694 @@
/* DataToC output of file <B_blend> */
-int datatoc_B_blend_size= 106004;
+int datatoc_B_blend_size= 106008;
char datatoc_B_blend[]= {
- 66, 76, 69, 78, 68, 69, 82, 45,118, 50, 53, 48, 82, 69, 78, 68, 32, 0, 0, 0,
-128, 13,156,230,255,127, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,250, 0, 0, 0, 83, 99,101,110,101, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 76, 79, 66, 40, 0, 0, 0,112, 13,156,230,255,127, 0, 0,
-184, 0, 0, 0, 1, 0, 0, 0, 32, 32, 32, 48, 0, 0, 0, 0,250, 0, 0, 0, 1, 0, 0, 1, 48, 3,160, 2, 0, 0, 0, 0,
- 32,116,160, 2, 0, 0, 0, 0, 0, 16, 0, 0,128, 32, 4, 0, 87, 77, 0, 0,208, 0, 0, 0, 0, 1,160, 2, 0, 0, 0, 0,
- 72, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 87, 77, 87,105,110, 77, 97,110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 2,160, 2, 0, 0, 0, 0, 16, 2,160, 2, 0, 0, 0, 0,
- 16, 2,160, 2, 0, 0, 0, 0, 16, 2,160, 2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 64,203,233, 2, 0, 0, 0, 0,
-224,220,232, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list