PageRenderTime 32ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/patch_idct.cpp

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