#include <math.h>
#include <wb/rgb_real.hpp>
#include <wb/FileDevice.hpp>
#include <stdio.h>
#include <wb/options.hpp>
#include <3D/spectrum.hpp>

void showrange(GraphicDevice&GD, int range, int ystart,
	       Spectral&R, Spectral&G, Spectral&B, double scal)
{
rgb_real S(0,0,0);
	for(int nm=350;nm<750;nm+=range)
	{
	rgb_real C ( R(nm,nm+range), G(nm,nm+range), B(nm,nm+range) );
		S += C;
		C *= scal;
		for(int unm=0;unm<range;unm++)
		{
			for(int y=ystart;y<ystart+50;y++)
				GD.Pset(nm+unm-250,y,C);

			for(int y=ystart+50;y<ystart+100;y++)
				GD.Pset(nm+unm-250,y,S);
		}
	}
}

main(int argc, const char*argv[])
{
Targaimage_Device tga;
	tga.fopen(640,480,"1.tga");
	tga.View(350,0,750,480);

int	sshw = ioption(argc,argv,"sshw",100),
	sshwg = ioption(argc,argv,"sshwg",sshw);

Spectral R(650,sshw), G(550, sshwg), B(450, sshw);

	for(int nm=250;nm<890;nm++)
	{
	rgb_real c ( R(nm), G(nm), B(nm) );
		for(int y=0;y<45;y++)
			tga.GraphicDevice::Pset(nm-250,y, 250*c);
	double	 gi = c.grey();
	rgb_real g(gi,gi,gi);
		for(int y=45;y<55;y++)
			tga.GraphicDevice::Pset(nm-250,y, 250*g);
	
		c.unit();
		for(int y=55;y<100;y++)
			tga.GraphicDevice::Pset(nm-250,y, c);
	}

	showrange(tga, 10, 100, R,G,B, 20);
	showrange(tga, 25, 200, R,G,B, 10);
	showrange(tga, 50, 300, R,G,B, 5);
	showrange(tga,100, 400, R,G,B, 2);
}
