PageRenderTime 82ms CodeModel.GetById 18ms app.highlight 59ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/patch_dct.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 769 lines | 604 code | 137 blank | 28 comment | 38 complexity | eb2764107c34b96e91516bd45199d046 MD5 | raw file
  1/** 
  2 * @file patch_dct.cpp
  3 * @brief DCT 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
 34typedef struct s_patch_compress_global_data
 35{
 36	S32 patch_size;
 37	S32 patch_stride;
 38	U32 charptr;
 39	S32 layer_type;
 40} PCGD;
 41
 42PCGD	gPatchCompressGlobalData;
 43
 44void reset_patch_compressor(void)
 45{
 46	PCGD *pcp = &gPatchCompressGlobalData;
 47
 48	pcp->charptr = 0;
 49}
 50
 51S32	gCurrentSize = 0;
 52
 53F32 gPatchQuantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 54
 55void build_patch_quantize_table(S32 size)
 56{
 57	S32 i, j;
 58	for (j = 0; j < size; j++)
 59	{
 60		for (i = 0; i < size; i++)
 61		{
 62			gPatchQuantizeTable[j*size + i] = 1.f/(1.f + 2.f*(i+j));
 63		}
 64	}
 65}
 66
 67F32	gPatchCosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 68
 69void setup_patch_cosines(S32 size)
 70{
 71	S32 n, u;
 72	F32 oosob = F_PI*0.5f/size;
 73
 74	for (u = 0; u < size; u++)
 75	{
 76		for (n = 0; n < size; n++)
 77		{
 78			gPatchCosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
 79		}
 80	}
 81}
 82
 83S32	gCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
 84
 85void build_copy_matrix(S32 size)
 86{
 87	S32 i, j, count;
 88	BOOL	b_diag = FALSE;
 89	BOOL	b_right = TRUE;
 90
 91	i = 0;
 92	j = 0;
 93	count = 0;
 94
 95	while (  (i < size)
 96		   &&(j < size))
 97	{
 98		gCopyMatrix[j*size + i] = count;
 99
100		count++;
101
102		if (!b_diag)
103		{
104			if (b_right)
105			{
106				if (i < size - 1)
107					i++;
108				else
109					j++;
110				b_right = FALSE;
111				b_diag = TRUE;
112			}
113			else
114			{
115				if (j < size - 1)
116					j++;
117				else
118					i++;
119				b_right = TRUE;
120				b_diag = TRUE;
121			}
122		}
123		else
124		{
125			if (b_right)
126			{
127				i++;
128				j--;
129				if (  (i == size - 1)
130					||(j == 0))
131				{
132					b_diag = FALSE;
133				}
134			}
135			else
136			{
137				i--;
138				j++;
139				if (  (i == 0)
140					||(j == size - 1))
141				{
142					b_diag = FALSE;
143				}
144			}
145		}
146	}
147}
148
149
150void init_patch_compressor(S32 patch_size, S32 patch_stride, S32 layer_type)
151{
152	PCGD *pcp = &gPatchCompressGlobalData;
153
154	pcp->charptr = 0;
155
156	pcp->patch_size = patch_size;
157	pcp->patch_stride = patch_stride;
158	pcp->layer_type = layer_type;
159
160	if (patch_size != gCurrentSize)
161	{
162		gCurrentSize = patch_size;
163		build_patch_quantize_table(patch_size);
164		setup_patch_cosines(patch_size);
165		build_copy_matrix(patch_size);
166	}
167}
168
169void prescan_patch(F32 *patch, LLPatchHeader *php, F32 &zmax, F32 &zmin)
170{
171	S32		i, j;
172	PCGD	*pcp = &gPatchCompressGlobalData;
173	S32		stride = pcp->patch_stride;
174	S32		size = pcp->patch_size;
175	S32		jstride;
176
177	zmax = -99999999.f;
178	zmin = 99999999.f;
179
180	for (j = 0; j < size; j++)
181	{
182		jstride = j*stride;
183		for (i = 0; i < size; i++)
184		{
185			if (*(patch + jstride + i) > zmax)
186			{
187				zmax = *(patch + jstride + i);
188			}
189			if (*(patch + jstride + i) < zmin)
190			{
191				zmin = *(patch + jstride + i);
192			}
193		}
194	}
195
196	php->dc_offset = zmin;
197	php->range = (U16) ((zmax - zmin) + 1.f);
198}
199
200void dct_line(F32 *linein, F32 *lineout, S32 line)
201{
202	S32 u;
203	F32 total;
204	F32 *pcp = gPatchCosines;
205	S32	line_size = line*NORMAL_PATCH_SIZE;
206
207#ifdef _PATCH_SIZE_16_AND_32_ONLY
208	F32 *tlinein, *tpcp;
209
210	tlinein = linein + line_size;
211
212	total = *(tlinein++);
213	total += *(tlinein++);
214	total += *(tlinein++);
215	total += *(tlinein++);
216
217	total += *(tlinein++);
218	total += *(tlinein++);
219	total += *(tlinein++);
220	total += *(tlinein++);
221
222	total += *(tlinein++);
223	total += *(tlinein++);
224	total += *(tlinein++);
225	total += *(tlinein++);
226
227	total += *(tlinein++);
228	total += *(tlinein++);
229	total += *(tlinein++);
230	total += *(tlinein);
231
232	*(lineout + line_size) = OO_SQRT2*total;
233
234	for (u = 1; u < NORMAL_PATCH_SIZE; u++)
235	{
236		tlinein = linein + line_size;
237		tpcp = pcp + (u<<4);
238
239		total = *(tlinein++)*(*(tpcp++));
240		total += *(tlinein++)*(*(tpcp++));
241		total += *(tlinein++)*(*(tpcp++));
242		total += *(tlinein++)*(*(tpcp++));
243
244		total += *(tlinein++)*(*(tpcp++));
245		total += *(tlinein++)*(*(tpcp++));
246		total += *(tlinein++)*(*(tpcp++));
247		total += *(tlinein++)*(*(tpcp++));
248
249		total += *(tlinein++)*(*(tpcp++));
250		total += *(tlinein++)*(*(tpcp++));
251		total += *(tlinein++)*(*(tpcp++));
252		total += *(tlinein++)*(*(tpcp++));
253
254		total += *(tlinein++)*(*(tpcp++));
255		total += *(tlinein++)*(*(tpcp++));
256		total += *(tlinein++)*(*(tpcp++));
257		total += *(tlinein)*(*tpcp);
258
259		*(lineout + line_size + u) = total;
260	}
261#else
262	S32 n;
263	S32	size = gPatchCompressGlobalData.patch_size;
264	total = 0.f;
265	for (n = 0; n < size; n++)
266	{
267		total += linein[line_size + n];
268	}
269	lineout[line_size] = OO_SQRT2*total;
270
271	for (u = 1; u < size; u++)
272	{
273		total = 0.f;
274		for (n = 0; n < size; n++)
275		{
276			total += linein[line_size + n]*pcp[u*size+n];
277		}
278		lineout[line_size + u] = total;
279	}
280#endif
281}
282
283void dct_line_large(F32 *linein, F32 *lineout, S32 line)
284{
285	S32 u;
286	F32 total;
287	F32 *pcp = gPatchCosines;
288	S32	line_size = line*LARGE_PATCH_SIZE;
289
290	F32 *tlinein, *tpcp;
291
292	tlinein = linein + line_size;
293
294	total = *(tlinein++);
295	total += *(tlinein++);
296	total += *(tlinein++);
297	total += *(tlinein++);
298
299	total += *(tlinein++);
300	total += *(tlinein++);
301	total += *(tlinein++);
302	total += *(tlinein++);
303
304	total += *(tlinein++);
305	total += *(tlinein++);
306	total += *(tlinein++);
307	total += *(tlinein++);
308
309	total += *(tlinein++);
310	total += *(tlinein++);
311	total += *(tlinein++);
312	total += *(tlinein++);
313
314	total += *(tlinein++);
315	total += *(tlinein++);
316	total += *(tlinein++);
317	total += *(tlinein++);
318
319	total += *(tlinein++);
320	total += *(tlinein++);
321	total += *(tlinein++);
322	total += *(tlinein++);
323
324	total += *(tlinein++);
325	total += *(tlinein++);
326	total += *(tlinein++);
327	total += *(tlinein++);
328
329	total += *(tlinein++);
330	total += *(tlinein++);
331	total += *(tlinein++);
332	total += *(tlinein);
333
334	*(lineout + line_size) = OO_SQRT2*total;
335
336	for (u = 1; u < LARGE_PATCH_SIZE; u++)
337	{
338		tlinein = linein + line_size;
339		tpcp = pcp + (u<<5);
340
341		total = *(tlinein++)*(*(tpcp++));
342		total += *(tlinein++)*(*(tpcp++));
343		total += *(tlinein++)*(*(tpcp++));
344		total += *(tlinein++)*(*(tpcp++));
345
346		total += *(tlinein++)*(*(tpcp++));
347		total += *(tlinein++)*(*(tpcp++));
348		total += *(tlinein++)*(*(tpcp++));
349		total += *(tlinein++)*(*(tpcp++));
350
351		total += *(tlinein++)*(*(tpcp++));
352		total += *(tlinein++)*(*(tpcp++));
353		total += *(tlinein++)*(*(tpcp++));
354		total += *(tlinein++)*(*(tpcp++));
355
356		total += *(tlinein++)*(*(tpcp++));
357		total += *(tlinein++)*(*(tpcp++));
358		total += *(tlinein++)*(*(tpcp++));
359		total += *(tlinein++)*(*(tpcp++));
360
361		total += *(tlinein++)*(*(tpcp++));
362		total += *(tlinein++)*(*(tpcp++));
363		total += *(tlinein++)*(*(tpcp++));
364		total += *(tlinein++)*(*(tpcp++));
365
366		total += *(tlinein++)*(*(tpcp++));
367		total += *(tlinein++)*(*(tpcp++));
368		total += *(tlinein++)*(*(tpcp++));
369		total += *(tlinein++)*(*(tpcp++));
370
371		total += *(tlinein++)*(*(tpcp++));
372		total += *(tlinein++)*(*(tpcp++));
373		total += *(tlinein++)*(*(tpcp++));
374		total += *(tlinein++)*(*(tpcp++));
375
376		total += *(tlinein++)*(*(tpcp++));
377		total += *(tlinein++)*(*(tpcp++));
378		total += *(tlinein++)*(*(tpcp++));
379		total += *(tlinein)*(*tpcp);
380
381		*(lineout + line_size + u) = total;
382	}
383}
384
385inline void dct_column(F32 *linein, S32 *lineout, S32 column)
386{
387	S32 u;
388	F32 total;
389	F32 oosob = 2.f/16.f;
390	F32 *pcp = gPatchCosines;
391	S32	*copy_matrix = gCopyMatrix;
392	F32	*qt = gPatchQuantizeTable;
393
394#ifdef _PATCH_SIZE_16_AND_32_ONLY
395	F32 *tlinein, *tpcp;
396	S32 sizeu;
397
398	tlinein = linein + column;
399
400	total = *(tlinein);
401	total += *(tlinein += NORMAL_PATCH_SIZE);
402	total += *(tlinein += NORMAL_PATCH_SIZE);
403	total += *(tlinein += NORMAL_PATCH_SIZE);
404
405	total += *(tlinein += NORMAL_PATCH_SIZE);
406	total += *(tlinein += NORMAL_PATCH_SIZE);
407	total += *(tlinein += NORMAL_PATCH_SIZE);
408	total += *(tlinein += NORMAL_PATCH_SIZE);
409
410	total += *(tlinein += NORMAL_PATCH_SIZE);
411	total += *(tlinein += NORMAL_PATCH_SIZE);
412	total += *(tlinein += NORMAL_PATCH_SIZE);
413	total += *(tlinein += NORMAL_PATCH_SIZE);
414
415	total += *(tlinein += NORMAL_PATCH_SIZE);
416	total += *(tlinein += NORMAL_PATCH_SIZE);
417	total += *(tlinein += NORMAL_PATCH_SIZE);
418	total += *(tlinein += NORMAL_PATCH_SIZE);
419
420	*(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
421
422	for (u = 1; u < NORMAL_PATCH_SIZE; u++)
423	{
424		tlinein = linein + column;
425		tpcp = pcp + (u<<4);
426
427		total = *(tlinein)*(*(tpcp++));
428		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
429		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
430		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
431
432		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
433		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
434		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
435		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
436
437		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
438		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
439		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
440		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
441
442		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
443		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
444		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
445		total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp));
446
447		sizeu = NORMAL_PATCH_SIZE*u + column;
448
449		*(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
450	}
451#else
452	S32	size = gPatchCompressGlobalData.patch_size;
453	F32 oosob = 2.f/size;
454	S32 n;
455	total = 0.f;
456	for (n = 0; n < size; n++)
457	{
458		total += linein[size*n + column];
459	}
460	lineout[copy_matrix[column]] = OO_SQRT2*total*oosob*qt[column];
461
462	for (u = 1; u < size; u++)
463	{
464		total = 0.f;
465		for (n = 0; n < size; n++)
466		{
467			total += linein[size*n + column]*pcp[u*size+n];
468		}
469		lineout[copy_matrix[size*u + column]] = total*oosob*qt[size*u + column];
470	}
471#endif
472}
473
474inline void dct_column_large(F32 *linein, S32 *lineout, S32 column)
475{
476	S32 u;
477	F32 total;
478	F32 oosob = 2.f/32.f;
479	F32 *pcp = gPatchCosines;
480	S32	*copy_matrix = gCopyMatrix;
481	F32	*qt = gPatchQuantizeTable;
482
483	F32 *tlinein, *tpcp;
484	S32 sizeu;
485
486	tlinein = linein + column;
487
488	total = *(tlinein);
489	total += *(tlinein += LARGE_PATCH_SIZE);
490	total += *(tlinein += LARGE_PATCH_SIZE);
491	total += *(tlinein += LARGE_PATCH_SIZE);
492
493	total += *(tlinein += LARGE_PATCH_SIZE);
494	total += *(tlinein += LARGE_PATCH_SIZE);
495	total += *(tlinein += LARGE_PATCH_SIZE);
496	total += *(tlinein += LARGE_PATCH_SIZE);
497
498	total += *(tlinein += LARGE_PATCH_SIZE);
499	total += *(tlinein += LARGE_PATCH_SIZE);
500	total += *(tlinein += LARGE_PATCH_SIZE);
501	total += *(tlinein += LARGE_PATCH_SIZE);
502
503	total += *(tlinein += LARGE_PATCH_SIZE);
504	total += *(tlinein += LARGE_PATCH_SIZE);
505	total += *(tlinein += LARGE_PATCH_SIZE);
506	total += *(tlinein += LARGE_PATCH_SIZE);
507
508	total += *(tlinein += LARGE_PATCH_SIZE);
509	total += *(tlinein += LARGE_PATCH_SIZE);
510	total += *(tlinein += LARGE_PATCH_SIZE);
511	total += *(tlinein += LARGE_PATCH_SIZE);
512
513	total += *(tlinein += LARGE_PATCH_SIZE);
514	total += *(tlinein += LARGE_PATCH_SIZE);
515	total += *(tlinein += LARGE_PATCH_SIZE);
516	total += *(tlinein += LARGE_PATCH_SIZE);
517
518	total += *(tlinein += LARGE_PATCH_SIZE);
519	total += *(tlinein += LARGE_PATCH_SIZE);
520	total += *(tlinein += LARGE_PATCH_SIZE);
521	total += *(tlinein += LARGE_PATCH_SIZE);
522
523	total += *(tlinein += LARGE_PATCH_SIZE);
524	total += *(tlinein += LARGE_PATCH_SIZE);
525	total += *(tlinein += LARGE_PATCH_SIZE);
526	total += *(tlinein += LARGE_PATCH_SIZE);
527
528	*(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
529
530	for (u = 1; u < LARGE_PATCH_SIZE; u++)
531	{
532		tlinein = linein + column;
533		tpcp = pcp + (u<<5);
534
535		total = *(tlinein)*(*(tpcp++));
536		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
537		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
538		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
539
540		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
541		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
542		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
543		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
544
545		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
546		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
547		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
548		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
549
550		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
551		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
552		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
553		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
554
555		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
556		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
557		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
558		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
559
560		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
561		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
562		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
563		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
564
565		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
566		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
567		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
568		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
569
570		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
571		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
572		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
573		total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp));
574
575		sizeu = LARGE_PATCH_SIZE*u + column;
576
577		*(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
578	}
579}
580
581inline void dct_patch(F32 *block, S32 *cpatch)
582{
583	F32 temp[NORMAL_PATCH_SIZE*NORMAL_PATCH_SIZE];
584
585#ifdef _PATCH_SIZE_16_AND_32_ONLY
586	dct_line(block, temp, 0);
587	dct_line(block, temp, 1);
588	dct_line(block, temp, 2);
589	dct_line(block, temp, 3);
590
591	dct_line(block, temp, 4);
592	dct_line(block, temp, 5);
593	dct_line(block, temp, 6);
594	dct_line(block, temp, 7);
595
596	dct_line(block, temp, 8);
597	dct_line(block, temp, 9);
598	dct_line(block, temp, 10);
599	dct_line(block, temp, 11);
600
601	dct_line(block, temp, 12);
602	dct_line(block, temp, 13);
603	dct_line(block, temp, 14);
604	dct_line(block, temp, 15);
605
606	dct_column(temp, cpatch, 0);
607	dct_column(temp, cpatch, 1);
608	dct_column(temp, cpatch, 2);
609	dct_column(temp, cpatch, 3);
610
611	dct_column(temp, cpatch, 4);
612	dct_column(temp, cpatch, 5);
613	dct_column(temp, cpatch, 6);
614	dct_column(temp, cpatch, 7);
615
616	dct_column(temp, cpatch, 8);
617	dct_column(temp, cpatch, 9);
618	dct_column(temp, cpatch, 10);
619	dct_column(temp, cpatch, 11);
620
621	dct_column(temp, cpatch, 12);
622	dct_column(temp, cpatch, 13);
623	dct_column(temp, cpatch, 14);
624	dct_column(temp, cpatch, 15);
625#else
626	S32 i;
627	S32	size = gPatchCompressGlobalData.patch_size;
628	for (i = 0; i < size; i++)
629	{
630		dct_line(block, temp, i);
631	}
632	for (i = 0; i < size; i++)
633	{
634		dct_column(temp, cpatch, i);
635	}
636#endif
637}
638
639inline void dct_patch_large(F32 *block, S32 *cpatch)
640{
641	F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
642
643	dct_line_large(block, temp, 0);
644	dct_line_large(block, temp, 1);
645	dct_line_large(block, temp, 2);
646	dct_line_large(block, temp, 3);
647
648	dct_line_large(block, temp, 4);
649	dct_line_large(block, temp, 5);
650	dct_line_large(block, temp, 6);
651	dct_line_large(block, temp, 7);
652
653	dct_line_large(block, temp, 8);
654	dct_line_large(block, temp, 9);
655	dct_line_large(block, temp, 10);
656	dct_line_large(block, temp, 11);
657
658	dct_line_large(block, temp, 12);
659	dct_line_large(block, temp, 13);
660	dct_line_large(block, temp, 14);
661	dct_line_large(block, temp, 15);
662
663	dct_line_large(block, temp, 16);
664	dct_line_large(block, temp, 17);
665	dct_line_large(block, temp, 18);
666	dct_line_large(block, temp, 19);
667
668	dct_line_large(block, temp, 20);
669	dct_line_large(block, temp, 21);
670	dct_line_large(block, temp, 22);
671	dct_line_large(block, temp, 23);
672
673	dct_line_large(block, temp, 24);
674	dct_line_large(block, temp, 25);
675	dct_line_large(block, temp, 26);
676	dct_line_large(block, temp, 27);
677
678	dct_line_large(block, temp, 28);
679	dct_line_large(block, temp, 29);
680	dct_line_large(block, temp, 30);
681	dct_line_large(block, temp, 31);
682
683	dct_column_large(temp, cpatch, 0);
684	dct_column_large(temp, cpatch, 1);
685	dct_column_large(temp, cpatch, 2);
686	dct_column_large(temp, cpatch, 3);
687
688	dct_column_large(temp, cpatch, 4);
689	dct_column_large(temp, cpatch, 5);
690	dct_column_large(temp, cpatch, 6);
691	dct_column_large(temp, cpatch, 7);
692
693	dct_column_large(temp, cpatch, 8);
694	dct_column_large(temp, cpatch, 9);
695	dct_column_large(temp, cpatch, 10);
696	dct_column_large(temp, cpatch, 11);
697
698	dct_column_large(temp, cpatch, 12);
699	dct_column_large(temp, cpatch, 13);
700	dct_column_large(temp, cpatch, 14);
701	dct_column_large(temp, cpatch, 15);
702
703	dct_column_large(temp, cpatch, 16);
704	dct_column_large(temp, cpatch, 17);
705	dct_column_large(temp, cpatch, 18);
706	dct_column_large(temp, cpatch, 19);
707
708	dct_column_large(temp, cpatch, 20);
709	dct_column_large(temp, cpatch, 21);
710	dct_column_large(temp, cpatch, 22);
711	dct_column_large(temp, cpatch, 23);
712
713	dct_column_large(temp, cpatch, 24);
714	dct_column_large(temp, cpatch, 25);
715	dct_column_large(temp, cpatch, 26);
716	dct_column_large(temp, cpatch, 27);
717
718	dct_column_large(temp, cpatch, 28);
719	dct_column_large(temp, cpatch, 29);
720	dct_column_large(temp, cpatch, 30);
721	dct_column_large(temp, cpatch, 31);
722}
723
724void compress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *php, S32 prequant)
725{
726	S32		i, j;
727	PCGD	*pcp = &gPatchCompressGlobalData;
728	S32		stride = pcp->patch_stride;
729	S32		size = pcp->patch_size;
730	F32		block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock;
731	F32		*tpatch;
732
733	S32		wordsize = prequant;
734	F32		oozrange = 1.f/php->range;
735
736	F32		dc = php->dc_offset;
737
738	S32		range = (1<<prequant);
739	F32		premult = oozrange*range;
740//	F32		sub = (F32)(1<<(prequant - 1));
741	F32		sub = (F32)(1<<(prequant - 1)) + dc*premult;
742
743	php->quant_wbits = wordsize - 2;
744	php->quant_wbits |= (prequant - 2)<<4;
745
746	for (j = 0; j < size; j++)
747	{
748		tblock = block + j*size;
749		tpatch = patch + j*stride;
750		for (i = 0; i < size; i++)
751		{
752//			block[j*size + i] = (patch[j*stride + i] - dc)*premult - sub;
753			*(tblock++) = *(tpatch++)*premult - sub;
754		}
755	}
756
757	if (size == 16)
758		dct_patch(block, cpatch);
759	else
760		dct_patch_large(block, cpatch);
761}
762
763void get_patch_group_header(LLGroupHeader *gopp)
764{
765	PCGD	*pcp = &gPatchCompressGlobalData;
766	gopp->stride = pcp->patch_stride;
767	gopp->patch_size = pcp->patch_size;
768	gopp->layer_type = pcp->layer_type;
769}