PageRenderTime 67ms CodeModel.GetById 9ms app.highlight 53ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmessage/patch_idct.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 684 lines | 532 code | 122 blank | 30 comment | 41 complexity | ac25fd5c8b859c62d7f9f537c7b87e51 MD5 | raw file
  1/** 
  2 * @file patch_idct.cpp
  3 * @brief IDCT patch.
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "llmath.h"
 30//#include "vmath.h"
 31#include "v3math.h"
 32#include "patch_dct.h"
 33
 34LLGroupHeader	*gGOPP;
 35
 36void set_group_of_patch_header(LLGroupHeader *gopp)
 37{
 38	gGOPP = gopp;
 39}
 40
 41F32 gPatchDequantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 42void build_patch_dequantize_table(S32 size)
 43{
 44	S32 i, j;
 45	for (j = 0; j < size; j++)
 46	{
 47		for (i = 0; i < size; i++)
 48		{
 49			gPatchDequantizeTable[j*size + i] = (1.f + 2.f*(i+j));
 50		}
 51	}
 52}
 53
 54S32	gCurrentDeSize = 0;
 55
 56F32	gPatchICosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 57
 58void setup_patch_icosines(S32 size)
 59{
 60	S32 n, u;
 61	F32 oosob = F_PI*0.5f/size;
 62
 63	for (u = 0; u < size; u++)
 64	{
 65		for (n = 0; n < size; n++)
 66		{
 67			gPatchICosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
 68		}
 69	}
 70}
 71
 72S32	gDeCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 73
 74void build_decopy_matrix(S32 size)
 75{
 76	S32 i, j, count;
 77	BOOL	b_diag = FALSE;
 78	BOOL	b_right = TRUE;
 79
 80	i = 0;
 81	j = 0;
 82	count = 0;
 83
 84	while (  (i < size)
 85		   &&(j < size))
 86	{
 87		gDeCopyMatrix[j*size + i] = count;
 88
 89		count++;
 90
 91		if (!b_diag)
 92		{
 93			if (b_right)
 94			{
 95				if (i < size - 1)
 96					i++;
 97				else
 98					j++;
 99				b_right = FALSE;
100				b_diag = TRUE;
101			}
102			else
103			{
104				if (j < size - 1)
105					j++;
106				else
107					i++;
108				b_right = TRUE;
109				b_diag = TRUE;
110			}
111		}
112		else
113		{
114			if (b_right)
115			{
116				i++;
117				j--;
118				if (  (i == size - 1)
119					||(j == 0))
120				{
121					b_diag = FALSE;
122				}
123			}
124			else
125			{
126				i--;
127				j++;
128				if (  (i == 0)
129					||(j == size - 1))
130				{
131					b_diag = FALSE;
132				}
133			}
134		}
135	}
136}
137
138void init_patch_decompressor(S32 size)
139{
140	if (size != gCurrentDeSize)
141	{
142		gCurrentDeSize = size;
143		build_patch_dequantize_table(size);
144		setup_patch_icosines(size);
145		build_decopy_matrix(size);
146	}
147}
148
149inline void idct_line(F32 *linein, F32 *lineout, S32 line)
150{
151	S32 n;
152	F32 total;
153	F32 *pcp = gPatchICosines;
154
155#ifdef _PATCH_SIZE_16_AND_32_ONLY
156	F32 oosob = 2.f/16.f;
157	S32	line_size = line*NORMAL_PATCH_SIZE;
158	F32 *tlinein, *tpcp;
159
160
161	for (n = 0; n < NORMAL_PATCH_SIZE; n++)
162	{
163		tpcp = pcp + n;
164		tlinein = linein + line_size;
165	
166		total = OO_SQRT2*(*(tlinein++));
167		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
168		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
169		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
170
171		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
172		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
173		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
174		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
175
176		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
177		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
178		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
179		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
180
181		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
182		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
183		total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
184		total += *(tlinein)*(*(tpcp += NORMAL_PATCH_SIZE));
185
186		*(lineout + line_size + n) = total*oosob;
187	}
188#else
189	F32 oosob = 2.f/size;
190	S32	size = gGOPP->patch_size;
191	S32	line_size = line*size;
192	S32 u;
193	for (n = 0; n < size; n++)
194	{
195		total = OO_SQRT2*linein[line_size];
196		for (u = 1; u < size; u++)
197		{
198			total += linein[line_size + u]*pcp[u*size+n];
199		}
200		lineout[line_size + n] = total*oosob;
201	}
202#endif
203}
204
205inline void idct_line_large_slow(F32 *linein, F32 *lineout, S32 line)
206{
207	S32 n;
208	F32 total;
209	F32 *pcp = gPatchICosines;
210
211	F32 oosob = 2.f/32.f;
212	S32	line_size = line*LARGE_PATCH_SIZE;
213	F32 *tlinein, *tpcp;
214
215
216	for (n = 0; n < LARGE_PATCH_SIZE; n++)
217	{
218		tpcp = pcp + n;
219		tlinein = linein + line_size;
220	
221		total = OO_SQRT2*(*(tlinein++));
222		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
223		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
224		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
225
226		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
227		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
228		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
229		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
230
231		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
232		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
233		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
234		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
235
236		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
237		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
238		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
239		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
240
241		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
242		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
243		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
244		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
245
246		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
247		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
248		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
249		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
250
251		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
252		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
253		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
254		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
255
256		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
257		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
258		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
259		total += *(tlinein)*(*(tpcp += LARGE_PATCH_SIZE));
260
261		*(lineout + line_size + n) = total*oosob;
262	}
263}
264
265// Nota Bene: assumes that coefficients beyond 128 are 0!
266
267void idct_line_large(F32 *linein, F32 *lineout, S32 line)
268{
269	S32 n;
270	F32 total;
271	F32 *pcp = gPatchICosines;
272
273	F32 oosob = 2.f/32.f;
274	S32	line_size = line*LARGE_PATCH_SIZE;
275	F32 *tlinein, *tpcp;
276	F32 *baselinein = linein + line_size;
277	F32 *baselineout = lineout + line_size;
278
279
280	for (n = 0; n < LARGE_PATCH_SIZE; n++)
281	{
282		tpcp = pcp++;
283		tlinein = baselinein;
284	
285		total = OO_SQRT2*(*(tlinein++));
286		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
287		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
288		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
289
290		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
291		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
292		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
293		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
294
295		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
296		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
297		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
298		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
299
300		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
301		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
302		total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
303		total += *(tlinein)*(*(tpcp));
304
305		*baselineout++ = total*oosob;
306	}
307}
308
309inline void idct_column(F32 *linein, F32 *lineout, S32 column)
310{
311	S32 n;
312	F32 total;
313	F32 *pcp = gPatchICosines;
314
315#ifdef _PATCH_SIZE_16_AND_32_ONLY
316	F32 *tlinein, *tpcp;
317
318	for (n = 0; n < NORMAL_PATCH_SIZE; n++)
319	{
320		tpcp = pcp + n;
321		tlinein = linein + column;
322
323		total = OO_SQRT2*(*tlinein);
324		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
325		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
326		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
327
328		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
329		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
330		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
331		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
332
333		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
334		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
335		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
336		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
337
338		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
339		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
340		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
341		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
342
343		*(lineout + (n<<4) + column) = total;
344	}
345
346#else
347	S32	size = gGOPP->patch_size;
348	S32 u;
349	S32 u_size;
350
351	for (n = 0; n < size; n++)
352	{
353		total = OO_SQRT2*linein[column];
354		for (u = 1; u < size; u++)
355		{
356			u_size = u*size;
357			total += linein[u_size + column]*pcp[u_size+n];
358		}
359		lineout[size*n + column] = total;
360	}
361#endif
362}
363
364inline void idct_column_large_slow(F32 *linein, F32 *lineout, S32 column)
365{
366	S32 n;
367	F32 total;
368	F32 *pcp = gPatchICosines;
369
370	F32 *tlinein, *tpcp;
371
372	for (n = 0; n < LARGE_PATCH_SIZE; n++)
373	{
374		tpcp = pcp + n;
375		tlinein = linein + column;
376
377		total = OO_SQRT2*(*tlinein);
378		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
379		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
380		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
381
382		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
383		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
384		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
385		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
386
387		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
388		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
389		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
390		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
391
392		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
393		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
394		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
395		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
396
397		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
398		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
399		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
400		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
401
402		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
403		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
404		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
405		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
406
407		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
408		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
409		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
410		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
411
412		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
413		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
414		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
415		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
416
417		*(lineout + (n<<5) + column) = total;
418	}
419}
420
421// Nota Bene: assumes that coefficients beyond 128 are 0!
422
423void idct_column_large(F32 *linein, F32 *lineout, S32 column)
424{
425	S32 n, m;
426	F32 total;
427	F32 *pcp = gPatchICosines;
428
429	F32 *tlinein, *tpcp;
430	F32 *baselinein = linein + column;
431	F32 *baselineout = lineout + column;
432
433	for (n = 0; n < LARGE_PATCH_SIZE; n++)
434	{
435		tpcp = pcp++;
436		tlinein = baselinein;
437
438		total = OO_SQRT2*(*tlinein);
439		for (m = 1; m < NORMAL_PATCH_SIZE; m++)
440			total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
441
442		*(baselineout + (n<<5)) = total;
443	}
444}
445
446inline void idct_patch(F32 *block)
447{
448	F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
449
450#ifdef _PATCH_SIZE_16_AND_32_ONLY
451	idct_column(block, temp, 0);	
452	idct_column(block, temp, 1);	
453	idct_column(block, temp, 2);	
454	idct_column(block, temp, 3);	
455
456	idct_column(block, temp, 4);	
457	idct_column(block, temp, 5);	
458	idct_column(block, temp, 6);	
459	idct_column(block, temp, 7);	
460
461	idct_column(block, temp, 8);	
462	idct_column(block, temp, 9);	
463	idct_column(block, temp, 10);	
464	idct_column(block, temp, 11);	
465
466	idct_column(block, temp, 12);	
467	idct_column(block, temp, 13);	
468	idct_column(block, temp, 14);	
469	idct_column(block, temp, 15);	
470
471	idct_line(temp, block, 0);	
472	idct_line(temp, block, 1);	
473	idct_line(temp, block, 2);	
474	idct_line(temp, block, 3);	
475
476	idct_line(temp, block, 4);	
477	idct_line(temp, block, 5);	
478	idct_line(temp, block, 6);	
479	idct_line(temp, block, 7);	
480
481	idct_line(temp, block, 8);	
482	idct_line(temp, block, 9);	
483	idct_line(temp, block, 10);	
484	idct_line(temp, block, 11);	
485
486	idct_line(temp, block, 12);	
487	idct_line(temp, block, 13);	
488	idct_line(temp, block, 14);	
489	idct_line(temp, block, 15);	
490#else
491	S32 i;
492	S32	size = gGOPP->patch_size;
493	for (i = 0; i < size; i++)
494	{
495		idct_column(block, temp, i);	
496	}
497	for (i = 0; i < size; i++)
498	{
499		idct_line(temp, block, i);	
500	}
501#endif
502}
503
504inline void idct_patch_large(F32 *block)
505{
506	F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
507
508	idct_column_large_slow(block, temp, 0);	
509	idct_column_large_slow(block, temp, 1);	
510	idct_column_large_slow(block, temp, 2);	
511	idct_column_large_slow(block, temp, 3);	
512
513	idct_column_large_slow(block, temp, 4);	
514	idct_column_large_slow(block, temp, 5);	
515	idct_column_large_slow(block, temp, 6);	
516	idct_column_large_slow(block, temp, 7);	
517
518	idct_column_large_slow(block, temp, 8);	
519	idct_column_large_slow(block, temp, 9);	
520	idct_column_large_slow(block, temp, 10);	
521	idct_column_large_slow(block, temp, 11);	
522
523	idct_column_large_slow(block, temp, 12);	
524	idct_column_large_slow(block, temp, 13);	
525	idct_column_large_slow(block, temp, 14);	
526	idct_column_large_slow(block, temp, 15);	
527
528	idct_column_large_slow(block, temp, 16);	
529	idct_column_large_slow(block, temp, 17);	
530	idct_column_large_slow(block, temp, 18);	
531	idct_column_large_slow(block, temp, 19);	
532
533	idct_column_large_slow(block, temp, 20);	
534	idct_column_large_slow(block, temp, 21);	
535	idct_column_large_slow(block, temp, 22);	
536	idct_column_large_slow(block, temp, 23);	
537
538	idct_column_large_slow(block, temp, 24);	
539	idct_column_large_slow(block, temp, 25);	
540	idct_column_large_slow(block, temp, 26);	
541	idct_column_large_slow(block, temp, 27);	
542
543	idct_column_large_slow(block, temp, 28);	
544	idct_column_large_slow(block, temp, 29);	
545	idct_column_large_slow(block, temp, 30);	
546	idct_column_large_slow(block, temp, 31);	
547
548	idct_line_large_slow(temp, block, 0);	
549	idct_line_large_slow(temp, block, 1);	
550	idct_line_large_slow(temp, block, 2);	
551	idct_line_large_slow(temp, block, 3);	
552
553	idct_line_large_slow(temp, block, 4);	
554	idct_line_large_slow(temp, block, 5);	
555	idct_line_large_slow(temp, block, 6);	
556	idct_line_large_slow(temp, block, 7);	
557
558	idct_line_large_slow(temp, block, 8);	
559	idct_line_large_slow(temp, block, 9);	
560	idct_line_large_slow(temp, block, 10);	
561	idct_line_large_slow(temp, block, 11);	
562
563	idct_line_large_slow(temp, block, 12);	
564	idct_line_large_slow(temp, block, 13);	
565	idct_line_large_slow(temp, block, 14);	
566	idct_line_large_slow(temp, block, 15);	
567
568	idct_line_large_slow(temp, block, 16);	
569	idct_line_large_slow(temp, block, 17);	
570	idct_line_large_slow(temp, block, 18);	
571	idct_line_large_slow(temp, block, 19);	
572
573	idct_line_large_slow(temp, block, 20);	
574	idct_line_large_slow(temp, block, 21);	
575	idct_line_large_slow(temp, block, 22);	
576	idct_line_large_slow(temp, block, 23);	
577
578	idct_line_large_slow(temp, block, 24);	
579	idct_line_large_slow(temp, block, 25);	
580	idct_line_large_slow(temp, block, 26);	
581	idct_line_large_slow(temp, block, 27);	
582
583	idct_line_large_slow(temp, block, 28);	
584	idct_line_large_slow(temp, block, 29);	
585	idct_line_large_slow(temp, block, 30);	
586	idct_line_large_slow(temp, block, 31);	
587}
588
589S32	gDitherNoise = 128;
590
591void decompress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *ph)
592{
593	S32		i, j;
594
595	F32		block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock = block;
596	F32		*tpatch;
597
598	LLGroupHeader	*gopp = gGOPP;
599	S32		size = gopp->patch_size;
600	F32		range = ph->range;
601	S32		prequant = (ph->quant_wbits >> 4) + 2;
602	S32		quantize = 1<<prequant;
603	F32		hmin = ph->dc_offset;
604	S32		stride = gopp->stride;
605
606	F32		ooq = 1.f/(F32)quantize;
607	F32     *dq = gPatchDequantizeTable;
608	S32		*decopy_matrix = gDeCopyMatrix;
609
610	F32		mult = ooq*range;
611	F32		addval = mult*(F32)(1<<(prequant - 1))+hmin;
612
613	for (i = 0; i < size*size; i++)
614	{
615		*(tblock++) = *(cpatch + *(decopy_matrix++))*(*dq++);
616	}
617
618	if (size == 16)
619	{
620		idct_patch(block);
621	}
622	else
623	{
624		idct_patch_large(block);
625	}
626
627	for (j = 0; j < size; j++)
628	{
629		tpatch = patch + j*stride;
630		tblock = block + j*size;
631		for (i = 0; i < size; i++)
632		{
633			*(tpatch++) = *(tblock++)*mult+addval;
634		}
635	}
636}
637
638
639void decompress_patchv(LLVector3 *v, S32 *cpatch, LLPatchHeader *ph)
640{
641	S32		i, j;
642
643	F32			block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock = block;
644	LLVector3	*tvec;
645
646	LLGroupHeader	*gopp = gGOPP;
647	S32		size = gopp->patch_size;
648	F32		range = ph->range;
649	S32		prequant = (ph->quant_wbits >> 4) + 2;
650	S32		quantize = 1<<prequant;
651	F32		hmin = ph->dc_offset;
652	S32		stride = gopp->stride;
653
654	F32		ooq = 1.f/(F32)quantize;
655	F32     *dq = gPatchDequantizeTable;
656	S32		*decopy_matrix = gDeCopyMatrix;
657
658	F32		mult = ooq*range;
659	F32		addval = mult*(F32)(1<<(prequant - 1))+hmin;
660
661//	BOOL	b_diag = FALSE;
662//	BOOL	b_right = TRUE;
663
664	for (i = 0; i < size*size; i++)
665	{
666		*(tblock++) = *(cpatch + *(decopy_matrix++))*(*dq++);
667	}
668
669	if (size == 16)
670		idct_patch(block);
671	else
672		idct_patch_large(block);
673
674	for (j = 0; j < size; j++)
675	{
676		tvec = v + j*stride;
677		tblock = block + j*size;
678		for (i = 0; i < size; i++)
679		{
680			(*tvec++).mV[VZ] = *(tblock++)*mult+addval;
681		}
682	}
683}
684