[Bf-blender-cvs] [14de836] master: Smoke (fire): Move spectrum code from C++ (intern/) to C code (BLI)

Kévin Dietrich noreply at git.blender.org
Sat Jan 9 04:49:10 CET 2016


Commit: 14de8361f97c64b3d99b6e009fc8e9d19f90a328
Author: Kévin Dietrich
Date:   Sat Jan 9 04:48:31 2016 +0100
Branches: master
https://developer.blender.org/rB14de8361f97c64b3d99b6e009fc8e9d19f90a328

Smoke (fire): Move spectrum code from C++ (intern/) to C code (BLI)

This change is for a few reasons:
- it works with color, and (therefore) will need to be color managed, at
some point. This will be much easier to do if the code is closer to the
actual color management code (in Blender's core, so to speak).
- it has nothing to do with the actual fire simulation, as it is just
used to create a lookup table
- it can be reused for other purposes (i.e. in Blender internal
renderer, if people are interrested in a blackbody node à la Cycles)
- cleanup: some functions (`contrain_rgb`, `xyz_to_rgb`) already exist
in BLI

Reviewers: brecht

Reviewed By: brecht

Subscribers: brecht

Differential Revision: https://developer.blender.org/D1719

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

M	intern/smoke/CMakeLists.txt
M	intern/smoke/extern/smoke_API.h
M	intern/smoke/intern/smoke_API.cpp
D	intern/smoke/intern/spectrum.cpp
D	intern/smoke/intern/spectrum.h
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/blenlib/BLI_math_color.h
M	source/blender/blenlib/intern/math_color.c
M	source/blender/editors/space_view3d/drawvolume.c

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

diff --git a/intern/smoke/CMakeLists.txt b/intern/smoke/CMakeLists.txt
index 8cda0fd..57678ec 100644
--- a/intern/smoke/CMakeLists.txt
+++ b/intern/smoke/CMakeLists.txt
@@ -40,7 +40,6 @@ set(SRC
 	intern/FLUID_3D_SOLVERS.cpp
 	intern/FLUID_3D_STATIC.cpp
 	intern/LU_HELPER.cpp
-	intern/spectrum.cpp
 	intern/SPHERE.cpp
 	intern/WTURBULENCE.cpp
 	intern/smoke_API.cpp
@@ -54,7 +53,6 @@ set(SRC
 	intern/LU_HELPER.h
 	intern/MERSENNETWISTER.h
 	intern/OBSTACLE.h
-	intern/spectrum.h
 	intern/SPHERE.h
 	intern/VEC3.h
 	intern/WAVELET_NOISE.h
diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h
index 08dbded..a68a587 100644
--- a/intern/smoke/extern/smoke_API.h
+++ b/intern/smoke/extern/smoke_API.h
@@ -99,9 +99,6 @@ void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, fl
 void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel,
 							 float **r, float **g, float **b, float **tcu, float **tcv, float **tcw);
 
-/* flame spectrum */
-void flame_get_spectrum(unsigned char *spec, int width, float t1, float t2);
-
 /* data fields */
 int smoke_has_heat(struct FLUID_3D *fluid);
 int smoke_has_fuel(struct FLUID_3D *fluid);
diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp
index d79aaf7..5cab0b3 100644
--- a/intern/smoke/intern/smoke_API.cpp
+++ b/intern/smoke/intern/smoke_API.cpp
@@ -30,7 +30,6 @@
 
 #include "FLUID_3D.h"
 #include "WTURBULENCE.h"
-#include "spectrum.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -449,11 +448,6 @@ extern "C" void smoke_turbulence_set_noise(WTURBULENCE *wt, int type, const char
 	wt->setNoise(type, noisefile_path);
 }
 
-extern "C" void flame_get_spectrum(unsigned char *spec, int width, float t1, float t2)
-{
-	spectrum(t1, t2, width, spec);
-}
-
 extern "C" int smoke_has_heat(FLUID_3D *fluid)
 {
 	return (fluid->_heat) ? 1 : 0;
diff --git a/intern/smoke/intern/spectrum.cpp b/intern/smoke/intern/spectrum.cpp
deleted file mode 100644
index 15e4d0c..0000000
--- a/intern/smoke/intern/spectrum.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
-                Colour Rendering of Spectra
-
-                       by John Walker
-                  http://www.fourmilab.ch/
-		  
-		 Last updated: March 9, 2003
-
-           This program is in the public domain.
-
-    For complete information about the techniques employed in
-    this program, see the World-Wide Web document:
-
-             http://www.fourmilab.ch/documents/specrend/
-	     
-    The xyz_to_rgb() function, which was wrong in the original
-    version of this program, was corrected by:
-    
-	    Andrew J. S. Hamilton 21 May 1999
-	    Andrew.Hamilton at Colorado.EDU
-	    http://casa.colorado.edu/~ajsh/
-
-    who also added the gamma correction facilities and
-    modified constrain_rgb() to work by desaturating the
-    colour by adding white.
-    
-    A program which uses these functions to plot CIE
-    "tongue" diagrams called "ppmcie" is included in
-    the Netpbm graphics toolkit:
-    	http://netpbm.sourceforge.net/
-    (The program was called cietoppm in earlier
-    versions of Netpbm.)
-
-*/
-
-#include <stdio.h>
-#include <math.h>
-#include "spectrum.h"
-
-/* A colour system is defined by the CIE x and y coordinates of
-   its three primary illuminants and the x and y coordinates of
-   the white point. */
-
-struct colourSystem {
-    const char *name;        	    /* Colour system name */
-    double xRed, yRed,	    	    /* Red x, y */
-           xGreen, yGreen,  	    /* Green x, y */
-           xBlue, yBlue,    	    /* Blue x, y */
-           xWhite, yWhite,  	    /* White point x, y */
-	   gamma;   	    	    /* Gamma correction for system */
-};
-
-/* White point chromaticities. */
-
-#if 0
-#define IlluminantC     0.3101, 0.3162	    	/* For NTSC television */
-#define IlluminantD65   0.3127, 0.3291	    	/* For EBU and SMPTE */
-#endif
-#define IlluminantE 	0.33333333, 0.33333333  /* CIE equal-energy illuminant */
-
-/*  Gamma of nonlinear correction.
-
-    See Charles Poynton's ColorFAQ Item 45 and GammaFAQ Item 6 at:
-    
-       http://www.poynton.com/ColorFAQ.html
-       http://www.poynton.com/GammaFAQ.html
- 
-*/
-
-#define GAMMA_REC709	0		/* Rec. 709 */
-
-static struct colourSystem
-                  /* Name                  xRed    yRed    xGreen  yGreen  xBlue  yBlue    White point        Gamma   */
-#if 0 /* UNUSED */
-    NTSCsystem  =  { "NTSC",               0.67,   0.33,   0.21,   0.71,   0.14,   0.08,   IlluminantC,    GAMMA_REC709 },
-    EBUsystem   =  { "EBU (PAL/SECAM)",    0.64,   0.33,   0.29,   0.60,   0.15,   0.06,   IlluminantD65,  GAMMA_REC709 },
-    SMPTEsystem =  { "SMPTE",              0.630,  0.340,  0.310,  0.595,  0.155,  0.070,  IlluminantD65,  GAMMA_REC709 },
-    HDTVsystem  =  { "HDTV",               0.670,  0.330,  0.210,  0.710,  0.150,  0.060,  IlluminantD65,  GAMMA_REC709 },
-#endif
-
-    CIEsystem   =  { "CIE",                0.7355, 0.2645, 0.2658, 0.7243, 0.1669, 0.0085, IlluminantE,    GAMMA_REC709 };
-
-#if 0 /* UNUSED */
-    Rec709system = { "CIE REC 709",        0.64,   0.33,   0.30,   0.60,   0.15,   0.06,   IlluminantD65,  GAMMA_REC709 };
-#endif
-
-/*  	    	    	    UPVP_TO_XY
-
-    Given 1976 coordinates u', v', determine 1931 chromaticities x, y
-    
-*/
-
-#if 0 /* UNUSED */
-static void upvp_to_xy(double up, double vp, double *xc, double *yc)
-{
-    *xc = (9 * up) / ((6 * up) - (16 * vp) + 12);
-    *yc = (4 * vp) / ((6 * up) - (16 * vp) + 12);
-}
-#endif
-
-/*  	    	    	    XY_TO_UPVP
-
-    Given 1931 chromaticities x, y, determine 1976 coordinates u', v'
-    
-*/
-
-#if 0 /* UNUSED */
-static void xy_to_upvp(double xc, double yc, double *up, double *vp)
-{
-    *up = (4 * xc) / ((-2 * xc) + (12 * yc) + 3);
-    *vp = (9 * yc) / ((-2 * xc) + (12 * yc) + 3);
-}
-#endif
-
-/*                             XYZ_TO_RGB
-
-    Given an additive tricolour system CS, defined by the CIE x
-    and y chromaticities of its three primaries (z is derived
-    trivially as 1-(x+y)), and a desired chromaticity (XC, YC,
-    ZC) in CIE space, determine the contribution of each
-    primary in a linear combination which sums to the desired
-    chromaticity.  If the  requested chromaticity falls outside
-    the Maxwell  triangle (colour gamut) formed by the three
-    primaries, one of the r, g, or b weights will be negative. 
-
-    Caller can use constrain_rgb() to desaturate an
-    outside-gamut colour to the closest representation within
-    the available gamut and/or norm_rgb to normalise the RGB
-    components so the largest nonzero component has value 1.
-    
-*/
-
-static void xyz_to_rgb(struct colourSystem *cs,
-                       double xc, double yc, double zc,
-                       double *r, double *g, double *b)
-{
-    double xr, yr, zr, xg, yg, zg, xb, yb, zb;
-    double xw, yw, zw;
-    double rx, ry, rz, gx, gy, gz, bx, by, bz;
-    double rw, gw, bw;
-
-    xr = cs->xRed;    yr = cs->yRed;    zr = 1 - (xr + yr);
-    xg = cs->xGreen;  yg = cs->yGreen;  zg = 1 - (xg + yg);
-    xb = cs->xBlue;   yb = cs->yBlue;   zb = 1 - (xb + yb);
-
-    xw = cs->xWhite;  yw = cs->yWhite;  zw = 1 - (xw + yw);
-
-    /* xyz -> rgb matrix, before scaling to white. */
-    
-    rx = (yg * zb) - (yb * zg);  ry = (xb * zg) - (xg * zb);  rz = (xg * yb) - (xb * yg);
-    gx = (yb * zr) - (yr * zb);  gy = (xr * zb) - (xb * zr);  gz = (xb * yr) - (xr * yb);
-    bx = (yr * zg) - (yg * zr);  by = (xg * zr) - (xr * zg);  bz = (xr * yg) - (xg * yr);
-
-    /* White scaling factors.
-       Dividing by yw scales the white luminance to unity, as conventional. */
-       
-    rw = ((rx * xw) + (ry * yw) + (rz * zw)) / yw;
-    gw = ((gx * xw) + (gy * yw) + (gz * zw)) / yw;
-    bw = ((bx * xw) + (by * yw) + (bz * zw)) / yw;
-
-    /* xyz -> rgb matrix, correctly scaled to white. */
-    
-    rx = rx / rw;  ry = ry / rw;  rz = rz / rw;
-    gx = gx / gw;  gy = gy / gw;  gz = gz / gw;
-    bx = bx / bw;  by = by / bw;  bz = bz / bw;
-
-    /* rgb of the desired point */
-
-    *r = (rx * xc) + (ry * yc) + (rz * zc);
-    *g = (gx * xc) + (gy * yc) + (gz * zc);
-    *b = (bx * xc) + (by * yc) + (bz * zc);
-}
-
-/*                            INSIDE_GAMUT
-
-     Test whether a requested colour is within the gamut
-     achievable with the primaries of the current colour
-     system.  This amounts simply to testing whether all the
-     primary weights are non-negative. */
-
-#if 0 /* UNUSED */
-static int inside_gamut(double r, double g, double b)
-{
-    return (r >= 0) && (g >= 0) && (b >= 0);
-}
-#endif
-
-/*                          CONSTRAIN_RGB
-
-    If the requested RGB shade contains a negative weight for
-    one of the primaries, it lies outside the colour gamut 
-    accessible from the given triple of primaries.  Desaturate
-    it by adding white, equal quantities of R, G, and B, enough
-    to make RGB all positive.  The function returns 1 if the
-    components were modified, zero otherwise.
-    
-*/
-
-static int constrain_rgb(double *r, double *g, double *b)
-{
-    double w;
-
-    /* Amount of white needed is w = - min(0, *r, *g, *b) */
-    
-    w = (0 < *r) ? 0 : *r;
-    w = (w < *g) ? w : *g;
-    w = (w < *b) ? w : *b;
-    w = -w;
-
-    /* Add just enough white to make r, g, b all positive. */
-    
-    if (w > 0) {
-        *r += w;  *g += w; *b += w;
-        return 1;                     /* Colour modified to fit RGB gamut */
-    }
-
-    return 0;                         /* Colour within RGB gamut */
-}
-
-/*                          GAMMA_CORRECT_RGB
-
-    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. For details see
-    
-       http://www.poynton.com/ColorFAQ.html
-       http://www.poynton.com/GammaFAQ.html
-*/
-
-#if 0 /* UNUSED */
-static void gamma_correct(const struct colourSystem *cs, double *c)
-{
-    double gamma;
-
-    gamma = cs->gamma;
-
-    if (gamma == GAMMA_REC709) {
-	/* Rec. 709 gamma correction. */
-	double cc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list