Exemplo n.º 1
0
void color_init() {
  double x, y, z, r, g, b;
  struct colourSystem* cs = &SMPTEsystem;

  for(int ii = 0; ii < TEMP_ENTRIES; ++ii) {
    double temp = base_temp + step * ii;
    bbTemp = temp;
    spectrum_to_xyz(bb_spectrum, &x, &y, &z);
    xyz_to_rgb(cs, x, y, z, &r, &g, &b);
    constrain_rgb(&r, &g, &b);
    norm_rgb(&r, &g, &b);

    temp_table[ii][0] = r;
    temp_table[ii][1] = g;
    temp_table[ii][2] = b;
  }
}
Exemplo n.º 2
0
void spectrum(double t1, double t2, int N, unsigned char *d)
{
	int i,j,dj;
	double X,Y,Z,R,G,B,L,M,S, Lw, Mw, Sw;
	struct colourSystem *cs = &CIEsystem;

	j = 0; dj = 1;
	if (t1<t2) {
		double t = t1;
		t1 = t2;
		t2 = t;
		j = N-1; dj=-1;
	}

	for (i=0; i<N; i++) {
		bbTemp = t1 + (t2-t1)/N*i;

			// integrate blackbody radiation spectrum to XYZ
		spectrum_to_xyz(bb_spectrum, &X, &Y, &Z);

			// normalize highest temperature to white (in LMS system)
		xyz_to_lms(X,Y,Z,&L,&M,&S);
		if (i==0) {
			Lw=1/L; Mw=1/M; Sw=1/S;
		}
		L *= Lw; M *= Mw; S *= Sw;
		lms_to_xyz(L,M,S,&X,&Y,&Z);

			// convert to RGB
		xyz_to_rgb(cs, X, Y, Z, &R, &G, &B);
		constrain_rgb(&R, &G, &B);
		norm_rgb(&R, &G, &B);
		d[(j<<2)] = (unsigned char) ((double)R*255);
		d[(j<<2)+1] = (unsigned char) ((double)G*255);
		d[(j<<2)+2] = (unsigned char) ((double)B*255);
		d[(j<<2)+3] = (B>0.1)? B*255 : 0;
		j += dj;
	}
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
NBodyWnd::NBodyWnd(int sz, std::string caption)
    :SDLWindow(sz, sz, 35000.0, caption)
    ,m_camOrient(0)
    ,m_starRenderType(1)
    ,m_flags(dspSTARS | dspAXIS | dspHELP | dspDUST | dspH2)
    ,m_bDumpImage(false)
    ,m_galaxy()
    ,m_colNum(200)
    ,m_t0(1000)
    ,m_t1(10000)
    ,m_dt( (m_t1-m_t0) /m_colNum)
{
    double x, y, z;
    for (int i=0; i<m_colNum; ++i)
    {
        Color &col = m_col[i];
        colourSystem *cs = &SMPTEsystem;
        bbTemp = m_t0 + m_dt*i;
        spectrum_to_xyz(bb_spectrum, &x, &y, &z);
        xyz_to_rgb(cs, x, y, z, &col.r, &col.g, &col.b);
        norm_rgb(&col.r, &col.g, &col.b);
    }
}
Exemplo n.º 4
0
int main()
{ 
    float t, x, y, z, r, g, b;
    struct colourSystem *cs = &SMPTEsystem;

    printf("Temperature       x      y      z       R     G     B\n");
    printf("-----------    ------ ------ ------   ----- ----- -----\n");
    
    for (t = 1000; t <= 10000; t+= 500) {
        bbTemp = t;
        spectrum_to_xyz(bb_spectrum, &x, &y, &z);
        xyz_to_rgb(cs, x, y, z, &r, &g, &b);
        printf("  %5.0f K      %.4f %.4f %.4f   ", t, x, y, z);
        if (constrain_rgb(&r, &g, &b)) {
	    norm_rgb(&r, &g, &b);
            printf("%.3f %.3f %.3f (Approximation)\n", r, g, b);
        } else {
	    norm_rgb(&r, &g, &b);
            printf("%.3f %.3f %.3f\n", r, g, b);
        }
    }
    return 0;
}