aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
authorUbitUmarov2019-01-07 23:54:13 +0000
committerUbitUmarov2019-01-07 23:54:13 +0000
commitc37b2094baf8077392435c1eef8ef61ccc6daf04 (patch)
tree46de43517b08da3b3294b1a89e60308b7fc44780 /OpenSim/Region/Framework/Scenes
parentmissing file (diff)
downloadopensim-SC-c37b2094baf8077392435c1eef8ef61ccc6daf04.zip
opensim-SC-c37b2094baf8077392435c1eef8ef61ccc6daf04.tar.gz
opensim-SC-c37b2094baf8077392435c1eef8ef61ccc6daf04.tar.bz2
opensim-SC-c37b2094baf8077392435c1eef8ef61ccc6daf04.tar.xz
cosmetics: terrain compressor is for 16m x 16m patchs only
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainCompressor.cs324
1 files changed, 117 insertions, 207 deletions
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
index 9d1f815..dd1f26b 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -30,16 +30,14 @@
30 * Aurora version created from libOpenMetaverse Library terrain compressor 30 * Aurora version created from libOpenMetaverse Library terrain compressor
31 */ 31 */
32 32
33// terrain patchs must be 16mx16m
34
33using System; 35using System;
34using System.Collections.Generic; 36using System.Collections.Generic;
35using System.Reflection;
36using System.Diagnostics;
37 37
38using log4net; 38using log4net;
39 39
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Region.Framework;
42using OpenSim.Region.Framework.Scenes;
43 41
44using OpenMetaverse; 42using OpenMetaverse;
45using OpenMetaverse.Packets; 43using OpenMetaverse.Packets;
@@ -56,7 +54,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
56 54
57 public const int END_OF_PATCHES = 97; 55 public const int END_OF_PATCHES = 97;
58 56
59 private const float OO_SQRT2 = 0.7071067811865475244008443621049f; 57 private const float OO_SQRT2 = 0.7071068f;
60 private const int STRIDE = 264; 58 private const int STRIDE = 264;
61 59
62 private const int ZERO_CODE = 0x0; 60 private const int ZERO_CODE = 0x0;
@@ -64,20 +62,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
64 private const int POSITIVE_VALUE = 0x6; 62 private const int POSITIVE_VALUE = 0x6;
65 private const int NEGATIVE_VALUE = 0x7; 63 private const int NEGATIVE_VALUE = 0x7;
66 64
67 65 private static readonly int[] CopyMatrix16 = new int[256];
68// private static readonly float[] CosineTable16 = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 66 private static readonly float[] QuantizeTable16 = new float[256];
69 private static readonly int[] CopyMatrix16 = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 67 private static readonly float[] DequantizeTable16 = new float[256];
70
71 private static readonly float[] QuantizeTable16 =
72 new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
73 private static readonly float[] DequantizeTable16 =
74 new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
75 68
76 static OpenSimTerrainCompressor() 69 static OpenSimTerrainCompressor()
77 { 70 {
71 if(Constants.TerrainPatchSize != 16)
72 throw new Exception("Terrain patch size must be 16m x 16m");
73
78 // Initialize the decompression tables 74 // Initialize the decompression tables
79 BuildDequantizeTable16(); 75 BuildDequantizeTable16();
80// SetupCosines16();
81 BuildCopyMatrix16(); 76 BuildCopyMatrix16();
82 BuildQuantizeTable16(); 77 BuildQuantizeTable16();
83 } 78 }
@@ -86,12 +81,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
86 public static LayerDataPacket CreateLayerDataPacketStandardSize(TerrainPatch[] patches, byte type) 81 public static LayerDataPacket CreateLayerDataPacketStandardSize(TerrainPatch[] patches, byte type)
87 { 82 {
88 LayerDataPacket layer = new LayerDataPacket { LayerID = { Type = type } }; 83 LayerDataPacket layer = new LayerDataPacket { LayerID = { Type = type } };
89 84 TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader { Stride = STRIDE, PatchSize = 16 };
90 TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
91 { Stride = STRIDE, PatchSize = Constants.TerrainPatchSize };
92 85
93 // Should be enough to fit even the most poorly packed data 86 // Should be enough to fit even the most poorly packed data
94 byte[] data = new byte[patches.Length * Constants.TerrainPatchSize * Constants.TerrainPatchSize * 2]; 87 byte[] data = new byte[patches.Length * 256 * 2];
88
95 BitPack bitpack = new BitPack(data, 0); 89 BitPack bitpack = new BitPack(data, 0);
96 bitpack.PackBits(header.Stride, 16); 90 bitpack.PackBits(header.Stride, 16);
97 bitpack.PackBits(header.PatchSize, 8); 91 bitpack.PackBits(header.PatchSize, 8);
@@ -118,7 +112,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
118 112
119 int wbits; 113 int wbits;
120 int[] patch = CompressPatch(patchData, header, 10, out wbits); 114 int[] patch = CompressPatch(patchData, header, 10, out wbits);
121 EncodePatchHeader(output, header, patch, false, ref wbits); 115 EncodePatchHeader(output, header, false, ref wbits);
122 EncodePatch(output, patch, 0, wbits); 116 EncodePatch(output, patch, 0, wbits);
123 } 117 }
124 118
@@ -128,7 +122,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
128 float zmax = -99999999.0f; 122 float zmax = -99999999.0f;
129 float zmin = 99999999.0f; 123 float zmin = 99999999.0f;
130 124
131 for (int i = 0; i < Constants.TerrainPatchSize * Constants.TerrainPatchSize; i++) 125 for (int i = 0; i < 256; i++)
132 { 126 {
133 float val = patch[i]; 127 float val = patch[i];
134 if (val > zmax) zmax = val; 128 if (val > zmax) zmax = val;
@@ -143,12 +137,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
143 137
144 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits) 138 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits)
145 { 139 {
146 float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 140 float[] block = new float[256];
147 float oozrange = 1.0f / header.Range; 141 float oozrange = 1.0f / header.Range;
148 float range = (1 << prequant); 142 float range = (1 << prequant);
149 float premult = oozrange * range; 143 float premult = oozrange * range;
150 144
151
152 float sub = 0.5f * header.Range + header.DCOffset; 145 float sub = 0.5f * header.Range + header.DCOffset;
153 146
154 int wordsize = (prequant - 2) & 0x0f; 147 int wordsize = (prequant - 2) & 0x0f;
@@ -156,16 +149,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
156 header.QuantWBits |= wordsize << 4; 149 header.QuantWBits |= wordsize << 4;
157 150
158 int k = 0; 151 int k = 0;
159 for (int j = 0; j < Constants.TerrainPatchSize; j++) 152 for (int j = 0; j < 16; j++)
160 { 153 {
161 for (int i = 0; i < Constants.TerrainPatchSize; i++) 154 for (int i = 0; i < 16; i++)
162 block[k++] = (patchData[j * Constants.TerrainPatchSize + i] - sub) * premult; 155 block[k++] = (patchData[j * 16 + i] - sub) * premult;
163 } 156 }
164 157
165 float[] ftemp = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
166 int[] iout = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
167
168 wbits = (prequant >> 1); 158 wbits = (prequant >> 1);
159 int[] iout = new int[256];
169 160
170 dct16x16(block, iout, ref wbits); 161 dct16x16(block, iout, ref wbits);
171 162
@@ -177,15 +168,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
177 { 168 {
178 List<LayerDataPacket> ret = new List<LayerDataPacket>(); 169 List<LayerDataPacket> ret = new List<LayerDataPacket>();
179 170
171 byte[] data = new byte[x.Length * 256 * 2];
172
180 //create packet and global header 173 //create packet and global header
181 LayerDataPacket layer = new LayerDataPacket(); 174 LayerDataPacket layer = new LayerDataPacket();
182 175
183 layer.LayerID.Type = landPacketType; 176 layer.LayerID.Type = landPacketType;
184 177
185 byte[] data = new byte[x.Length * Constants.TerrainPatchSize * Constants.TerrainPatchSize * 2];
186 BitPack bitpack = new BitPack(data, 0); 178 BitPack bitpack = new BitPack(data, 0);
187 bitpack.PackBits(STRIDE, 16); 179 bitpack.PackBits(STRIDE, 16);
188 bitpack.PackBits(Constants.TerrainPatchSize, 8); 180 bitpack.PackBits(16, 8);
189 bitpack.PackBits(landPacketType, 8); 181 bitpack.PackBits(landPacketType, 8);
190 182
191 for (int i = 0; i < x.Length; i++) 183 for (int i = 0; i < x.Length; i++)
@@ -206,7 +198,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
206 198
207 bitpack = new BitPack(data, 0); 199 bitpack = new BitPack(data, 0);
208 bitpack.PackBits(STRIDE, 16); 200 bitpack.PackBits(STRIDE, 16);
209 bitpack.PackBits(Constants.TerrainPatchSize, 8); 201 bitpack.PackBits(16, 8);
210 bitpack.PackBits(landPacketType, 8); 202 bitpack.PackBits(landPacketType, 8);
211 } 203 }
212 } 204 }
@@ -223,6 +215,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
223 public static void CreatePatchFromTerrainData(BitPack output, TerrainData terrData, int patchX, int patchY) 215 public static void CreatePatchFromTerrainData(BitPack output, TerrainData terrData, int patchX, int patchY)
224 { 216 {
225 float frange; 217 float frange;
218
226 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY, out frange); 219 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY, out frange);
227 header.QuantWBits = 130; 220 header.QuantWBits = 130;
228 221
@@ -262,7 +255,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
262 255
263 int wbits; 256 int wbits;
264 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits); 257 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits);
265 EncodePatchHeader(output, header, patch, largeRegion, ref wbits); 258 EncodePatchHeader(output, header, largeRegion, ref wbits);
266 EncodePatch(output, patch, 0, wbits); 259 EncodePatch(output, patch, 0, wbits);
267 } 260 }
268 261
@@ -273,12 +266,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
273 float zmax = float.MinValue; 266 float zmax = float.MinValue;
274 float zmin = float.MaxValue; 267 float zmin = float.MaxValue;
275 268
276 int startx = patchX * Constants.TerrainPatchSize; 269 int startx = patchX * 16;
277 int starty = patchY * Constants.TerrainPatchSize; 270 int starty = patchY * 16;
278 271
279 for (int j = starty; j < starty + Constants.TerrainPatchSize; j++) 272 for (int j = starty; j < starty + 16; j++)
280 { 273 {
281 for (int i = startx; i < startx + Constants.TerrainPatchSize; i++) 274 for (int i = startx; i < startx + 16; i++)
282 { 275 {
283 float val = terrData[i, j]; 276 float val = terrData[i, j];
284 if (val > zmax) zmax = val; 277 if (val > zmax) zmax = val;
@@ -293,7 +286,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
293 return header; 286 return header;
294 } 287 }
295 288
296 private static void EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, bool largeRegion, ref int wbits) 289 private static void EncodePatchHeader(BitPack output, TerrainPatch.Header header, bool largeRegion, ref int wbits)
297 { 290 {
298 if (wbits > 17) 291 if (wbits > 17)
299 wbits = 17; 292 wbits = 17;
@@ -315,70 +308,73 @@ namespace OpenSim.Region.ClientStack.LindenUDP
315 private static void EncodePatch(BitPack output, int[] patch, int postquant, int wbits) 308 private static void EncodePatch(BitPack output, int[] patch, int postquant, int wbits)
316 { 309 {
317 int maxwbitssize = (1 << wbits) - 1; 310 int maxwbitssize = (1 << wbits) - 1;
318 int fullSize = Constants.TerrainPatchSize * Constants.TerrainPatchSize;
319 311
320 if (postquant > fullSize || postquant < 0) 312 if (postquant > 256 || postquant < 0)
321 { 313 {
322 Logger.Log("Postquant is outside the range of allowed values in EncodePatch()", Helpers.LogLevel.Error); 314 Logger.Log("Postquant is outside the range of allowed values in EncodePatch()", Helpers.LogLevel.Error);
323 return; 315 return;
324 } 316 }
325 317
326 if (postquant != 0) 318 int lastZeroindx = 256 - postquant;
327 patch[fullSize - postquant] = 0;
328 319
329 int lastZeroindx = fullSize - postquant; 320 if (lastZeroindx != 256)
321 patch[lastZeroindx] = 0;
330 322
331 for (int i = 0; i < fullSize; i++) 323 int i = 0;
324 while(i < 256)
332 { 325 {
333 int temp = patch[i]; 326 int temp = patch[i];
334 327
335 if (temp == 0) 328 if (temp == 0)
336 { 329 {
337 bool eob = true; 330 int j = i + 1;
338 331 while(j < lastZeroindx)
339 for (int j = i; j < lastZeroindx; j++)
340 { 332 {
341 if (patch[j] != 0) 333 if (patch[j] != 0)
342 {
343 eob = false;
344 break; 334 break;
345 } 335 ++j;
346 } 336 }
347 337
348 if (eob) 338 if (j == lastZeroindx)
349 { 339 {
350 output.PackBits(ZERO_EOB, 2); 340 output.PackBits(ZERO_EOB, 2);
351 return; 341 return;
352 } 342 }
353 output.PackBits(ZERO_CODE, 1); 343
354 } 344 while(i < j)
355 else
356 {
357 if (temp < 0)
358 { 345 {
359 temp *= -1; 346 output.PackBits(ZERO_CODE, 1);
347 ++i;
348 }
349 continue;
350 }
360 351
361 if (temp > maxwbitssize) temp = maxwbitssize; 352 if (temp < 0)
353 {
354 temp *= -1;
355 if (temp > maxwbitssize)
356 temp = maxwbitssize;
362 357
363 output.PackBits(NEGATIVE_VALUE, 3); 358 output.PackBits(NEGATIVE_VALUE, 3);
364 output.PackBits(temp, wbits); 359 output.PackBits(temp, wbits);
365 } 360 }
366 else 361 else
367 { 362 {
368 if (temp > maxwbitssize) temp = maxwbitssize; 363 if (temp > maxwbitssize)
364 temp = maxwbitssize;
369 365
370 output.PackBits(POSITIVE_VALUE, 3); 366 output.PackBits(POSITIVE_VALUE, 3);
371 output.PackBits(temp, wbits); 367 output.PackBits(temp, wbits);
372 }
373 } 368 }
369 ++i;
374 } 370 }
375 } 371 }
376 372
377 private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header, 373 private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header,
378 int prequant, out int wbits) 374 int prequant, out int wbits)
379 { 375 {
380 float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 376 float[] block = new float[256];
381 int[] iout = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 377 int[] iout = new int[256];
382 378
383 float oozrange = 1.0f / header.Range; 379 float oozrange = 1.0f / header.Range;
384 float invprequat = (1 << prequant); 380 float invprequat = (1 << prequant);
@@ -391,11 +387,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
391 header.QuantWBits |= wordsize << 4; 387 header.QuantWBits |= wordsize << 4;
392 388
393 int k = 0; 389 int k = 0;
394 int startX = patchX * Constants.TerrainPatchSize; 390 int startX = patchX * 16;
395 int startY = patchY * Constants.TerrainPatchSize; 391 int startY = patchY * 16;
396 for (int y = startY; y < startY + Constants.TerrainPatchSize; y++) 392 for (int y = startY; y < startY + 16; y++)
397 { 393 {
398 for (int x = startX; x < startX + Constants.TerrainPatchSize; x++) 394 for (int x = startX; x < startX + 16; x++)
399 { 395 {
400 block[k++] = (terrData[x, y] - sub) * premult; 396 block[k++] = (terrData[x, y] - sub) * premult;
401 } 397 }
@@ -412,23 +408,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
412 408
413 private static void BuildDequantizeTable16() 409 private static void BuildDequantizeTable16()
414 { 410 {
415 for (int j = 0; j < Constants.TerrainPatchSize; j++) 411 for (int j = 0; j < 16; j++)
416 { 412 {
417 for (int i = 0; i < Constants.TerrainPatchSize; i++) 413 int c = j * 16;
414 for (int i = 0; i < 16; i++)
418 { 415 {
419 DequantizeTable16[j * Constants.TerrainPatchSize + i] = 1.0f + 2.0f * (i + j); 416 DequantizeTable16[c + i] = 1.0f + 2.0f * (i + j);
420 } 417 }
421 } 418 }
422 } 419 }
423 420
424 private static void BuildQuantizeTable16() 421 private static void BuildQuantizeTable16()
425 { 422 {
426 const float oosob = 2.0f / Constants.TerrainPatchSize; 423 const float oosob = 2.0f / 16;
427 for (int j = 0; j < Constants.TerrainPatchSize; j++) 424 for (int j = 0; j < 16; j++)
428 { 425 {
429 for (int i = 0; i < Constants.TerrainPatchSize; i++) 426 int c = j * 16;
427 for (int i = 0; i < 16; i++)
430 { 428 {
431 QuantizeTable16[j * Constants.TerrainPatchSize + i] = oosob / (1.0f + 2.0f * (i + (float)j)); 429 QuantizeTable16[c + i] = oosob / (1.0f + 2.0f * (i + j));
432 } 430 }
433 } 431 }
434 } 432 }
@@ -441,15 +439,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
441 int j = 0; 439 int j = 0;
442 int count = 0; 440 int count = 0;
443 441
444 while (i < Constants.TerrainPatchSize && j < Constants.TerrainPatchSize) 442 while (i < 16 && j < 16)
445 { 443 {
446 CopyMatrix16[j * Constants.TerrainPatchSize + i] = count++; 444 CopyMatrix16[j * 16 + i] = count++;
447 445
448 if (!diag) 446 if (!diag)
449 { 447 {
450 if (right) 448 if (right)
451 { 449 {
452 if (i < Constants.TerrainPatchSize - 1) i++; 450 if (i < 15) i++;
453 else j++; 451 else j++;
454 452
455 right = false; 453 right = false;
@@ -457,7 +455,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
457 } 455 }
458 else 456 else
459 { 457 {
460 if (j < Constants.TerrainPatchSize - 1) j++; 458 if (j < 15 ) j++;
461 else i++; 459 else i++;
462 460
463 right = true; 461 right = true;
@@ -470,13 +468,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
470 { 468 {
471 i++; 469 i++;
472 j--; 470 j--;
473 if (i == Constants.TerrainPatchSize - 1 || j == 0) diag = false; 471 if (i == 15 || j == 0) diag = false;
474 } 472 }
475 else 473 else
476 { 474 {
477 i--; 475 i--;
478 j++; 476 j++;
479 if (j == Constants.TerrainPatchSize - 1 || i == 0) diag = false; 477 if (j == 15 || i == 0) diag = false;
480 } 478 }
481 } 479 }
482 } 480 }
@@ -534,16 +532,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
534 const float W16_4I = 0.38268343236508977173f; 532 const float W16_4I = 0.38268343236508977173f;
535 const float W16_8R = 0.70710678118654752440f; 533 const float W16_8R = 0.70710678118654752440f;
536 534
535
537 static void dct16x16(float[] a, int[] iout, ref int wbits) 536 static void dct16x16(float[] a, int[] iout, ref int wbits)
538 { 537 {
539 float[] tmp = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 538 float[] tmp = new float[256];
540 539
541 float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; 540 float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
542 float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i; 541 float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i;
543 float xr, xi; 542 float xr, xi;
544 float ftmp; 543 float ftmp;
545 544
546 int fullSize = Constants.TerrainPatchSize * Constants.TerrainPatchSize;
547 int itmp; 545 int itmp;
548 int j, k; 546 int j, k;
549 int indx; 547 int indx;
@@ -552,7 +550,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
552 int wbitsMaxValue = 1 << wbits; 550 int wbitsMaxValue = 1 << wbits;
553 bool dowbits = wbits < 17; 551 bool dowbits = wbits < 17;
554 552
555 for (j = 0, k = 0; j < fullSize; j += Constants.TerrainPatchSize, k++) 553 for (j = 0, k = 0; j < 256; j += 16, k++)
556 { 554 {
557 x4r = a[0 + j] - a[15 + j]; 555 x4r = a[0 + j] - a[15 + j];
558 xr = a[0 + j] + a[15 + j]; 556 xr = a[0 + j] + a[15 + j];
@@ -581,21 +579,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
581 xr = x0r + x2r; 579 xr = x0r + x2r;
582 xi = x1r + x3r; 580 xi = x1r + x3r;
583 tmp[k] = C16_8R * (xr + xi); // 581 tmp[k] = C16_8R * (xr + xi); //
584 tmp[8 * Constants.TerrainPatchSize + k] = C16_8R * (xr - xi); // 582 tmp[8 * 16 + k] = C16_8R * (xr - xi); //
585 xr = x0r - x2r; 583 xr = x0r - x2r;
586 xi = x1r - x3r; 584 xi = x1r - x3r;
587 tmp[4 * Constants.TerrainPatchSize + k] = C16_4R * xr - C16_4I * xi; // 585 tmp[4 * 16 + k] = C16_4R * xr - C16_4I * xi; //
588 tmp[12 * Constants.TerrainPatchSize + k] = C16_4R * xi + C16_4I * xr; // 586 tmp[12 * 16 + k] = C16_4R * xi + C16_4I * xr; //
589 x0r = W16_8R * (x1i - x3i); 587 x0r = W16_8R * (x1i - x3i);
590 x2r = W16_8R * (x1i + x3i); 588 x2r = W16_8R * (x1i + x3i);
591 xr = x0i + x0r; 589 xr = x0i + x0r;
592 xi = x2r + x2i; 590 xi = x2r + x2i;
593 tmp[2 * Constants.TerrainPatchSize + k] = C16_2R * xr - C16_2I * xi; // 591 tmp[2 * 16 + k] = C16_2R * xr - C16_2I * xi; //
594 tmp[14 * Constants.TerrainPatchSize + k] = C16_2R * xi + C16_2I * xr; // 592 tmp[14 * 16 + k] = C16_2R * xi + C16_2I * xr; //
595 xr = x0i - x0r; 593 xr = x0i - x0r;
596 xi = x2r - x2i; 594 xi = x2r - x2i;
597 tmp[6 * Constants.TerrainPatchSize + k] = C16_6R * xr - C16_6I * xi; // 595 tmp[6 * 16 + k] = C16_6R * xr - C16_6I * xi; //
598 tmp[10 * Constants.TerrainPatchSize + k] = C16_6R * xi + C16_6I * xr; // 596 tmp[10 * 16 + k] = C16_6R * xi + C16_6I * xr; //
599 xr = W16_8R * (x6r - x6i); 597 xr = W16_8R * (x6r - x6i);
600 xi = W16_8R * (x6i + x6r); 598 xi = W16_8R * (x6i + x6r);
601 x6r = x4r - xr; 599 x6r = x4r - xr;
@@ -612,23 +610,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
612 x7i -= xi; 610 x7i -= xi;
613 xr = x4r + x5r; 611 xr = x4r + x5r;
614 xi = x5i + x4i; 612 xi = x5i + x4i;
615 tmp[Constants.TerrainPatchSize + k] = C16_1R * xr - C16_1I * xi; // 613 tmp[16 + k] = C16_1R * xr - C16_1I * xi; //
616 tmp[15 * Constants.TerrainPatchSize + k] = C16_1R * xi + C16_1I * xr; // 614 tmp[15 * 16 + k] = C16_1R * xi + C16_1I * xr; //
617 xr = x4r - x5r; 615 xr = x4r - x5r;
618 xi = x5i - x4i; 616 xi = x5i - x4i;
619 tmp[7 * Constants.TerrainPatchSize + k] = C16_7R * xr - C16_7I * xi; // 617 tmp[7 * 16 + k] = C16_7R * xr - C16_7I * xi; //
620 tmp[9 * Constants.TerrainPatchSize + k] = C16_7R * xi + C16_7I * xr; // 618 tmp[9 * 16 + k] = C16_7R * xi + C16_7I * xr; //
621 xr = x6r - x7i; 619 xr = x6r - x7i;
622 xi = x7r + x6i; 620 xi = x7r + x6i;
623 tmp[5 * Constants.TerrainPatchSize + k] = C16_5R * xr - C16_5I * xi; // 621 tmp[5 * 16 + k] = C16_5R * xr - C16_5I * xi; //
624 tmp[11 * Constants.TerrainPatchSize + k] = C16_5R * xi + C16_5I * xr; // 622 tmp[11 * 16 + k] = C16_5R * xi + C16_5I * xr; //
625 xr = x6r + x7i; 623 xr = x6r + x7i;
626 xi = x7r - x6i; 624 xi = x7r - x6i;
627 tmp[3 * Constants.TerrainPatchSize + k] = C16_3R * xr - C16_3I * xi; // 625 tmp[3 * 16 + k] = C16_3R * xr - C16_3I * xi; //
628 tmp[13 * Constants.TerrainPatchSize + k] = C16_3R * xi + C16_3I * xr; // 626 tmp[13 * 16 + k] = C16_3R * xi + C16_3I * xr; //
629 } 627 }
630 628
631 for (j = 0, k = 0; j < fullSize; j += Constants.TerrainPatchSize, k++) 629 for (j = 0, k = 0; j < 256; j += 16, k++)
632 { 630 {
633 x4r = tmp[0 + j] - tmp[15 + j]; 631 x4r = tmp[0 + j] - tmp[15 + j];
634 xr = tmp[0 + j] + tmp[15 + j]; 632 xr = tmp[0 + j] + tmp[15 + j];
@@ -679,7 +677,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
679 677
680 //tmp[8 * Constants.TerrainPatchSize + k] = C16_8R * (xr - xi); // 678 //tmp[8 * Constants.TerrainPatchSize + k] = C16_8R * (xr - xi); //
681 ftmp = C16_8R * (xr - xi); 679 ftmp = C16_8R * (xr - xi);
682 indx = 8 * Constants.TerrainPatchSize + k; 680 indx = 8 * 16 + k;
683 itmp = (int)(ftmp * QuantizeTable16[indx]); 681 itmp = (int)(ftmp * QuantizeTable16[indx]);
684 iout[CopyMatrix16[indx]] = itmp; 682 iout[CopyMatrix16[indx]] = itmp;
685 683
@@ -703,7 +701,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
703 701
704 //tmp[4 * Constants.TerrainPatchSize + k] = C16_4R * xr - C16_4I * xi; // 702 //tmp[4 * Constants.TerrainPatchSize + k] = C16_4R * xr - C16_4I * xi; //
705 ftmp = C16_4R * xr - C16_4I * xi; 703 ftmp = C16_4R * xr - C16_4I * xi;
706 indx = 4 * Constants.TerrainPatchSize + k; 704 indx = 4 * 16 + k;
707 itmp = (int)(ftmp * QuantizeTable16[indx]); 705 itmp = (int)(ftmp * QuantizeTable16[indx]);
708 iout[CopyMatrix16[indx]] = itmp; 706 iout[CopyMatrix16[indx]] = itmp;
709 707
@@ -724,7 +722,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
724 722
725 //tmp[12 * Constants.TerrainPatchSize + k] = C16_4R * xi + C16_4I * xr; // 723 //tmp[12 * Constants.TerrainPatchSize + k] = C16_4R * xi + C16_4I * xr; //
726 ftmp = C16_4R * xi + C16_4I * xr; 724 ftmp = C16_4R * xi + C16_4I * xr;
727 indx = 12 * Constants.TerrainPatchSize + k; 725 indx = 12 * 16 + k;
728 itmp = (int)(ftmp * QuantizeTable16[indx]); 726 itmp = (int)(ftmp * QuantizeTable16[indx]);
729 iout[CopyMatrix16[indx]] = itmp; 727 iout[CopyMatrix16[indx]] = itmp;
730 728
@@ -750,7 +748,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
750 748
751 //tmp[2 * Constants.TerrainPatchSize + k] = C16_2R * xr - C16_2I * xi; // 749 //tmp[2 * Constants.TerrainPatchSize + k] = C16_2R * xr - C16_2I * xi; //
752 ftmp = C16_2R * xr - C16_2I * xi; 750 ftmp = C16_2R * xr - C16_2I * xi;
753 indx = 2 * Constants.TerrainPatchSize + k; 751 indx = 2 * 16 + k;
754 itmp = (int)(ftmp * QuantizeTable16[indx]); 752 itmp = (int)(ftmp * QuantizeTable16[indx]);
755 iout[CopyMatrix16[indx]] = itmp; 753 iout[CopyMatrix16[indx]] = itmp;
756 754
@@ -771,7 +769,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
771 769
772 //tmp[14 * Constants.TerrainPatchSize + k] = C16_2R * xi + C16_2I * xr; // 770 //tmp[14 * Constants.TerrainPatchSize + k] = C16_2R * xi + C16_2I * xr; //
773 ftmp = C16_2R * xi + C16_2I * xr; 771 ftmp = C16_2R * xi + C16_2I * xr;
774 indx = 14 * Constants.TerrainPatchSize + k; 772 indx = 14 * 16 + k;
775 itmp = (int)(ftmp * QuantizeTable16[indx]); 773 itmp = (int)(ftmp * QuantizeTable16[indx]);
776 iout[CopyMatrix16[indx]] = itmp; 774 iout[CopyMatrix16[indx]] = itmp;
777 775
@@ -795,7 +793,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
795 793
796 //tmp[6 * Constants.TerrainPatchSize + k] = C16_6R * xr - C16_6I * xi; // 794 //tmp[6 * Constants.TerrainPatchSize + k] = C16_6R * xr - C16_6I * xi; //
797 ftmp = C16_6R * xr - C16_6I * xi; 795 ftmp = C16_6R * xr - C16_6I * xi;
798 indx = 6 * Constants.TerrainPatchSize + k; 796 indx = 6 * 16 + k;
799 itmp = (int)(ftmp * QuantizeTable16[indx]); 797 itmp = (int)(ftmp * QuantizeTable16[indx]);
800 iout[CopyMatrix16[indx]] = itmp; 798 iout[CopyMatrix16[indx]] = itmp;
801 799
@@ -816,7 +814,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
816 814
817 //tmp[10 * Constants.TerrainPatchSize + k] = C16_6R * xi + C16_6I * xr; // 815 //tmp[10 * Constants.TerrainPatchSize + k] = C16_6R * xi + C16_6I * xr; //
818 ftmp = C16_6R * xi + C16_6I * xr; 816 ftmp = C16_6R * xi + C16_6I * xr;
819 indx = 10 * Constants.TerrainPatchSize + k; 817 indx = 10 * 16 + k;
820 itmp = (int)(ftmp * QuantizeTable16[indx]); 818 itmp = (int)(ftmp * QuantizeTable16[indx]);
821 iout[CopyMatrix16[indx]] = itmp; 819 iout[CopyMatrix16[indx]] = itmp;
822 820
@@ -854,7 +852,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
854 852
855 //tmp[1 * Constants.TerrainPatchSize + k] = C16_1R * xr - C16_1I * xi; // 853 //tmp[1 * Constants.TerrainPatchSize + k] = C16_1R * xr - C16_1I * xi; //
856 ftmp = C16_1R * xr - C16_1I * xi; 854 ftmp = C16_1R * xr - C16_1I * xi;
857 indx = Constants.TerrainPatchSize + k; 855 indx = 16 + k;
858 itmp = (int)(ftmp * QuantizeTable16[indx]); 856 itmp = (int)(ftmp * QuantizeTable16[indx]);
859 iout[CopyMatrix16[indx]] = itmp; 857 iout[CopyMatrix16[indx]] = itmp;
860 858
@@ -875,7 +873,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
875 873
876 //tmp[15 * Constants.TerrainPatchSize + k] = C16_1R * xi + C16_1I * xr; // 874 //tmp[15 * Constants.TerrainPatchSize + k] = C16_1R * xi + C16_1I * xr; //
877 ftmp = C16_1R * xi + C16_1I * xr; 875 ftmp = C16_1R * xi + C16_1I * xr;
878 indx = 15 * Constants.TerrainPatchSize + k; 876 indx = 15 * 16 + k;
879 itmp = (int)(ftmp * QuantizeTable16[indx]); 877 itmp = (int)(ftmp * QuantizeTable16[indx]);
880 iout[CopyMatrix16[indx]] = itmp; 878 iout[CopyMatrix16[indx]] = itmp;
881 879
@@ -899,7 +897,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
899 897
900 //tmp[7 * Constants.TerrainPatchSize + k] = C16_7R * xr - C16_7I * xi; // 898 //tmp[7 * Constants.TerrainPatchSize + k] = C16_7R * xr - C16_7I * xi; //
901 ftmp = C16_7R * xr - C16_7I * xi; 899 ftmp = C16_7R * xr - C16_7I * xi;
902 indx = 7 * Constants.TerrainPatchSize + k; 900 indx = 7 * 16 + k;
903 itmp = (int)(ftmp * QuantizeTable16[indx]); 901 itmp = (int)(ftmp * QuantizeTable16[indx]);
904 iout[CopyMatrix16[indx]] = itmp; 902 iout[CopyMatrix16[indx]] = itmp;
905 903
@@ -920,7 +918,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
920 918
921 //tmp[9 * Constants.TerrainPatchSize + k] = C16_7R * xi + C16_7I * xr; // 919 //tmp[9 * Constants.TerrainPatchSize + k] = C16_7R * xi + C16_7I * xr; //
922 ftmp = C16_7R * xi + C16_7I * xr; 920 ftmp = C16_7R * xi + C16_7I * xr;
923 indx = 9 * Constants.TerrainPatchSize + k; 921 indx = 9 * 16 + k;
924 itmp = (int)(ftmp * QuantizeTable16[indx]); 922 itmp = (int)(ftmp * QuantizeTable16[indx]);
925 iout[CopyMatrix16[indx]] = itmp; 923 iout[CopyMatrix16[indx]] = itmp;
926 924
@@ -944,7 +942,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
944 942
945 //tmp[5 * Constants.TerrainPatchSize + k] = C16_5R * xr - C16_5I * xi; // 943 //tmp[5 * Constants.TerrainPatchSize + k] = C16_5R * xr - C16_5I * xi; //
946 ftmp = C16_5R * xr - C16_5I * xi; 944 ftmp = C16_5R * xr - C16_5I * xi;
947 indx = 5 * Constants.TerrainPatchSize + k; 945 indx = 5 * 16 + k;
948 itmp = (int)(ftmp * QuantizeTable16[indx]); 946 itmp = (int)(ftmp * QuantizeTable16[indx]);
949 iout[CopyMatrix16[indx]] = itmp; 947 iout[CopyMatrix16[indx]] = itmp;
950 948
@@ -965,7 +963,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
965 963
966 //tmp[11 * Constants.TerrainPatchSize + k] = C16_5R * xi + C16_5I * xr; // 964 //tmp[11 * Constants.TerrainPatchSize + k] = C16_5R * xi + C16_5I * xr; //
967 ftmp = C16_5R * xi + C16_5I * xr; 965 ftmp = C16_5R * xi + C16_5I * xr;
968 indx = 11 * Constants.TerrainPatchSize + k; 966 indx = 11 * 16 + k;
969 itmp = (int)(ftmp * QuantizeTable16[indx]); 967 itmp = (int)(ftmp * QuantizeTable16[indx]);
970 iout[CopyMatrix16[indx]] = itmp; 968 iout[CopyMatrix16[indx]] = itmp;
971 969
@@ -989,7 +987,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
989 987
990 //tmp[3 * Constants.TerrainPatchSize + k] = C16_3R * xr - C16_3I * xi; // 988 //tmp[3 * Constants.TerrainPatchSize + k] = C16_3R * xr - C16_3I * xi; //
991 ftmp = C16_3R * xr - C16_3I * xi; 989 ftmp = C16_3R * xr - C16_3I * xi;
992 indx = 3 * Constants.TerrainPatchSize + k; 990 indx = 3 * 16 + k;
993 itmp = (int)(ftmp * QuantizeTable16[indx]); 991 itmp = (int)(ftmp * QuantizeTable16[indx]);
994 iout[CopyMatrix16[indx]] = itmp; 992 iout[CopyMatrix16[indx]] = itmp;
995 993
@@ -1010,7 +1008,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1010 1008
1011 //tmp[13 * Constants.TerrainPatchSize + k] = C16_3R * xi + C16_3I * xr; // 1009 //tmp[13 * Constants.TerrainPatchSize + k] = C16_3R * xi + C16_3I * xr; //
1012 ftmp = C16_3R * xi + C16_3I * xr; 1010 ftmp = C16_3R * xi + C16_3I * xr;
1013 indx = 13 * Constants.TerrainPatchSize + k; 1011 indx = 13 * 16 + k;
1014 itmp = (int)(ftmp * QuantizeTable16[indx]); 1012 itmp = (int)(ftmp * QuantizeTable16[indx]);
1015 iout[CopyMatrix16[indx]] = itmp; 1013 iout[CopyMatrix16[indx]] = itmp;
1016 1014
@@ -1033,78 +1031,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1033 1031
1034 #endregion DCT 1032 #endregion DCT
1035 1033
1036 #region Decode
1037 /*
1038 public static TerrainPatch.Header DecodePatchHeader(BitPack bitpack)
1039 {
1040 TerrainPatch.Header header = new TerrainPatch.Header { QuantWBits = bitpack.UnpackBits(8) };
1041
1042 // Quantized word bits
1043 if (header.QuantWBits == END_OF_PATCHES)
1044 return header;
1045
1046 // DC offset
1047 header.DCOffset = bitpack.UnpackFloat();
1048
1049 // Range
1050 header.Range = bitpack.UnpackBits(16);
1051
1052 // Patch IDs (10 bits)
1053 header.PatchIDs = bitpack.UnpackBits(10);
1054
1055 // Word bits
1056 header.WordBits = (uint)((header.QuantWBits & 0x0f) + 2);
1057
1058 return header;
1059 }
1060 */
1061
1062 /*
1063 public static void DecodePatch(int[] patches, BitPack bitpack, TerrainPatch.Header header, int size)
1064 {
1065 for (int n = 0; n < size * size; n++)
1066 {
1067 // ?
1068 int temp = bitpack.UnpackBits(1);
1069 if (temp != 0)
1070 {
1071 // Value or EOB
1072 temp = bitpack.UnpackBits(1);
1073 if (temp != 0)
1074 {
1075 // Value
1076 temp = bitpack.UnpackBits(1);
1077 if (temp != 0)
1078 {
1079 // Negative
1080 temp = bitpack.UnpackBits((int)header.WordBits);
1081 patches[n] = temp * -1;
1082 }
1083 else
1084 {
1085 // Positive
1086 temp = bitpack.UnpackBits((int)header.WordBits);
1087 patches[n] = temp;
1088 }
1089 }
1090 else
1091 {
1092 // Set the rest to zero
1093 // TODO: This might not be necessary
1094 for (int o = n; o < size * size; o++)
1095 {
1096 patches[o] = 0;
1097 }
1098 break;
1099 }
1100 }
1101 else
1102 {
1103 patches[n] = 0;
1104 }
1105 }
1106 }
1107 */
1108 #region IDCT 1034 #region IDCT
1109 /* not in use 1035 /* not in use
1110 private static void IDCTColumn16(float[] linein, float[] lineout, int column) 1036 private static void IDCTColumn16(float[] linein, float[] lineout, int column)
@@ -1141,20 +1067,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1141 } 1067 }
1142 } 1068 }
1143 1069
1144/*
1145 private static void SetupCosines16()
1146 {
1147 const float hposz = (float)Math.PI * 0.5f / Constants.TerrainPatchSize;
1148
1149 for (int u = 0; u < Constants.TerrainPatchSize; u++)
1150 {
1151 for (int n = 0; n < Constants.TerrainPatchSize; n++)
1152 {
1153 CosineTable16[u * Constants.TerrainPatchSize + n] = (float)Math.Cos((2.0f * n + 1.0f) * u * hposz);
1154 }
1155 }
1156 }
1157*/
1158 //not in use, and still not fixed 1070 //not in use, and still not fixed
1159 /* 1071 /*
1160 static void idct16x16(float[] a) 1072 static void idct16x16(float[] a)
@@ -1319,7 +1231,5 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1319 } 1231 }
1320 */ 1232 */
1321 #endregion IDCT 1233 #endregion IDCT
1322 #endregion Decode
1323 } 1234 }
1324
1325} 1235}