From 1118ae303329ef0d6d8a9441704f8c99886f83fe Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 15 May 2013 15:55:04 +0000 Subject: Fixed 2D linear upscale to compile on Linux, added a test for it. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1484 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Generating/Noise3DGenerator.cpp | 46 +++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'source/Generating/Noise3DGenerator.cpp') diff --git a/source/Generating/Noise3DGenerator.cpp b/source/Generating/Noise3DGenerator.cpp index 42a0d70d9..79138aa9f 100644 --- a/source/Generating/Noise3DGenerator.cpp +++ b/source/Generating/Noise3DGenerator.cpp @@ -61,14 +61,36 @@ void Debug3DNoise(NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int a_Size f2.Write(buf, a_SizeX); } // for y } // if (XZ file open) - //*/ - } +void Debug2DNoise(NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, const AString & a_FileNameBase) +{ + const int BUF_SIZE = 512; + ASSERT(a_SizeX <= BUF_SIZE); // Just stretch it, if needed + + cFile f1; + if (f1.Open(Printf("%s (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + { + for (int y = 0; y < a_SizeY; y++) + { + int idx = y * a_SizeX; + unsigned char buf[BUF_SIZE]; + for (int x = 0; x < a_SizeX; x++) + { + buf[x] = (unsigned char)(std::min(255, std::max(0, (int)(128 + 32 * a_Noise[idx++])))); + } + f1.Write(buf, a_SizeX); + } // for y + } // if (file open) +} + + + + /* // Perform an automatic test of upscaling upon program start (use breakpoints to debug): @@ -78,6 +100,7 @@ public: Test(void) { DoTest1(); + DoTest2(); } @@ -88,11 +111,26 @@ public: { In[i] = (float)(i % 5); } - Debug3DNoise(In, 3, 3, 3, "Upscale in"); + Debug3DNoise(In, 3, 3, 3, "Upscale3D in"); float Out[17 * 33 * 35]; LinearUpscale3DArray(In, 3, 3, 3, Out, 8, 16, 17); - Debug3DNoise(Out, 17, 33, 35, "Upscale test"); + Debug3DNoise(Out, 17, 33, 35, "Upscale3D test"); + } + + + void DoTest2(void) + { + float In[3 * 3]; + for (int i = 0; i < ARRAYCOUNT(In); i++) + { + In[i] = (float)(i % 5); + } + Debug2DNoise(In, 3, 3, "Upscale2D in"); + float Out[17 * 33]; + LinearUpscale2DArray(In, 3, 3, Out, 8, 16); + Debug2DNoise(Out, 17, 33, "Upscale2D test"); } + } gTest; //*/ -- cgit v1.2.3