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:
authorMatt Ebb <matt@mke3.net>2009-07-17 06:43:15 +0400
committerMatt Ebb <matt@mke3.net>2009-07-17 06:43:15 +0400
commit1ef729358517248888073be71ba5d3b6e3d723ee (patch)
treedfa33f083ac1afd500e76dcf4bc581394637d0dd /source/blender/blenkernel/intern/colortools.c
parent70f6255433fcb1f5551199ef7a285a9ab80a3318 (diff)
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!
Diffstat (limited to 'source/blender/blenkernel/intern/colortools.c')
-rw-r--r--source/blender/blenkernel/intern/colortools.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index e8716aba296..2280ec71f7a 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -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 ************* */