patch_dct.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llmath.h"
00035 //#include "vmath.h"
00036 #include "v3math.h"
00037 #include "patch_dct.h"
00038 
00039 typedef struct s_patch_compress_global_data
00040 {
00041         S32 patch_size;
00042         S32 patch_stride;
00043         U32 charptr;
00044         S32 layer_type;
00045 } PCGD;
00046 
00047 PCGD    gPatchCompressGlobalData;
00048 
00049 void reset_patch_compressor(void)
00050 {
00051         PCGD *pcp = &gPatchCompressGlobalData;
00052 
00053         pcp->charptr = 0;
00054 }
00055 
00056 S32     gCurrentSize = 0;
00057 
00058 F32 gPatchQuantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
00059 
00060 void build_patch_quantize_table(S32 size)
00061 {
00062         S32 i, j;
00063         for (j = 0; j < size; j++)
00064         {
00065                 for (i = 0; i < size; i++)
00066                 {
00067                         gPatchQuantizeTable[j*size + i] = 1.f/(1.f + 2.f*(i+j));
00068                 }
00069         }
00070 }
00071 
00072 F32     gPatchCosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
00073 
00074 void setup_patch_cosines(S32 size)
00075 {
00076         S32 n, u;
00077         F32 oosob = F_PI*0.5f/size;
00078 
00079         for (u = 0; u < size; u++)
00080         {
00081                 for (n = 0; n < size; n++)
00082                 {
00083                         gPatchCosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
00084                 }
00085         }
00086 }
00087 
00088 S32     gCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
00089 
00090 void build_copy_matrix(S32 size)
00091 {
00092         S32 i, j, count;
00093         BOOL    b_diag = FALSE;
00094         BOOL    b_right = TRUE;
00095 
00096         i = 0;
00097         j = 0;
00098         count = 0;
00099 
00100         while (  (i < size)
00101                    &&(j < size))
00102         {
00103                 gCopyMatrix[j*size + i] = count;
00104 
00105                 count++;
00106 
00107                 if (!b_diag)
00108                 {
00109                         if (b_right)
00110                         {
00111                                 if (i < size - 1)
00112                                         i++;
00113                                 else
00114                                         j++;
00115                                 b_right = FALSE;
00116                                 b_diag = TRUE;
00117                         }
00118                         else
00119                         {
00120                                 if (j < size - 1)
00121                                         j++;
00122                                 else
00123                                         i++;
00124                                 b_right = TRUE;
00125                                 b_diag = TRUE;
00126                         }
00127                 }
00128                 else
00129                 {
00130                         if (b_right)
00131                         {
00132                                 i++;
00133                                 j--;
00134                                 if (  (i == size - 1)
00135                                         ||(j == 0))
00136                                 {
00137                                         b_diag = FALSE;
00138                                 }
00139                         }
00140                         else
00141                         {
00142                                 i--;
00143                                 j++;
00144                                 if (  (i == 0)
00145                                         ||(j == size - 1))
00146                                 {
00147                                         b_diag = FALSE;
00148                                 }
00149                         }
00150                 }
00151         }
00152 }
00153 
00154 
00155 void init_patch_compressor(S32 patch_size, S32 patch_stride, S32 layer_type)
00156 {
00157         PCGD *pcp = &gPatchCompressGlobalData;
00158 
00159         pcp->charptr = 0;
00160 
00161         pcp->patch_size = patch_size;
00162         pcp->patch_stride = patch_stride;
00163         pcp->layer_type = layer_type;
00164 
00165         if (patch_size != gCurrentSize)
00166         {
00167                 gCurrentSize = patch_size;
00168                 build_patch_quantize_table(patch_size);
00169                 setup_patch_cosines(patch_size);
00170                 build_copy_matrix(patch_size);
00171         }
00172 }
00173 
00174 void prescan_patch(F32 *patch, LLPatchHeader *php, F32 &zmax, F32 &zmin)
00175 {
00176         S32             i, j;
00177         PCGD    *pcp = &gPatchCompressGlobalData;
00178         S32             stride = pcp->patch_stride;
00179         S32             size = pcp->patch_size;
00180         S32             jstride;
00181 
00182         zmax = -99999999.f;
00183         zmin = 99999999.f;
00184 
00185         for (j = 0; j < size; j++)
00186         {
00187                 jstride = j*stride;
00188                 for (i = 0; i < size; i++)
00189                 {
00190                         if (*(patch + jstride + i) > zmax)
00191                         {
00192                                 zmax = *(patch + jstride + i);
00193                         }
00194                         if (*(patch + jstride + i) < zmin)
00195                         {
00196                                 zmin = *(patch + jstride + i);
00197                         }
00198                 }
00199         }
00200 
00201         php->dc_offset = zmin;
00202         php->range = (U16) ((zmax - zmin) + 1.f);
00203 }
00204 
00205 void dct_line(F32 *linein, F32 *lineout, S32 line)
00206 {
00207         S32 u;
00208         F32 total;
00209         F32 *pcp = gPatchCosines;
00210         S32     line_size = line*NORMAL_PATCH_SIZE;
00211 
00212 #ifdef _PATCH_SIZE_16_AND_32_ONLY
00213         F32 *tlinein, *tpcp;
00214 
00215         tlinein = linein + line_size;
00216 
00217         total = *(tlinein++);
00218         total += *(tlinein++);
00219         total += *(tlinein++);
00220         total += *(tlinein++);
00221 
00222         total += *(tlinein++);
00223         total += *(tlinein++);
00224         total += *(tlinein++);
00225         total += *(tlinein++);
00226 
00227         total += *(tlinein++);
00228         total += *(tlinein++);
00229         total += *(tlinein++);
00230         total += *(tlinein++);
00231 
00232         total += *(tlinein++);
00233         total += *(tlinein++);
00234         total += *(tlinein++);
00235         total += *(tlinein);
00236 
00237         *(lineout + line_size) = OO_SQRT2*total;
00238 
00239         for (u = 1; u < NORMAL_PATCH_SIZE; u++)
00240         {
00241                 tlinein = linein + line_size;
00242                 tpcp = pcp + (u<<4);
00243 
00244                 total = *(tlinein++)*(*(tpcp++));
00245                 total += *(tlinein++)*(*(tpcp++));
00246                 total += *(tlinein++)*(*(tpcp++));
00247                 total += *(tlinein++)*(*(tpcp++));
00248 
00249                 total += *(tlinein++)*(*(tpcp++));
00250                 total += *(tlinein++)*(*(tpcp++));
00251                 total += *(tlinein++)*(*(tpcp++));
00252                 total += *(tlinein++)*(*(tpcp++));
00253 
00254                 total += *(tlinein++)*(*(tpcp++));
00255                 total += *(tlinein++)*(*(tpcp++));
00256                 total += *(tlinein++)*(*(tpcp++));
00257                 total += *(tlinein++)*(*(tpcp++));
00258 
00259                 total += *(tlinein++)*(*(tpcp++));
00260                 total += *(tlinein++)*(*(tpcp++));
00261                 total += *(tlinein++)*(*(tpcp++));
00262                 total += *(tlinein)*(*tpcp);
00263 
00264                 *(lineout + line_size + u) = total;
00265         }
00266 #else
00267         S32 n;
00268         S32     size = gPatchCompressGlobalData.patch_size;
00269         total = 0.f;
00270         for (n = 0; n < size; n++)
00271         {
00272                 total += linein[line_size + n];
00273         }
00274         lineout[line_size] = OO_SQRT2*total;
00275 
00276         for (u = 1; u < size; u++)
00277         {
00278                 total = 0.f;
00279                 for (n = 0; n < size; n++)
00280                 {
00281                         total += linein[line_size + n]*pcp[u*size+n];
00282                 }
00283                 lineout[line_size + u] = total;
00284         }
00285 #endif
00286 }
00287 
00288 void dct_line_large(F32 *linein, F32 *lineout, S32 line)
00289 {
00290         S32 u;
00291         F32 total;
00292         F32 *pcp = gPatchCosines;
00293         S32     line_size = line*LARGE_PATCH_SIZE;
00294 
00295         F32 *tlinein, *tpcp;
00296 
00297         tlinein = linein + line_size;
00298 
00299         total = *(tlinein++);
00300         total += *(tlinein++);
00301         total += *(tlinein++);
00302         total += *(tlinein++);
00303 
00304         total += *(tlinein++);
00305         total += *(tlinein++);
00306         total += *(tlinein++);
00307         total += *(tlinein++);
00308 
00309         total += *(tlinein++);
00310         total += *(tlinein++);
00311         total += *(tlinein++);
00312         total += *(tlinein++);
00313 
00314         total += *(tlinein++);
00315         total += *(tlinein++);
00316         total += *(tlinein++);
00317         total += *(tlinein++);
00318 
00319         total += *(tlinein++);
00320         total += *(tlinein++);
00321         total += *(tlinein++);
00322         total += *(tlinein++);
00323 
00324         total += *(tlinein++);
00325         total += *(tlinein++);
00326         total += *(tlinein++);
00327         total += *(tlinein++);
00328 
00329         total += *(tlinein++);
00330         total += *(tlinein++);
00331         total += *(tlinein++);
00332         total += *(tlinein++);
00333 
00334         total += *(tlinein++);
00335         total += *(tlinein++);
00336         total += *(tlinein++);
00337         total += *(tlinein);
00338 
00339         *(lineout + line_size) = OO_SQRT2*total;
00340 
00341         for (u = 1; u < LARGE_PATCH_SIZE; u++)
00342         {
00343                 tlinein = linein + line_size;
00344                 tpcp = pcp + (u<<5);
00345 
00346                 total = *(tlinein++)*(*(tpcp++));
00347                 total += *(tlinein++)*(*(tpcp++));
00348                 total += *(tlinein++)*(*(tpcp++));
00349                 total += *(tlinein++)*(*(tpcp++));
00350 
00351                 total += *(tlinein++)*(*(tpcp++));
00352                 total += *(tlinein++)*(*(tpcp++));
00353                 total += *(tlinein++)*(*(tpcp++));
00354                 total += *(tlinein++)*(*(tpcp++));
00355 
00356                 total += *(tlinein++)*(*(tpcp++));
00357                 total += *(tlinein++)*(*(tpcp++));
00358                 total += *(tlinein++)*(*(tpcp++));
00359                 total += *(tlinein++)*(*(tpcp++));
00360 
00361                 total += *(tlinein++)*(*(tpcp++));
00362                 total += *(tlinein++)*(*(tpcp++));
00363                 total += *(tlinein++)*(*(tpcp++));
00364                 total += *(tlinein++)*(*(tpcp++));
00365 
00366                 total += *(tlinein++)*(*(tpcp++));
00367                 total += *(tlinein++)*(*(tpcp++));
00368                 total += *(tlinein++)*(*(tpcp++));
00369                 total += *(tlinein++)*(*(tpcp++));
00370 
00371                 total += *(tlinein++)*(*(tpcp++));
00372                 total += *(tlinein++)*(*(tpcp++));
00373                 total += *(tlinein++)*(*(tpcp++));
00374                 total += *(tlinein++)*(*(tpcp++));
00375 
00376                 total += *(tlinein++)*(*(tpcp++));
00377                 total += *(tlinein++)*(*(tpcp++));
00378                 total += *(tlinein++)*(*(tpcp++));
00379                 total += *(tlinein++)*(*(tpcp++));
00380 
00381                 total += *(tlinein++)*(*(tpcp++));
00382                 total += *(tlinein++)*(*(tpcp++));
00383                 total += *(tlinein++)*(*(tpcp++));
00384                 total += *(tlinein)*(*tpcp);
00385 
00386                 *(lineout + line_size + u) = total;
00387         }
00388 }
00389 
00390 inline void dct_column(F32 *linein, S32 *lineout, S32 column)
00391 {
00392         S32 u;
00393         F32 total;
00394         F32 oosob = 2.f/16.f;
00395         F32 *pcp = gPatchCosines;
00396         S32     *copy_matrix = gCopyMatrix;
00397         F32     *qt = gPatchQuantizeTable;
00398 
00399 #ifdef _PATCH_SIZE_16_AND_32_ONLY
00400         F32 *tlinein, *tpcp;
00401         S32 sizeu;
00402 
00403         tlinein = linein + column;
00404 
00405         total = *(tlinein);
00406         total += *(tlinein += NORMAL_PATCH_SIZE);
00407         total += *(tlinein += NORMAL_PATCH_SIZE);
00408         total += *(tlinein += NORMAL_PATCH_SIZE);
00409 
00410         total += *(tlinein += NORMAL_PATCH_SIZE);
00411         total += *(tlinein += NORMAL_PATCH_SIZE);
00412         total += *(tlinein += NORMAL_PATCH_SIZE);
00413         total += *(tlinein += NORMAL_PATCH_SIZE);
00414 
00415         total += *(tlinein += NORMAL_PATCH_SIZE);
00416         total += *(tlinein += NORMAL_PATCH_SIZE);
00417         total += *(tlinein += NORMAL_PATCH_SIZE);
00418         total += *(tlinein += NORMAL_PATCH_SIZE);
00419 
00420         total += *(tlinein += NORMAL_PATCH_SIZE);
00421         total += *(tlinein += NORMAL_PATCH_SIZE);
00422         total += *(tlinein += NORMAL_PATCH_SIZE);
00423         total += *(tlinein += NORMAL_PATCH_SIZE);
00424 
00425         *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
00426 
00427         for (u = 1; u < NORMAL_PATCH_SIZE; u++)
00428         {
00429                 tlinein = linein + column;
00430                 tpcp = pcp + (u<<4);
00431 
00432                 total = *(tlinein)*(*(tpcp++));
00433                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00434                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00435                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00436 
00437                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00438                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00439                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00440                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00441 
00442                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00443                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00444                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00445                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00446 
00447                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00448                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00449                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
00450                 total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp));
00451 
00452                 sizeu = NORMAL_PATCH_SIZE*u + column;
00453 
00454                 *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
00455         }
00456 #else
00457         S32     size = gPatchCompressGlobalData.patch_size;
00458         F32 oosob = 2.f/size;
00459         S32 n;
00460         total = 0.f;
00461         for (n = 0; n < size; n++)
00462         {
00463                 total += linein[size*n + column];
00464         }
00465         lineout[copy_matrix[column]] = OO_SQRT2*total*oosob*qt[column];
00466 
00467         for (u = 1; u < size; u++)
00468         {
00469                 total = 0.f;
00470                 for (n = 0; n < size; n++)
00471                 {
00472                         total += linein[size*n + column]*pcp[u*size+n];
00473                 }
00474                 lineout[copy_matrix[size*u + column]] = total*oosob*qt[size*u + column];
00475         }
00476 #endif
00477 }
00478 
00479 inline void dct_column_large(F32 *linein, S32 *lineout, S32 column)
00480 {
00481         S32 u;
00482         F32 total;
00483         F32 oosob = 2.f/32.f;
00484         F32 *pcp = gPatchCosines;
00485         S32     *copy_matrix = gCopyMatrix;
00486         F32     *qt = gPatchQuantizeTable;
00487 
00488         F32 *tlinein, *tpcp;
00489         S32 sizeu;
00490 
00491         tlinein = linein + column;
00492 
00493         total = *(tlinein);
00494         total += *(tlinein += LARGE_PATCH_SIZE);
00495         total += *(tlinein += LARGE_PATCH_SIZE);
00496         total += *(tlinein += LARGE_PATCH_SIZE);
00497 
00498         total += *(tlinein += LARGE_PATCH_SIZE);
00499         total += *(tlinein += LARGE_PATCH_SIZE);
00500         total += *(tlinein += LARGE_PATCH_SIZE);
00501         total += *(tlinein += LARGE_PATCH_SIZE);
00502 
00503         total += *(tlinein += LARGE_PATCH_SIZE);
00504         total += *(tlinein += LARGE_PATCH_SIZE);
00505         total += *(tlinein += LARGE_PATCH_SIZE);
00506         total += *(tlinein += LARGE_PATCH_SIZE);
00507 
00508         total += *(tlinein += LARGE_PATCH_SIZE);
00509         total += *(tlinein += LARGE_PATCH_SIZE);
00510         total += *(tlinein += LARGE_PATCH_SIZE);
00511         total += *(tlinein += LARGE_PATCH_SIZE);
00512 
00513         total += *(tlinein += LARGE_PATCH_SIZE);
00514         total += *(tlinein += LARGE_PATCH_SIZE);
00515         total += *(tlinein += LARGE_PATCH_SIZE);
00516         total += *(tlinein += LARGE_PATCH_SIZE);
00517 
00518         total += *(tlinein += LARGE_PATCH_SIZE);
00519         total += *(tlinein += LARGE_PATCH_SIZE);
00520         total += *(tlinein += LARGE_PATCH_SIZE);
00521         total += *(tlinein += LARGE_PATCH_SIZE);
00522 
00523         total += *(tlinein += LARGE_PATCH_SIZE);
00524         total += *(tlinein += LARGE_PATCH_SIZE);
00525         total += *(tlinein += LARGE_PATCH_SIZE);
00526         total += *(tlinein += LARGE_PATCH_SIZE);
00527 
00528         total += *(tlinein += LARGE_PATCH_SIZE);
00529         total += *(tlinein += LARGE_PATCH_SIZE);
00530         total += *(tlinein += LARGE_PATCH_SIZE);
00531         total += *(tlinein += LARGE_PATCH_SIZE);
00532 
00533         *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
00534 
00535         for (u = 1; u < LARGE_PATCH_SIZE; u++)
00536         {
00537                 tlinein = linein + column;
00538                 tpcp = pcp + (u<<5);
00539 
00540                 total = *(tlinein)*(*(tpcp++));
00541                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00542                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00543                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00544 
00545                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00546                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00547                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00548                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00549 
00550                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00551                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00552                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00553                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00554 
00555                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00556                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00557                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00558                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00559 
00560                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00561                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00562                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00563                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00564 
00565                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00566                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00567                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00568                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00569 
00570                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00571                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00572                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00573                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00574 
00575                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00576                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00577                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
00578                 total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp));
00579 
00580                 sizeu = LARGE_PATCH_SIZE*u + column;
00581 
00582                 *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
00583         }
00584 }
00585 
00586 inline void dct_patch(F32 *block, S32 *cpatch)
00587 {
00588         F32 temp[NORMAL_PATCH_SIZE*NORMAL_PATCH_SIZE];
00589 
00590 #ifdef _PATCH_SIZE_16_AND_32_ONLY
00591         dct_line(block, temp, 0);
00592         dct_line(block, temp, 1);
00593         dct_line(block, temp, 2);
00594         dct_line(block, temp, 3);
00595 
00596         dct_line(block, temp, 4);
00597         dct_line(block, temp, 5);
00598         dct_line(block, temp, 6);
00599         dct_line(block, temp, 7);
00600 
00601         dct_line(block, temp, 8);
00602         dct_line(block, temp, 9);
00603         dct_line(block, temp, 10);
00604         dct_line(block, temp, 11);
00605 
00606         dct_line(block, temp, 12);
00607         dct_line(block, temp, 13);
00608         dct_line(block, temp, 14);
00609         dct_line(block, temp, 15);
00610 
00611         dct_column(temp, cpatch, 0);
00612         dct_column(temp, cpatch, 1);
00613         dct_column(temp, cpatch, 2);
00614         dct_column(temp, cpatch, 3);
00615 
00616         dct_column(temp, cpatch, 4);
00617         dct_column(temp, cpatch, 5);
00618         dct_column(temp, cpatch, 6);
00619         dct_column(temp, cpatch, 7);
00620 
00621         dct_column(temp, cpatch, 8);
00622         dct_column(temp, cpatch, 9);
00623         dct_column(temp, cpatch, 10);
00624         dct_column(temp, cpatch, 11);
00625 
00626         dct_column(temp, cpatch, 12);
00627         dct_column(temp, cpatch, 13);
00628         dct_column(temp, cpatch, 14);
00629         dct_column(temp, cpatch, 15);
00630 #else
00631         S32 i;
00632         S32     size = gPatchCompressGlobalData.patch_size;
00633         for (i = 0; i < size; i++)
00634         {
00635                 dct_line(block, temp, i);
00636         }
00637         for (i = 0; i < size; i++)
00638         {
00639                 dct_column(temp, cpatch, i);
00640         }
00641 #endif
00642 }
00643 
00644 inline void dct_patch_large(F32 *block, S32 *cpatch)
00645 {
00646         F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
00647 
00648         dct_line_large(block, temp, 0);
00649         dct_line_large(block, temp, 1);
00650         dct_line_large(block, temp, 2);
00651         dct_line_large(block, temp, 3);
00652 
00653         dct_line_large(block, temp, 4);
00654         dct_line_large(block, temp, 5);
00655         dct_line_large(block, temp, 6);
00656         dct_line_large(block, temp, 7);
00657 
00658         dct_line_large(block, temp, 8);
00659         dct_line_large(block, temp, 9);
00660         dct_line_large(block, temp, 10);
00661         dct_line_large(block, temp, 11);
00662 
00663         dct_line_large(block, temp, 12);
00664         dct_line_large(block, temp, 13);
00665         dct_line_large(block, temp, 14);
00666         dct_line_large(block, temp, 15);
00667 
00668         dct_line_large(block, temp, 16);
00669         dct_line_large(block, temp, 17);
00670         dct_line_large(block, temp, 18);
00671         dct_line_large(block, temp, 19);
00672 
00673         dct_line_large(block, temp, 20);
00674         dct_line_large(block, temp, 21);
00675         dct_line_large(block, temp, 22);
00676         dct_line_large(block, temp, 23);
00677 
00678         dct_line_large(block, temp, 24);
00679         dct_line_large(block, temp, 25);
00680         dct_line_large(block, temp, 26);
00681         dct_line_large(block, temp, 27);
00682 
00683         dct_line_large(block, temp, 28);
00684         dct_line_large(block, temp, 29);
00685         dct_line_large(block, temp, 30);
00686         dct_line_large(block, temp, 31);
00687 
00688         dct_column_large(temp, cpatch, 0);
00689         dct_column_large(temp, cpatch, 1);
00690         dct_column_large(temp, cpatch, 2);
00691         dct_column_large(temp, cpatch, 3);
00692 
00693         dct_column_large(temp, cpatch, 4);
00694         dct_column_large(temp, cpatch, 5);
00695         dct_column_large(temp, cpatch, 6);
00696         dct_column_large(temp, cpatch, 7);
00697 
00698         dct_column_large(temp, cpatch, 8);
00699         dct_column_large(temp, cpatch, 9);
00700         dct_column_large(temp, cpatch, 10);
00701         dct_column_large(temp, cpatch, 11);
00702 
00703         dct_column_large(temp, cpatch, 12);
00704         dct_column_large(temp, cpatch, 13);
00705         dct_column_large(temp, cpatch, 14);
00706         dct_column_large(temp, cpatch, 15);
00707 
00708         dct_column_large(temp, cpatch, 16);
00709         dct_column_large(temp, cpatch, 17);
00710         dct_column_large(temp, cpatch, 18);
00711         dct_column_large(temp, cpatch, 19);
00712 
00713         dct_column_large(temp, cpatch, 20);
00714         dct_column_large(temp, cpatch, 21);
00715         dct_column_large(temp, cpatch, 22);
00716         dct_column_large(temp, cpatch, 23);
00717 
00718         dct_column_large(temp, cpatch, 24);
00719         dct_column_large(temp, cpatch, 25);
00720         dct_column_large(temp, cpatch, 26);
00721         dct_column_large(temp, cpatch, 27);
00722 
00723         dct_column_large(temp, cpatch, 28);
00724         dct_column_large(temp, cpatch, 29);
00725         dct_column_large(temp, cpatch, 30);
00726         dct_column_large(temp, cpatch, 31);
00727 }
00728 
00729 void compress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *php, S32 prequant)
00730 {
00731         S32             i, j;
00732         PCGD    *pcp = &gPatchCompressGlobalData;
00733         S32             stride = pcp->patch_stride;
00734         S32             size = pcp->patch_size;
00735         F32             block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock;
00736         F32             *tpatch;
00737 
00738         S32             wordsize = prequant;
00739         F32             oozrange = 1.f/php->range;
00740 
00741         F32             dc = php->dc_offset;
00742 
00743         S32             range = (1<<prequant);
00744         F32             premult = oozrange*range;
00745 //      F32             sub = (F32)(1<<(prequant - 1));
00746         F32             sub = (F32)(1<<(prequant - 1)) + dc*premult;
00747 
00748         php->quant_wbits = wordsize - 2;
00749         php->quant_wbits |= (prequant - 2)<<4;
00750 
00751         for (j = 0; j < size; j++)
00752         {
00753                 tblock = block + j*size;
00754                 tpatch = patch + j*stride;
00755                 for (i = 0; i < size; i++)
00756                 {
00757 //                      block[j*size + i] = (patch[j*stride + i] - dc)*premult - sub;
00758                         *(tblock++) = *(tpatch++)*premult - sub;
00759                 }
00760         }
00761 
00762         if (size == 16)
00763                 dct_patch(block, cpatch);
00764         else
00765                 dct_patch_large(block, cpatch);
00766 }
00767 
00768 void get_patch_group_header(LLGroupHeader *gopp)
00769 {
00770         PCGD    *pcp = &gPatchCompressGlobalData;
00771         gopp->stride = pcp->patch_stride;
00772         gopp->patch_size = pcp->patch_size;
00773         gopp->layer_type = pcp->layer_type;
00774 }

Generated on Fri May 16 08:32:45 2008 for SecondLife by  doxygen 1.5.5