123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419 |
- /**
- * @file llpatch_dct.cpp
- * @brief DCT patch.
- *
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "linden_common.h"
- #include "llmath.h"
- #include "llvector3.h"
- #include "llpatch_dct.h"
- typedef struct s_patch_compress_global_data
- {
- S32 patch_size;
- S32 patch_stride;
- U32 charptr;
- S32 layer_type;
- } PCGD;
- PCGD gPatchCompressGlobalData;
- void reset_patch_compressor()
- {
- PCGD* pcp = &gPatchCompressGlobalData;
- pcp->charptr = 0;
- }
- S32 gCurrentSize = 0;
- F32 gPatchQuantizeTable[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- void build_patch_quantize_table(S32 size)
- {
- for (S32 j = 0; j < size; ++j)
- {
- for (S32 i = 0; i < size; ++i)
- {
- gPatchQuantizeTable[j * size + i] = 1.f / (1.f + 2.f * (i + j));
- }
- }
- }
- F32 gPatchCosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
- void setup_patch_cosines(S32 size)
- {
- F32 oosob = F_PI * 0.5f / size;
- for (S32 u = 0; u < size; ++u)
- {
- for (S32 n = 0; n < size; ++n)
- {
- gPatchCosines[u * size + n] = cosf((2.f * n + 1.f) * u * oosob);
- }
- }
- }
- S32 gCopyMatrix[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- void build_copy_matrix(S32 size)
- {
- bool b_diag = false;
- bool b_right = true;
- S32 i = 0;
- S32 j = 0;
- S32 count = 0;
- while (i < size && j < size)
- {
- gCopyMatrix[j * size + i] = count++;
- if (!b_diag)
- {
- if (b_right)
- {
- if (i < size - 1)
- {
- ++i;
- }
- else
- {
- ++j;
- }
- b_right = false;
- b_diag = true;
- }
- else
- {
- if (j < size - 1)
- {
- ++j;
- }
- else
- {
- ++i;
- }
- b_right = true;
- b_diag = true;
- }
- }
- else
- {
- if (b_right)
- {
- ++i;
- --j;
- if (i == size - 1 || j == 0)
- {
- b_diag = false;
- }
- }
- else
- {
- --i;
- ++j;
- if (i == 0 || j == size - 1)
- {
- b_diag = false;
- }
- }
- }
- }
- }
- void init_patch_compressor(S32 patch_size, S32 patch_stride, S32 layer_type)
- {
- PCGD* pcp = &gPatchCompressGlobalData;
- pcp->charptr = 0;
- pcp->patch_size = patch_size;
- pcp->patch_stride = patch_stride;
- pcp->layer_type = layer_type;
- if (patch_size != gCurrentSize)
- {
- gCurrentSize = patch_size;
- build_patch_quantize_table(patch_size);
- setup_patch_cosines(patch_size);
- build_copy_matrix(patch_size);
- }
- }
- void prescan_patch(F32* patch, LLPatchHeader* php, F32& zmax, F32& zmin)
- {
- PCGD* pcp = &gPatchCompressGlobalData;
- S32 stride = pcp->patch_stride;
- S32 size = pcp->patch_size;
- S32 jstride;
- zmax = -99999999.f;
- zmin = 99999999.f;
- for (S32 j = 0; j < size; ++j)
- {
- jstride = j * stride;
- for (S32 i = 0; i < size; ++i)
- {
- if (*(patch + jstride + i) > zmax)
- {
- zmax = *(patch + jstride + i);
- }
- if (*(patch + jstride + i) < zmin)
- {
- zmin = *(patch + jstride + i);
- }
- }
- }
- php->dc_offset = zmin;
- php->range = (U16)(zmax - zmin + 1.f);
- }
- void dct_line(F32* linein, F32* lineout, S32 line)
- {
- F32 total;
- F32 *pcp = gPatchCosines;
- S32 line_size = line * NORMAL_PATCH_SIZE;
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- F32* tlinein;
- F32* tpcp;
- tlinein = linein + line_size;
- total = *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein);
- *(lineout + line_size) = OO_SQRT2 * total;
- for (S32 u = 1; u < NORMAL_PATCH_SIZE; ++u)
- {
- tlinein = linein + line_size;
- tpcp = pcp + (u<<4);
- total = *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein)*(*tpcp);
- *(lineout + line_size + u) = total;
- }
- #else
- S32 size = gPatchCompressGlobalData.patch_size;
- total = 0.f;
- for (S32 n = 0; n < size; ++n)
- {
- total += linein[line_size + n];
- }
- lineout[line_size] = OO_SQRT2*total;
- for (S32 u = 1; u < size; ++u)
- {
- total = 0.f;
- for (S32 n = 0; n < size; ++n)
- {
- total += linein[line_size + n] * pcp[u * size + n];
- }
- lineout[line_size + u] = total;
- }
- #endif
- }
- void dct_line_large(F32* linein, F32* lineout, S32 line)
- {
- F32 total;
- F32* pcp = gPatchCosines;
- S32 line_size = line * LARGE_PATCH_SIZE;
- F32* tlinein;
- F32* tpcp;
- tlinein = linein + line_size;
- total = *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein++);
- total += *(tlinein);
- *(lineout + line_size) = OO_SQRT2 * total;
- for (S32 u = 1; u < LARGE_PATCH_SIZE; ++u)
- {
- tlinein = linein + line_size;
- tpcp = pcp + (u << 5);
- total = *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein++) * (*(tpcp++));
- total += *(tlinein) * (*tpcp);
- *(lineout + line_size + u) = total;
- }
- }
- LL_INLINE void dct_column(F32* linein, S32* lineout, S32 column)
- {
- F32 total;
- F32 oosob = 2.f / 16.f;
- F32* pcp = gPatchCosines;
- S32* copy_matrix = gCopyMatrix;
- F32* qt = gPatchQuantizeTable;
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- F32* tlinein;
- F32* tpcp;
- S32 sizeu;
- tlinein = linein + column;
- total = *(tlinein);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- total += *(tlinein += NORMAL_PATCH_SIZE);
- *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2 * total * oosob*(*(qt + column)));
- for (S32 u = 1; u < NORMAL_PATCH_SIZE; ++u)
- {
- tlinein = linein + column;
- tpcp = pcp + (u << 4);
- total = *(tlinein)*(*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp));
- sizeu = NORMAL_PATCH_SIZE * u + column;
- *(lineout + *(copy_matrix + sizeu)) = (S32)(total * oosob * (*(qt + sizeu)));
- }
- #else
- S32 size = gPatchCompressGlobalData.patch_size;
- F32 oosob = 2.f / size;
- total = 0.f;
- for (S32 n = 0; n < size; ++n)
- {
- total += linein[size * n + column];
- }
- lineout[copy_matrix[column]] = OO_SQRT2 * total * oosob * qt[column];
- for (S32 u = 1; u < size; ++u)
- {
- total = 0.f;
- for (S32 n = 0; n < size; ++n)
- {
- total += linein[size * n + column] * pcp[u * size + n];
- }
- lineout[copy_matrix[size * u + column]] = total * oosob * qt[size * u + column];
- }
- #endif
- }
- LL_INLINE void dct_column_large(F32* linein, S32* lineout, S32 column)
- {
- F32 total;
- F32 oosob = 2.f / 32.f;
- F32* pcp = gPatchCosines;
- S32* copy_matrix = gCopyMatrix;
- F32* qt = gPatchQuantizeTable;
- F32* tlinein;
- F32* tpcp;
- S32 sizeu;
- tlinein = linein + column;
- total = *(tlinein);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- total += *(tlinein += LARGE_PATCH_SIZE);
- *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
- for (S32 u = 1; u < LARGE_PATCH_SIZE; ++u)
- {
- tlinein = linein + column;
- tpcp = pcp + (u << 5);
- total = *(tlinein)*(*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp++));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp));
- sizeu = LARGE_PATCH_SIZE * u + column;
- *(lineout + *(copy_matrix + sizeu)) = (S32)(total * oosob * (*(qt + sizeu)));
- }
- }
- LL_INLINE void dct_patch(F32* block, S32* cpatch)
- {
- F32 temp[NORMAL_PATCH_SIZE * NORMAL_PATCH_SIZE];
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- dct_line(block, temp, 0);
- dct_line(block, temp, 1);
- dct_line(block, temp, 2);
- dct_line(block, temp, 3);
- dct_line(block, temp, 4);
- dct_line(block, temp, 5);
- dct_line(block, temp, 6);
- dct_line(block, temp, 7);
- dct_line(block, temp, 8);
- dct_line(block, temp, 9);
- dct_line(block, temp, 10);
- dct_line(block, temp, 11);
- dct_line(block, temp, 12);
- dct_line(block, temp, 13);
- dct_line(block, temp, 14);
- dct_line(block, temp, 15);
- dct_column(temp, cpatch, 0);
- dct_column(temp, cpatch, 1);
- dct_column(temp, cpatch, 2);
- dct_column(temp, cpatch, 3);
- dct_column(temp, cpatch, 4);
- dct_column(temp, cpatch, 5);
- dct_column(temp, cpatch, 6);
- dct_column(temp, cpatch, 7);
- dct_column(temp, cpatch, 8);
- dct_column(temp, cpatch, 9);
- dct_column(temp, cpatch, 10);
- dct_column(temp, cpatch, 11);
- dct_column(temp, cpatch, 12);
- dct_column(temp, cpatch, 13);
- dct_column(temp, cpatch, 14);
- dct_column(temp, cpatch, 15);
- #else
- S32 size = gPatchCompressGlobalData.patch_size;
- for (S32 i = 0; i < size; ++i)
- {
- dct_line(block, temp, i);
- }
- for (S32 i = 0; i < size; ++i)
- {
- dct_column(temp, cpatch, i);
- }
- #endif
- }
- LL_INLINE void dct_patch_large(F32* block, S32* cpatch)
- {
- F32 temp[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- dct_line_large(block, temp, 0);
- dct_line_large(block, temp, 1);
- dct_line_large(block, temp, 2);
- dct_line_large(block, temp, 3);
- dct_line_large(block, temp, 4);
- dct_line_large(block, temp, 5);
- dct_line_large(block, temp, 6);
- dct_line_large(block, temp, 7);
- dct_line_large(block, temp, 8);
- dct_line_large(block, temp, 9);
- dct_line_large(block, temp, 10);
- dct_line_large(block, temp, 11);
- dct_line_large(block, temp, 12);
- dct_line_large(block, temp, 13);
- dct_line_large(block, temp, 14);
- dct_line_large(block, temp, 15);
- dct_line_large(block, temp, 16);
- dct_line_large(block, temp, 17);
- dct_line_large(block, temp, 18);
- dct_line_large(block, temp, 19);
- dct_line_large(block, temp, 20);
- dct_line_large(block, temp, 21);
- dct_line_large(block, temp, 22);
- dct_line_large(block, temp, 23);
- dct_line_large(block, temp, 24);
- dct_line_large(block, temp, 25);
- dct_line_large(block, temp, 26);
- dct_line_large(block, temp, 27);
- dct_line_large(block, temp, 28);
- dct_line_large(block, temp, 29);
- dct_line_large(block, temp, 30);
- dct_line_large(block, temp, 31);
- dct_column_large(temp, cpatch, 0);
- dct_column_large(temp, cpatch, 1);
- dct_column_large(temp, cpatch, 2);
- dct_column_large(temp, cpatch, 3);
- dct_column_large(temp, cpatch, 4);
- dct_column_large(temp, cpatch, 5);
- dct_column_large(temp, cpatch, 6);
- dct_column_large(temp, cpatch, 7);
- dct_column_large(temp, cpatch, 8);
- dct_column_large(temp, cpatch, 9);
- dct_column_large(temp, cpatch, 10);
- dct_column_large(temp, cpatch, 11);
- dct_column_large(temp, cpatch, 12);
- dct_column_large(temp, cpatch, 13);
- dct_column_large(temp, cpatch, 14);
- dct_column_large(temp, cpatch, 15);
- dct_column_large(temp, cpatch, 16);
- dct_column_large(temp, cpatch, 17);
- dct_column_large(temp, cpatch, 18);
- dct_column_large(temp, cpatch, 19);
- dct_column_large(temp, cpatch, 20);
- dct_column_large(temp, cpatch, 21);
- dct_column_large(temp, cpatch, 22);
- dct_column_large(temp, cpatch, 23);
- dct_column_large(temp, cpatch, 24);
- dct_column_large(temp, cpatch, 25);
- dct_column_large(temp, cpatch, 26);
- dct_column_large(temp, cpatch, 27);
- dct_column_large(temp, cpatch, 28);
- dct_column_large(temp, cpatch, 29);
- dct_column_large(temp, cpatch, 30);
- dct_column_large(temp, cpatch, 31);
- }
- void compress_patch(F32* patch, S32* cpatch, LLPatchHeader* php, S32 prequant)
- {
- PCGD* pcp = &gPatchCompressGlobalData;
- S32 stride = pcp->patch_stride;
- S32 size = pcp->patch_size;
- F32 block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock;
- F32* tpatch;
- S32 wordsize = prequant;
- F32 oozrange = 1.f / php->range;
- F32 dc = php->dc_offset;
- S32 range = 1 << prequant;
- F32 premult = oozrange*range;
- F32 sub = (F32)(1 << (prequant - 1)) + dc * premult;
- php->quant_wbits = wordsize - 2;
- php->quant_wbits |= (prequant - 2) << 4;
- for (S32 j = 0; j < size; ++j)
- {
- tblock = block + j * size;
- tpatch = patch + j * stride;
- for (S32 i = 0; i < size; ++i)
- {
- *(tblock++) = *(tpatch++)*premult - sub;
- }
- }
- if (size == 16)
- {
- dct_patch(block, cpatch);
- }
- else
- {
- dct_patch_large(block, cpatch);
- }
- }
- void get_patch_group_header(LLGroupHeader *gopp)
- {
- PCGD* pcp = &gPatchCompressGlobalData;
- gopp->stride = pcp->patch_stride;
- gopp->patch_size = pcp->patch_size;
- gopp->layer_type = pcp->layer_type;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // Formerly in patch_idct.cpp
- ///////////////////////////////////////////////////////////////////////////////
- LLGroupHeader* gGOPP;
- void set_group_of_patch_header(LLGroupHeader* gopp)
- {
- gGOPP = gopp;
- }
- F32 gPatchDequantizeTable[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- void build_patch_dequantize_table(S32 size)
- {
- for (S32 j = 0; j < size; ++j)
- {
- for (S32 i = 0; i < size; ++i)
- {
- gPatchDequantizeTable[j * size + i] = (1.f + 2.f * (i + j));
- }
- }
- }
- S32 gCurrentDeSize = 0;
- F32 gPatchICosines[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- void setup_patch_icosines(S32 size)
- {
- F32 oosob = F_PI * 0.5f / size;
- for (S32 u = 0; u < size; ++u)
- {
- for (S32 n = 0; n < size; ++n)
- {
- gPatchICosines[u * size + n] = cosf((2.f * n + 1.f) * u * oosob);
- }
- }
- }
- S32 gDeCopyMatrix[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- void build_decopy_matrix(S32 size)
- {
- bool b_diag = false;
- bool b_right = true;
- S32 i = 0;
- S32 j = 0;
- S32 count = 0;
- while (i < size && j < size)
- {
- gDeCopyMatrix[j * size + i] = count++;
- if (!b_diag)
- {
- if (b_right)
- {
- if (i < size - 1)
- {
- ++i;
- }
- else
- {
- ++j;
- }
- b_right = false;
- b_diag = true;
- }
- else
- {
- if (j < size - 1)
- {
- ++j;
- }
- else
- {
- ++i;
- }
- b_right = true;
- b_diag = true;
- }
- }
- else
- {
- if (b_right)
- {
- ++i;
- --j;
- if (i == size - 1 || j == 0)
- {
- b_diag = false;
- }
- }
- else
- {
- --i;
- ++j;
- if (i == 0 || j == size - 1)
- {
- b_diag = false;
- }
- }
- }
- }
- }
- void init_patch_decompressor(S32 size)
- {
- if (size != gCurrentDeSize)
- {
- gCurrentDeSize = size;
- build_patch_dequantize_table(size);
- setup_patch_icosines(size);
- build_decopy_matrix(size);
- }
- }
- LL_INLINE void idct_line(F32* linein, F32* lineout, S32 line)
- {
- F32 total;
- F32* pcp = gPatchICosines;
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- F32 oosob = 2.f / 16.f;
- S32 line_size = line * NORMAL_PATCH_SIZE;
- F32* tlinein;
- F32* tpcp;
- for (S32 n = 0; n < NORMAL_PATCH_SIZE; ++n)
- {
- tpcp = pcp + n;
- tlinein = linein + line_size;
- total = OO_SQRT2 * (*(tlinein++));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein) * (*(tpcp += NORMAL_PATCH_SIZE));
- *(lineout + line_size + n) = total * oosob;
- }
- #else
- F32 oosob = 2.f / size;
- S32 size = gGOPP->patch_size;
- S32 line_size = line * size;
- for (S32 n = 0; n < size; ++n)
- {
- total = OO_SQRT2*linein[line_size];
- for (S32 u = 1; u < size; ++u)
- {
- total += linein[line_size + u] * pcp[u * size + n];
- }
- lineout[line_size + n] = total * oosob;
- }
- #endif
- }
- LL_INLINE void idct_line_large_slow(F32* linein, F32* lineout, S32 line)
- {
- F32 total;
- F32* pcp = gPatchICosines;
- F32 oosob = 2.f / 32.f;
- S32 line_size = line * LARGE_PATCH_SIZE;
- F32* tlinein;
- F32* tpcp;
- for (S32 n = 0; n < LARGE_PATCH_SIZE; ++n)
- {
- tpcp = pcp + n;
- tlinein = linein + line_size;
- total = OO_SQRT2 * (*(tlinein++));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein)*(*(tpcp += LARGE_PATCH_SIZE));
- *(lineout + line_size + n) = total * oosob;
- }
- }
- // Nota Bene: assumes that coefficients beyond 128 are 0 !
- void idct_line_large(F32* linein, F32* lineout, S32 line)
- {
- F32 total;
- F32 *pcp = gPatchICosines;
- F32 oosob = 2.f / 32.f;
- S32 line_size = line*LARGE_PATCH_SIZE;
- F32* tlinein;
- F32* tpcp;
- F32* baselinein = linein + line_size;
- F32* baselineout = lineout + line_size;
- for (S32 n = 0; n < LARGE_PATCH_SIZE; ++n)
- {
- tpcp = pcp++;
- tlinein = baselinein;
- total = OO_SQRT2 * (*(tlinein++));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein++) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein) * (*(tpcp));
- *baselineout++ = total * oosob;
- }
- }
- LL_INLINE void idct_column(F32* linein, F32* lineout, S32 column)
- {
- F32 total;
- F32 *pcp = gPatchICosines;
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- F32* tlinein;
- F32* tpcp;
- for (S32 n = 0; n < NORMAL_PATCH_SIZE; ++n)
- {
- tpcp = pcp + n;
- tlinein = linein + column;
- total = OO_SQRT2*(*tlinein);
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- total += *(tlinein += NORMAL_PATCH_SIZE) * (*(tpcp += NORMAL_PATCH_SIZE));
- *(lineout + (n<<4) + column) = total;
- }
- #else
- S32 size = gGOPP->patch_size;
- S32 u;
- S32 u_size;
- for (n = 0; n < size; n++)
- {
- total = OO_SQRT2*linein[column];
- for (u = 1; u < size; u++)
- {
- u_size = u*size;
- total += linein[u_size + column]*pcp[u_size+n];
- }
- lineout[size*n + column] = total;
- }
- #endif
- }
- LL_INLINE void idct_column_large_slow(F32* linein, F32* lineout, S32 column)
- {
- F32 total;
- F32* pcp = gPatchICosines;
- F32* tlinein;
- F32* tpcp;
- for (S32 n = 0; n < LARGE_PATCH_SIZE; ++n)
- {
- tpcp = pcp + n;
- tlinein = linein + column;
- total = OO_SQRT2 * (*tlinein);
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- *(lineout + (n << 5) + column) = total;
- }
- }
- // Nota Bene: assumes that coefficients beyond 128 are 0!
- void idct_column_large(F32* linein, F32* lineout, S32 column)
- {
- F32 total;
- F32* pcp = gPatchICosines;
- F32* tlinein;
- F32* tpcp;
- F32* baselinein = linein + column;
- F32* baselineout = lineout + column;
- for (S32 n = 0; n < LARGE_PATCH_SIZE; ++n)
- {
- tpcp = pcp++;
- tlinein = baselinein;
- total = OO_SQRT2 * (*tlinein);
- for (S32 m = 1; m < NORMAL_PATCH_SIZE; ++m)
- {
- total += *(tlinein += LARGE_PATCH_SIZE) * (*(tpcp += LARGE_PATCH_SIZE));
- }
- *(baselineout + (n << 5)) = total;
- }
- }
- LL_INLINE void idct_patch(F32* block)
- {
- F32 temp[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- #ifdef _PATCH_SIZE_16_AND_32_ONLY
- idct_column(block, temp, 0);
- idct_column(block, temp, 1);
- idct_column(block, temp, 2);
- idct_column(block, temp, 3);
- idct_column(block, temp, 4);
- idct_column(block, temp, 5);
- idct_column(block, temp, 6);
- idct_column(block, temp, 7);
- idct_column(block, temp, 8);
- idct_column(block, temp, 9);
- idct_column(block, temp, 10);
- idct_column(block, temp, 11);
- idct_column(block, temp, 12);
- idct_column(block, temp, 13);
- idct_column(block, temp, 14);
- idct_column(block, temp, 15);
- idct_line(temp, block, 0);
- idct_line(temp, block, 1);
- idct_line(temp, block, 2);
- idct_line(temp, block, 3);
- idct_line(temp, block, 4);
- idct_line(temp, block, 5);
- idct_line(temp, block, 6);
- idct_line(temp, block, 7);
- idct_line(temp, block, 8);
- idct_line(temp, block, 9);
- idct_line(temp, block, 10);
- idct_line(temp, block, 11);
- idct_line(temp, block, 12);
- idct_line(temp, block, 13);
- idct_line(temp, block, 14);
- idct_line(temp, block, 15);
- #else
- S32 size = gGOPP->patch_size;
- for (S32 i = 0; i < size; ++i)
- {
- idct_column(block, temp, i);
- }
- for (S32 i = 0; i < size; ++i)
- {
- idct_line(temp, block, i);
- }
- #endif
- }
- LL_INLINE void idct_patch_large(F32* block)
- {
- F32 temp[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- idct_column_large_slow(block, temp, 0);
- idct_column_large_slow(block, temp, 1);
- idct_column_large_slow(block, temp, 2);
- idct_column_large_slow(block, temp, 3);
- idct_column_large_slow(block, temp, 4);
- idct_column_large_slow(block, temp, 5);
- idct_column_large_slow(block, temp, 6);
- idct_column_large_slow(block, temp, 7);
- idct_column_large_slow(block, temp, 8);
- idct_column_large_slow(block, temp, 9);
- idct_column_large_slow(block, temp, 10);
- idct_column_large_slow(block, temp, 11);
- idct_column_large_slow(block, temp, 12);
- idct_column_large_slow(block, temp, 13);
- idct_column_large_slow(block, temp, 14);
- idct_column_large_slow(block, temp, 15);
- idct_column_large_slow(block, temp, 16);
- idct_column_large_slow(block, temp, 17);
- idct_column_large_slow(block, temp, 18);
- idct_column_large_slow(block, temp, 19);
- idct_column_large_slow(block, temp, 20);
- idct_column_large_slow(block, temp, 21);
- idct_column_large_slow(block, temp, 22);
- idct_column_large_slow(block, temp, 23);
- idct_column_large_slow(block, temp, 24);
- idct_column_large_slow(block, temp, 25);
- idct_column_large_slow(block, temp, 26);
- idct_column_large_slow(block, temp, 27);
- idct_column_large_slow(block, temp, 28);
- idct_column_large_slow(block, temp, 29);
- idct_column_large_slow(block, temp, 30);
- idct_column_large_slow(block, temp, 31);
- idct_line_large_slow(temp, block, 0);
- idct_line_large_slow(temp, block, 1);
- idct_line_large_slow(temp, block, 2);
- idct_line_large_slow(temp, block, 3);
- idct_line_large_slow(temp, block, 4);
- idct_line_large_slow(temp, block, 5);
- idct_line_large_slow(temp, block, 6);
- idct_line_large_slow(temp, block, 7);
- idct_line_large_slow(temp, block, 8);
- idct_line_large_slow(temp, block, 9);
- idct_line_large_slow(temp, block, 10);
- idct_line_large_slow(temp, block, 11);
- idct_line_large_slow(temp, block, 12);
- idct_line_large_slow(temp, block, 13);
- idct_line_large_slow(temp, block, 14);
- idct_line_large_slow(temp, block, 15);
- idct_line_large_slow(temp, block, 16);
- idct_line_large_slow(temp, block, 17);
- idct_line_large_slow(temp, block, 18);
- idct_line_large_slow(temp, block, 19);
- idct_line_large_slow(temp, block, 20);
- idct_line_large_slow(temp, block, 21);
- idct_line_large_slow(temp, block, 22);
- idct_line_large_slow(temp, block, 23);
- idct_line_large_slow(temp, block, 24);
- idct_line_large_slow(temp, block, 25);
- idct_line_large_slow(temp, block, 26);
- idct_line_large_slow(temp, block, 27);
- idct_line_large_slow(temp, block, 28);
- idct_line_large_slow(temp, block, 29);
- idct_line_large_slow(temp, block, 30);
- idct_line_large_slow(temp, block, 31);
- }
- S32 gDitherNoise = 128;
- void decompress_patch(F32* patch, S32* cpatch, LLPatchHeader* ph)
- {
- F32 block[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- F32* tblock = block;
- F32* tpatch;
- LLGroupHeader* gopp = gGOPP;
- S32 size = gopp->patch_size;
- F32 range = ph->range;
- S32 prequant = (ph->quant_wbits >> 4) + 2;
- S32 quantize = 1<<prequant;
- F32 hmin = ph->dc_offset;
- S32 stride = gopp->stride;
- F32 ooq = 1.f / (F32)quantize;
- F32* dq = gPatchDequantizeTable;
- S32* decopy_matrix = gDeCopyMatrix;
- F32 mult = ooq * range;
- F32 addval = mult * (F32)(1 << (prequant - 1)) + hmin;
- for (S32 i = 0; i < size*size; ++i)
- {
- *(tblock++) = *(cpatch + *(decopy_matrix++)) * (*dq++);
- }
- if (size == 16)
- {
- idct_patch(block);
- }
- else
- {
- idct_patch_large(block);
- }
- for (S32 j = 0; j < size; ++j)
- {
- tpatch = patch + j * stride;
- tblock = block + j * size;
- for (S32 i = 0; i < size; ++i)
- {
- *(tpatch++) = *(tblock++) * mult + addval;
- }
- }
- }
- void decompress_patchv(LLVector3* v, S32* cpatch, LLPatchHeader* ph)
- {
- F32 block[LARGE_PATCH_SIZE * LARGE_PATCH_SIZE];
- F32* tblock = block;
- LLVector3* tvec;
- LLGroupHeader* gopp = gGOPP;
- S32 size = gopp->patch_size;
- F32 range = ph->range;
- S32 prequant = (ph->quant_wbits >> 4) + 2;
- S32 quantize = 1 << prequant;
- F32 hmin = ph->dc_offset;
- S32 stride = gopp->stride;
- F32 ooq = 1.f / (F32)quantize;
- F32* dq = gPatchDequantizeTable;
- S32* decopy_matrix = gDeCopyMatrix;
- F32 mult = ooq * range;
- F32 addval = mult*(F32)(1 << (prequant - 1)) + hmin;
- for (S32 i = 0; i < size * size; ++i)
- {
- *(tblock++) = *(cpatch + *(decopy_matrix++)) * (*dq++);
- }
- if (size == 16)
- {
- idct_patch(block);
- }
- else
- {
- idct_patch_large(block);
- }
- for (S32 j = 0; j < size; ++j)
- {
- tvec = v + j * stride;
- tblock = block + j*size;
- for (S32 i = 0; i < size; ++i)
- {
- (*tvec++).mV[VZ] = *(tblock++) * mult + addval;
- }
- }
- }
|