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