patch_idct.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:18k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file patch_idct.cpp
  3.  * @brief IDCT patch.
  4.  *
  5.  * $LicenseInfo:firstyear=2000&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2000-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "linden_common.h"
  33. #include "llmath.h"
  34. //#include "vmath.h"
  35. #include "v3math.h"
  36. #include "patch_dct.h"
  37. LLGroupHeader *gGOPP;
  38. void set_group_of_patch_header(LLGroupHeader *gopp)
  39. {
  40. gGOPP = gopp;
  41. }
  42. F32 gPatchDequantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  43. void build_patch_dequantize_table(S32 size)
  44. {
  45. S32 i, j;
  46. for (j = 0; j < size; j++)
  47. {
  48. for (i = 0; i < size; i++)
  49. {
  50. gPatchDequantizeTable[j*size + i] = (1.f + 2.f*(i+j));
  51. }
  52. }
  53. }
  54. S32 gCurrentDeSize = 0;
  55. F32 gPatchICosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  56. void setup_patch_icosines(S32 size)
  57. {
  58. S32 n, u;
  59. F32 oosob = F_PI*0.5f/size;
  60. for (u = 0; u < size; u++)
  61. {
  62. for (n = 0; n < size; n++)
  63. {
  64. gPatchICosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
  65. }
  66. }
  67. }
  68. S32 gDeCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  69. void build_decopy_matrix(S32 size)
  70. {
  71. S32 i, j, count;
  72. BOOL b_diag = FALSE;
  73. BOOL b_right = TRUE;
  74. i = 0;
  75. j = 0;
  76. count = 0;
  77. while (  (i < size)
  78.    &&(j < size))
  79. {
  80. gDeCopyMatrix[j*size + i] = count;
  81. count++;
  82. if (!b_diag)
  83. {
  84. if (b_right)
  85. {
  86. if (i < size - 1)
  87. i++;
  88. else
  89. j++;
  90. b_right = FALSE;
  91. b_diag = TRUE;
  92. }
  93. else
  94. {
  95. if (j < size - 1)
  96. j++;
  97. else
  98. i++;
  99. b_right = TRUE;
  100. b_diag = TRUE;
  101. }
  102. }
  103. else
  104. {
  105. if (b_right)
  106. {
  107. i++;
  108. j--;
  109. if (  (i == size - 1)
  110. ||(j == 0))
  111. {
  112. b_diag = FALSE;
  113. }
  114. }
  115. else
  116. {
  117. i--;
  118. j++;
  119. if (  (i == 0)
  120. ||(j == size - 1))
  121. {
  122. b_diag = FALSE;
  123. }
  124. }
  125. }
  126. }
  127. }
  128. void init_patch_decompressor(S32 size)
  129. {
  130. if (size != gCurrentDeSize)
  131. {
  132. gCurrentDeSize = size;
  133. build_patch_dequantize_table(size);
  134. setup_patch_icosines(size);
  135. build_decopy_matrix(size);
  136. }
  137. }
  138. inline void idct_line(F32 *linein, F32 *lineout, S32 line)
  139. {
  140. S32 n;
  141. F32 total;
  142. F32 *pcp = gPatchICosines;
  143. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  144. F32 oosob = 2.f/16.f;
  145. S32 line_size = line*NORMAL_PATCH_SIZE;
  146. F32 *tlinein, *tpcp;
  147. for (n = 0; n < NORMAL_PATCH_SIZE; n++)
  148. {
  149. tpcp = pcp + n;
  150. tlinein = linein + line_size;
  151. total = OO_SQRT2*(*(tlinein++));
  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. total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
  162. total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
  163. total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
  164. total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
  165. total += *(tlinein++)*(*(tpcp += NORMAL_PATCH_SIZE));
  166. total += *(tlinein)*(*(tpcp += NORMAL_PATCH_SIZE));
  167. *(lineout + line_size + n) = total*oosob;
  168. }
  169. #else
  170. F32 oosob = 2.f/size;
  171. S32 size = gGOPP->patch_size;
  172. S32 line_size = line*size;
  173. S32 u;
  174. for (n = 0; n < size; n++)
  175. {
  176. total = OO_SQRT2*linein[line_size];
  177. for (u = 1; u < size; u++)
  178. {
  179. total += linein[line_size + u]*pcp[u*size+n];
  180. }
  181. lineout[line_size + n] = total*oosob;
  182. }
  183. #endif
  184. }
  185. inline void idct_line_large_slow(F32 *linein, F32 *lineout, S32 line)
  186. {
  187. S32 n;
  188. F32 total;
  189. F32 *pcp = gPatchICosines;
  190. F32 oosob = 2.f/32.f;
  191. S32 line_size = line*LARGE_PATCH_SIZE;
  192. F32 *tlinein, *tpcp;
  193. for (n = 0; n < LARGE_PATCH_SIZE; n++)
  194. {
  195. tpcp = pcp + n;
  196. tlinein = linein + line_size;
  197. total = OO_SQRT2*(*(tlinein++));
  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. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  224. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  225. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  226. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  227. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  228. total += *(tlinein)*(*(tpcp += LARGE_PATCH_SIZE));
  229. *(lineout + line_size + n) = total*oosob;
  230. }
  231. }
  232. // Nota Bene: assumes that coefficients beyond 128 are 0!
  233. void idct_line_large(F32 *linein, F32 *lineout, S32 line)
  234. {
  235. S32 n;
  236. F32 total;
  237. F32 *pcp = gPatchICosines;
  238. F32 oosob = 2.f/32.f;
  239. S32 line_size = line*LARGE_PATCH_SIZE;
  240. F32 *tlinein, *tpcp;
  241. F32 *baselinein = linein + line_size;
  242. F32 *baselineout = lineout + line_size;
  243. for (n = 0; n < LARGE_PATCH_SIZE; n++)
  244. {
  245. tpcp = pcp++;
  246. tlinein = baselinein;
  247. total = OO_SQRT2*(*(tlinein++));
  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 += LARGE_PATCH_SIZE));
  257. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  258. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  259. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  260. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  261. total += *(tlinein++)*(*(tpcp += LARGE_PATCH_SIZE));
  262. total += *(tlinein)*(*(tpcp));
  263. *baselineout++ = total*oosob;
  264. }
  265. }
  266. inline void idct_column(F32 *linein, F32 *lineout, S32 column)
  267. {
  268. S32 n;
  269. F32 total;
  270. F32 *pcp = gPatchICosines;
  271. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  272. F32 *tlinein, *tpcp;
  273. for (n = 0; n < NORMAL_PATCH_SIZE; n++)
  274. {
  275. tpcp = pcp + n;
  276. tlinein = linein + column;
  277. total = OO_SQRT2*(*tlinein);
  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. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  288. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  289. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  290. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  291. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  292. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp += NORMAL_PATCH_SIZE));
  293. *(lineout + (n<<4) + column) = total;
  294. }
  295. #else
  296. S32 size = gGOPP->patch_size;
  297. S32 u;
  298. S32 u_size;
  299. for (n = 0; n < size; n++)
  300. {
  301. total = OO_SQRT2*linein[column];
  302. for (u = 1; u < size; u++)
  303. {
  304. u_size = u*size;
  305. total += linein[u_size + column]*pcp[u_size+n];
  306. }
  307. lineout[size*n + column] = total;
  308. }
  309. #endif
  310. }
  311. inline void idct_column_large_slow(F32 *linein, F32 *lineout, S32 column)
  312. {
  313. S32 n;
  314. F32 total;
  315. F32 *pcp = gPatchICosines;
  316. F32 *tlinein, *tpcp;
  317. for (n = 0; n < LARGE_PATCH_SIZE; n++)
  318. {
  319. tpcp = pcp + n;
  320. tlinein = linein + column;
  321. total = OO_SQRT2*(*tlinein);
  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. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  348. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  349. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  350. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  351. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  352. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  353. *(lineout + (n<<5) + column) = total;
  354. }
  355. }
  356. // Nota Bene: assumes that coefficients beyond 128 are 0!
  357. void idct_column_large(F32 *linein, F32 *lineout, S32 column)
  358. {
  359. S32 n, m;
  360. F32 total;
  361. F32 *pcp = gPatchICosines;
  362. F32 *tlinein, *tpcp;
  363. F32 *baselinein = linein + column;
  364. F32 *baselineout = lineout + column;
  365. for (n = 0; n < LARGE_PATCH_SIZE; n++)
  366. {
  367. tpcp = pcp++;
  368. tlinein = baselinein;
  369. total = OO_SQRT2*(*tlinein);
  370. for (m = 1; m < NORMAL_PATCH_SIZE; m++)
  371. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp += LARGE_PATCH_SIZE));
  372. *(baselineout + (n<<5)) = total;
  373. }
  374. }
  375. inline void idct_patch(F32 *block)
  376. {
  377. F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  378. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  379. idct_column(block, temp, 0);
  380. idct_column(block, temp, 1);
  381. idct_column(block, temp, 2);
  382. idct_column(block, temp, 3);
  383. idct_column(block, temp, 4);
  384. idct_column(block, temp, 5);
  385. idct_column(block, temp, 6);
  386. idct_column(block, temp, 7);
  387. idct_column(block, temp, 8);
  388. idct_column(block, temp, 9);
  389. idct_column(block, temp, 10);
  390. idct_column(block, temp, 11);
  391. idct_column(block, temp, 12);
  392. idct_column(block, temp, 13);
  393. idct_column(block, temp, 14);
  394. idct_column(block, temp, 15);
  395. idct_line(temp, block, 0);
  396. idct_line(temp, block, 1);
  397. idct_line(temp, block, 2);
  398. idct_line(temp, block, 3);
  399. idct_line(temp, block, 4);
  400. idct_line(temp, block, 5);
  401. idct_line(temp, block, 6);
  402. idct_line(temp, block, 7);
  403. idct_line(temp, block, 8);
  404. idct_line(temp, block, 9);
  405. idct_line(temp, block, 10);
  406. idct_line(temp, block, 11);
  407. idct_line(temp, block, 12);
  408. idct_line(temp, block, 13);
  409. idct_line(temp, block, 14);
  410. idct_line(temp, block, 15);
  411. #else
  412. S32 i;
  413. S32 size = gGOPP->patch_size;
  414. for (i = 0; i < size; i++)
  415. {
  416. idct_column(block, temp, i);
  417. }
  418. for (i = 0; i < size; i++)
  419. {
  420. idct_line(temp, block, i);
  421. }
  422. #endif
  423. }
  424. inline void idct_patch_large(F32 *block)
  425. {
  426. F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  427. idct_column_large_slow(block, temp, 0);
  428. idct_column_large_slow(block, temp, 1);
  429. idct_column_large_slow(block, temp, 2);
  430. idct_column_large_slow(block, temp, 3);
  431. idct_column_large_slow(block, temp, 4);
  432. idct_column_large_slow(block, temp, 5);
  433. idct_column_large_slow(block, temp, 6);
  434. idct_column_large_slow(block, temp, 7);
  435. idct_column_large_slow(block, temp, 8);
  436. idct_column_large_slow(block, temp, 9);
  437. idct_column_large_slow(block, temp, 10);
  438. idct_column_large_slow(block, temp, 11);
  439. idct_column_large_slow(block, temp, 12);
  440. idct_column_large_slow(block, temp, 13);
  441. idct_column_large_slow(block, temp, 14);
  442. idct_column_large_slow(block, temp, 15);
  443. idct_column_large_slow(block, temp, 16);
  444. idct_column_large_slow(block, temp, 17);
  445. idct_column_large_slow(block, temp, 18);
  446. idct_column_large_slow(block, temp, 19);
  447. idct_column_large_slow(block, temp, 20);
  448. idct_column_large_slow(block, temp, 21);
  449. idct_column_large_slow(block, temp, 22);
  450. idct_column_large_slow(block, temp, 23);
  451. idct_column_large_slow(block, temp, 24);
  452. idct_column_large_slow(block, temp, 25);
  453. idct_column_large_slow(block, temp, 26);
  454. idct_column_large_slow(block, temp, 27);
  455. idct_column_large_slow(block, temp, 28);
  456. idct_column_large_slow(block, temp, 29);
  457. idct_column_large_slow(block, temp, 30);
  458. idct_column_large_slow(block, temp, 31);
  459. idct_line_large_slow(temp, block, 0);
  460. idct_line_large_slow(temp, block, 1);
  461. idct_line_large_slow(temp, block, 2);
  462. idct_line_large_slow(temp, block, 3);
  463. idct_line_large_slow(temp, block, 4);
  464. idct_line_large_slow(temp, block, 5);
  465. idct_line_large_slow(temp, block, 6);
  466. idct_line_large_slow(temp, block, 7);
  467. idct_line_large_slow(temp, block, 8);
  468. idct_line_large_slow(temp, block, 9);
  469. idct_line_large_slow(temp, block, 10);
  470. idct_line_large_slow(temp, block, 11);
  471. idct_line_large_slow(temp, block, 12);
  472. idct_line_large_slow(temp, block, 13);
  473. idct_line_large_slow(temp, block, 14);
  474. idct_line_large_slow(temp, block, 15);
  475. idct_line_large_slow(temp, block, 16);
  476. idct_line_large_slow(temp, block, 17);
  477. idct_line_large_slow(temp, block, 18);
  478. idct_line_large_slow(temp, block, 19);
  479. idct_line_large_slow(temp, block, 20);
  480. idct_line_large_slow(temp, block, 21);
  481. idct_line_large_slow(temp, block, 22);
  482. idct_line_large_slow(temp, block, 23);
  483. idct_line_large_slow(temp, block, 24);
  484. idct_line_large_slow(temp, block, 25);
  485. idct_line_large_slow(temp, block, 26);
  486. idct_line_large_slow(temp, block, 27);
  487. idct_line_large_slow(temp, block, 28);
  488. idct_line_large_slow(temp, block, 29);
  489. idct_line_large_slow(temp, block, 30);
  490. idct_line_large_slow(temp, block, 31);
  491. }
  492. S32 gDitherNoise = 128;
  493. void decompress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *ph)
  494. {
  495. S32 i, j;
  496. F32 block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock = block;
  497. F32 *tpatch;
  498. LLGroupHeader *gopp = gGOPP;
  499. S32 size = gopp->patch_size;
  500. F32 range = ph->range;
  501. S32 prequant = (ph->quant_wbits >> 4) + 2;
  502. S32 quantize = 1<<prequant;
  503. F32 hmin = ph->dc_offset;
  504. S32 stride = gopp->stride;
  505. F32 ooq = 1.f/(F32)quantize;
  506. F32     *dq = gPatchDequantizeTable;
  507. S32 *decopy_matrix = gDeCopyMatrix;
  508. F32 mult = ooq*range;
  509. F32 addval = mult*(F32)(1<<(prequant - 1))+hmin;
  510. for (i = 0; i < size*size; i++)
  511. {
  512. *(tblock++) = *(cpatch + *(decopy_matrix++))*(*dq++);
  513. }
  514. if (size == 16)
  515. {
  516. idct_patch(block);
  517. }
  518. else
  519. {
  520. idct_patch_large(block);
  521. }
  522. for (j = 0; j < size; j++)
  523. {
  524. tpatch = patch + j*stride;
  525. tblock = block + j*size;
  526. for (i = 0; i < size; i++)
  527. {
  528. *(tpatch++) = *(tblock++)*mult+addval;
  529. }
  530. }
  531. }
  532. void decompress_patchv(LLVector3 *v, S32 *cpatch, LLPatchHeader *ph)
  533. {
  534. S32 i, j;
  535. F32 block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock = block;
  536. LLVector3 *tvec;
  537. LLGroupHeader *gopp = gGOPP;
  538. S32 size = gopp->patch_size;
  539. F32 range = ph->range;
  540. S32 prequant = (ph->quant_wbits >> 4) + 2;
  541. S32 quantize = 1<<prequant;
  542. F32 hmin = ph->dc_offset;
  543. S32 stride = gopp->stride;
  544. F32 ooq = 1.f/(F32)quantize;
  545. F32     *dq = gPatchDequantizeTable;
  546. S32 *decopy_matrix = gDeCopyMatrix;
  547. F32 mult = ooq*range;
  548. F32 addval = mult*(F32)(1<<(prequant - 1))+hmin;
  549. // BOOL b_diag = FALSE;
  550. // BOOL b_right = TRUE;
  551. for (i = 0; i < size*size; i++)
  552. {
  553. *(tblock++) = *(cpatch + *(decopy_matrix++))*(*dq++);
  554. }
  555. if (size == 16)
  556. idct_patch(block);
  557. else
  558. idct_patch_large(block);
  559. for (j = 0; j < size; j++)
  560. {
  561. tvec = v + j*stride;
  562. tblock = block + j*size;
  563. for (i = 0; i < size; i++)
  564. {
  565. (*tvec++).mV[VZ] = *(tblock++)*mult+addval;
  566. }
  567. }
  568. }