void DrawNoise8bit (CG16bitImage &Dest, int x, int y, int cxWidth, int cyHeight, int iScale, BYTE byMin, BYTE byMax)

//	DrawNoise8bit
//
//	Draws 8-bit Perlin noise

	{
	ASSERT(iScale > 0);

	NoiseInit();

	//	Make sure we're in bounds

	if (!Dest.HasAlpha() || !Dest.AdjustCoords(NULL, NULL, 0, 0, 
			&x, &y, 
			&cxWidth, &cyHeight))
		return;

	//	Noise returns numbers from -1.0 to 1.0, so we need to scale to appropriate values
	//	Note: We add 0.99999 because we will later truncate to integers and we want
	//	255.0 - 255.99999 to equal 255. We can't add more 9s because floating-point precision
	//	will turn it into 256.0.

	float rRange = (float)(byMax - byMin) + 0.99999f;
	float rFactor = rRange / 2.0f;

	//	Prepare

	CNoiseGenerator Noise(iScale);
	SNoisePos xP, yP;

	//	Fill

	Noise.Reset(yP, y);

	BYTE *pRow = Dest.GetAlphaRow(y);
	BYTE *pRowEnd = Dest.GetAlphaRow(y + cyHeight);
	while (pRow < pRowEnd)
		{
		Noise.Reset(xP, x);

		BYTE *pPos = pRow;
		BYTE *pPosEnd = pRow + cxWidth;
		while (pPos < pPosEnd)
			{
			float rNoise = Noise.GetAt(xP, yP);
			*pPos = byMin + (BYTE)(DWORD)(rFactor * (1.0f + rNoise));

			//	Next pixel

			pPos++;
			Noise.Next(xP);
			}

		//	Next row

		pRow = Dest.NextAlphaRow(pRow);
		Noise.Next(yP);
		}
	}
int _tmain(int argc, _TCHAR* argv[])
{
	NoiseInit();

	txResourceManageer resource;
	txScene *scene = resource.txReadRayFile(g_sceneName);

	if (!scene) exit(1);

	// trial save file
	char * filenamebkp = "D:\\pictures\\trial.jpg";
	txImage image(512,512);
	txRgb equalcolor(0.5,0.5,0.5);
	for (size_t i=0; i<512; i++){
		image.SetPixelRGB(i,40,equalcolor);
		image.SetPixelRGB(i,41,equalcolor);
		image.SetPixelRGB(i,42,equalcolor);
	}
	image.WriteJPEG(filenamebkp);

	return 0;
}
Exemple #3
0
/*
 * Set default parameters
 */
void
RSSetup()
{
	extern SurfList *CurSurf;
	extern Medium TopMedium;
	extern void NoiseInit();
#ifdef MULTIMAX
	unsigned int bytes;

	/*
	 * Initialize shared memory stuff.
	 */
	bytes = 1 << SHARED_BYTES;
	if (share_malloc_init(bytes) == -1) {
		RLerror(RL_PANIC, "Cannot share_malloc %d bytes.\n",bytes);
	} else
		fprintf(fstats,"Malloced %d bytes of shared memory.\n",
				bytes);
#endif

	Camera.hfov = HFOV;
	Camera.vfov = UNSET;
	Camera.pos.x = EYEX;
	Camera.pos.y = EYEY;
	Camera.pos.z = EYEZ;
	Camera.lookp.x = LOOKX;
	Camera.lookp.y = LOOKY;
	Camera.lookp.z = LOOKZ;
	Camera.up.x = UPX;
	Camera.up.y = UPY;
	Camera.up.z = UPZ;
	Camera.focaldist = UNSET;
	Camera.aperture = 0.;

	Screen.xres = Screen.yres = UNSET;

	Options.cpp = TRUE;
	Options.maxdepth = MAXDEPTH;
	Options.report_freq = REPORTFREQ;
	Options.jitter = TRUE;
	Options.samples = UNSET;
	Options.gaussian = GAUSSIAN;
	Options.filterwidth = UNSET;
	Options.contrast.r = UNSET;
	Options.ambient.r = Options.ambient.g =
		Options.ambient.b = 1.0;
	Options.cutoff.r = UNSET;
	Options.cache = TRUE;
	Options.shadowtransp = TRUE;
	Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
	Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
	Stats.fstats = stderr;
	Options.pictfile = stdout;
#ifdef URT
	Options.alpha = TRUE;
	Options.exp_output = FALSE;
#endif
	Options.gamma = GAMMA;
	Options.eyesep = UNSET;
#ifdef LINDA
	Options.workers = WORKERS;
#endif

	Options.totalframes = 1;
	Options.startframe = 0;
	Options.starttime = 0.;
	Options.framelength = 1.;
	Options.shutterspeed = 0.;

	TopMedium.index = DEFAULT_INDEX;
	TopMedium.statten = 1.0;
	NoiseInit();			/* Initialize values for Noise() */

	/*
	 * Top of object definition stack points to the World object.
	 * The World object is always a list.
	 */
	Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
	Defstack->obj->name = strsave("World");
	/* Initialize surface stack */
	CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
}
void DrawNebulosity8bit (CG16bitImage &Dest, int x, int y, int cxWidth, int cyHeight, int iScale, BYTE byMin, BYTE byMax)

//	DrawNebulosity8bit
//
//	Draws 8-bit clouds.

	{
	int i;

	ASSERT(iScale > 0);

	NoiseInit();

	//	Make sure we're in bounds

	if (!Dest.HasAlpha() || !Dest.AdjustCoords(NULL, NULL, 0, 0, 
			&x, &y, 
			&cxWidth, &cyHeight))
		return;

	//	We need noise generators for each frequency

	struct SFreq
		{
		int iFreq;
		float Amplitude;
		CNoiseGenerator *pNoise;
		SNoisePos x;
		SNoisePos y;
		};

	TArray<SFreq> FreqList;

	//	At iMinFreq = 1 we create detail all the way to the pixel level.

	int iMinFreq = 1;//Max(iScale / 256, 1);

	//	In theory, the noise function returns values from -1.0 to 1.0, but
	//	in practice the values are clutered between -0.5 to 0.5. We multiply
	//	the result by this amplitude adjustment so that we get a greater
	//	dynamic range.

	float rAmplitudeAdj = 2.0f;

	//	As we get to smaller and smaller detail, the amplitude decreases
	//	(by half for each frequency). But if there are too many levels of
	//	detail, the amplitude decreases so much that it is invisible.
	//	Thus we have a minimum amplitude.

	float rMinAmplitude = (float)iScale / 32.0f;

	//	Create noise generators are each frequency.

	float rMaxValue = 0.0;
	int iFreq = iScale;
	while (iFreq >= iMinFreq)
		{
		SFreq *pFreq = FreqList.Insert();

		pFreq->iFreq = iFreq;
		pFreq->pNoise = new CNoiseGenerator(iFreq);
		pFreq->Amplitude = rAmplitudeAdj * Max((float)iFreq, rMinAmplitude);

		rMaxValue += (pFreq->Amplitude / rAmplitudeAdj);

		iFreq = iFreq / 2;
		};

	//	Compute the factor to adjust the pixel value

	float rRange = (float)(byMax - byMin) + 0.99999f;
	float rFactor = rRange / (2.0f * rMaxValue);

	int iFreqCount = FreqList.GetCount();

	//	Fill

	for (i = 0; i < iFreqCount; i++)
		FreqList[i].pNoise->Reset(FreqList[i].y, y);

	BYTE *pRow = Dest.GetAlphaRow(y);
	BYTE *pRowEnd = Dest.GetAlphaRow(y + cyHeight);
	while (pRow < pRowEnd)
		{
		for (i = 0; i < iFreqCount; i++)
			FreqList[i].pNoise->Reset(FreqList[i].x, x);

		BYTE *pPos = pRow;
		BYTE *pPosEnd = pRow + cxWidth;
		while (pPos < pPosEnd)
			{
			float rValue = rMaxValue;
			for (i = 0; i < iFreqCount; i++)
				{
				SFreq *pFreq = &FreqList[i];
				rValue += pFreq->pNoise->GetAt(pFreq->x, pFreq->y) * pFreq->Amplitude;

				pFreq->pNoise->Next(pFreq->x);
				}

			*pPos = (BYTE)Clamp((DWORD)byMin + (DWORD)(rFactor * rValue), (DWORD)byMin, (DWORD)byMax);

			//	Next pixel

			pPos++;
			}

		//	Next row

		pRow = Dest.NextAlphaRow(pRow);
		for (i = 0; i < iFreqCount; i++)
			FreqList[i].pNoise->Next(FreqList[i].y);
		}

	//	Free the noise generators

	for (i = 0; i < iFreqCount; i++)
		delete FreqList[i].pNoise;
	}
Exemple #5
0
/*===========================================================================*\
 *
 *	Routine:	rt_Setup()
 *
 *	Comments:	Sets the default parameters
 *
\*===========================================================================*/
static
TQ3Status
rt_Setup(TRTDrawContext * /*inContext*/)
{
	extern Medium TopMedium;
	extern void NoiseInit();
#ifdef MULTIMAX
	unsigned int bytes;

	/*
	 * Initialize shared memory stuff.
	 */
	bytes = 1 << SHARED_BYTES;
	if (share_malloc_init(bytes) == -1) {
		RLerror(RL_PANIC, "Cannot share_malloc %d bytes.\n",bytes);
	} else
		fprintf(fstats,"Malloced %d bytes of shared memory.\n",
				bytes);
#endif

	Camera.hfov = HFOV;
	Camera.vfov = UNSET;
	Camera.pos.x = EYEX;
	Camera.pos.y = EYEY;
	Camera.pos.z = EYEZ;
	Camera.lookp.x = LOOKX;
	Camera.lookp.y = LOOKY;
	Camera.lookp.z = LOOKZ;
	Camera.up.x = UPX;
	Camera.up.y = UPY;
	Camera.up.z = UPZ;
	Camera.focaldist = UNSET;
	Camera.aperture = 0.;

	Screen.xres = Screen.yres = UNSET;

	Options.cpp = TRUE;
	Options.maxdepth = MAXDEPTH;
	Options.report_freq = REPORTFREQ;
	Options.jitter = TRUE;
	Options.samples = UNSET;
	Options.gaussian = GAUSSIAN;
	Options.filterwidth = UNSET;
	Options.contrast.r = UNSET;
	Options.ambient.r = Options.ambient.g =
		Options.ambient.b = 1.0;
	Options.cutoff.r = UNSET;
	Options.cache = TRUE;
	Options.shadowtransp = TRUE;
	Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
	Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
	Stats.fstats = stderr;
	Options.pictfile = stdout;
#ifdef URT
	Options.alpha = TRUE;
	Options.exp_output = FALSE;
#endif
	Options.gamma = GAMMA;
	Options.eyesep = UNSET;
#ifdef LINDA
	Options.workers = WORKERS;
#endif

	Options.totalframes = 1;
	Options.startframe = 0;
	Options.starttime = 0.;
	Options.framelength = 1.;
	Options.shutterspeed = 0.;

	TopMedium.index = DEFAULT_INDEX;
	TopMedium.statten = 1.0;
	NoiseInit();			/* Initialize values for Noise() */


	
	return kQ3Success;
}