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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file patch_dct.cpp
  3.  * @brief DCT 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. typedef struct s_patch_compress_global_data
  38. {
  39. S32 patch_size;
  40. S32 patch_stride;
  41. U32 charptr;
  42. S32 layer_type;
  43. } PCGD;
  44. PCGD gPatchCompressGlobalData;
  45. void reset_patch_compressor(void)
  46. {
  47. PCGD *pcp = &gPatchCompressGlobalData;
  48. pcp->charptr = 0;
  49. }
  50. S32 gCurrentSize = 0;
  51. F32 gPatchQuantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  52. void build_patch_quantize_table(S32 size)
  53. {
  54. S32 i, j;
  55. for (j = 0; j < size; j++)
  56. {
  57. for (i = 0; i < size; i++)
  58. {
  59. gPatchQuantizeTable[j*size + i] = 1.f/(1.f + 2.f*(i+j));
  60. }
  61. }
  62. }
  63. F32 gPatchCosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  64. void setup_patch_cosines(S32 size)
  65. {
  66. S32 n, u;
  67. F32 oosob = F_PI*0.5f/size;
  68. for (u = 0; u < size; u++)
  69. {
  70. for (n = 0; n < size; n++)
  71. {
  72. gPatchCosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
  73. }
  74. }
  75. }
  76. S32 gCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  77. void build_copy_matrix(S32 size)
  78. {
  79. S32 i, j, count;
  80. BOOL b_diag = FALSE;
  81. BOOL b_right = TRUE;
  82. i = 0;
  83. j = 0;
  84. count = 0;
  85. while (  (i < size)
  86.    &&(j < size))
  87. {
  88. gCopyMatrix[j*size + i] = count;
  89. count++;
  90. if (!b_diag)
  91. {
  92. if (b_right)
  93. {
  94. if (i < size - 1)
  95. i++;
  96. else
  97. j++;
  98. b_right = FALSE;
  99. b_diag = TRUE;
  100. }
  101. else
  102. {
  103. if (j < size - 1)
  104. j++;
  105. else
  106. i++;
  107. b_right = TRUE;
  108. b_diag = TRUE;
  109. }
  110. }
  111. else
  112. {
  113. if (b_right)
  114. {
  115. i++;
  116. j--;
  117. if (  (i == size - 1)
  118. ||(j == 0))
  119. {
  120. b_diag = FALSE;
  121. }
  122. }
  123. else
  124. {
  125. i--;
  126. j++;
  127. if (  (i == 0)
  128. ||(j == size - 1))
  129. {
  130. b_diag = FALSE;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. void init_patch_compressor(S32 patch_size, S32 patch_stride, S32 layer_type)
  137. {
  138. PCGD *pcp = &gPatchCompressGlobalData;
  139. pcp->charptr = 0;
  140. pcp->patch_size = patch_size;
  141. pcp->patch_stride = patch_stride;
  142. pcp->layer_type = layer_type;
  143. if (patch_size != gCurrentSize)
  144. {
  145. gCurrentSize = patch_size;
  146. build_patch_quantize_table(patch_size);
  147. setup_patch_cosines(patch_size);
  148. build_copy_matrix(patch_size);
  149. }
  150. }
  151. void prescan_patch(F32 *patch, LLPatchHeader *php, F32 &zmax, F32 &zmin)
  152. {
  153. S32 i, j;
  154. PCGD *pcp = &gPatchCompressGlobalData;
  155. S32 stride = pcp->patch_stride;
  156. S32 size = pcp->patch_size;
  157. S32 jstride;
  158. zmax = -99999999.f;
  159. zmin = 99999999.f;
  160. for (j = 0; j < size; j++)
  161. {
  162. jstride = j*stride;
  163. for (i = 0; i < size; i++)
  164. {
  165. if (*(patch + jstride + i) > zmax)
  166. {
  167. zmax = *(patch + jstride + i);
  168. }
  169. if (*(patch + jstride + i) < zmin)
  170. {
  171. zmin = *(patch + jstride + i);
  172. }
  173. }
  174. }
  175. php->dc_offset = zmin;
  176. php->range = (U16) ((zmax - zmin) + 1.f);
  177. }
  178. void dct_line(F32 *linein, F32 *lineout, S32 line)
  179. {
  180. S32 u;
  181. F32 total;
  182. F32 *pcp = gPatchCosines;
  183. S32 line_size = line*NORMAL_PATCH_SIZE;
  184. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  185. F32 *tlinein, *tpcp;
  186. tlinein = linein + line_size;
  187. total = *(tlinein++);
  188. total += *(tlinein++);
  189. total += *(tlinein++);
  190. total += *(tlinein++);
  191. total += *(tlinein++);
  192. total += *(tlinein++);
  193. total += *(tlinein++);
  194. total += *(tlinein++);
  195. total += *(tlinein++);
  196. total += *(tlinein++);
  197. total += *(tlinein++);
  198. total += *(tlinein++);
  199. total += *(tlinein++);
  200. total += *(tlinein++);
  201. total += *(tlinein++);
  202. total += *(tlinein);
  203. *(lineout + line_size) = OO_SQRT2*total;
  204. for (u = 1; u < NORMAL_PATCH_SIZE; u++)
  205. {
  206. tlinein = linein + line_size;
  207. tpcp = pcp + (u<<4);
  208. total = *(tlinein++)*(*(tpcp++));
  209. total += *(tlinein++)*(*(tpcp++));
  210. total += *(tlinein++)*(*(tpcp++));
  211. total += *(tlinein++)*(*(tpcp++));
  212. total += *(tlinein++)*(*(tpcp++));
  213. total += *(tlinein++)*(*(tpcp++));
  214. total += *(tlinein++)*(*(tpcp++));
  215. total += *(tlinein++)*(*(tpcp++));
  216. total += *(tlinein++)*(*(tpcp++));
  217. total += *(tlinein++)*(*(tpcp++));
  218. total += *(tlinein++)*(*(tpcp++));
  219. total += *(tlinein++)*(*(tpcp++));
  220. total += *(tlinein++)*(*(tpcp++));
  221. total += *(tlinein++)*(*(tpcp++));
  222. total += *(tlinein++)*(*(tpcp++));
  223. total += *(tlinein)*(*tpcp);
  224. *(lineout + line_size + u) = total;
  225. }
  226. #else
  227. S32 n;
  228. S32 size = gPatchCompressGlobalData.patch_size;
  229. total = 0.f;
  230. for (n = 0; n < size; n++)
  231. {
  232. total += linein[line_size + n];
  233. }
  234. lineout[line_size] = OO_SQRT2*total;
  235. for (u = 1; u < size; u++)
  236. {
  237. total = 0.f;
  238. for (n = 0; n < size; n++)
  239. {
  240. total += linein[line_size + n]*pcp[u*size+n];
  241. }
  242. lineout[line_size + u] = total;
  243. }
  244. #endif
  245. }
  246. void dct_line_large(F32 *linein, F32 *lineout, S32 line)
  247. {
  248. S32 u;
  249. F32 total;
  250. F32 *pcp = gPatchCosines;
  251. S32 line_size = line*LARGE_PATCH_SIZE;
  252. F32 *tlinein, *tpcp;
  253. tlinein = linein + line_size;
  254. total = *(tlinein++);
  255. total += *(tlinein++);
  256. total += *(tlinein++);
  257. total += *(tlinein++);
  258. total += *(tlinein++);
  259. total += *(tlinein++);
  260. total += *(tlinein++);
  261. total += *(tlinein++);
  262. total += *(tlinein++);
  263. total += *(tlinein++);
  264. total += *(tlinein++);
  265. total += *(tlinein++);
  266. total += *(tlinein++);
  267. total += *(tlinein++);
  268. total += *(tlinein++);
  269. total += *(tlinein++);
  270. total += *(tlinein++);
  271. total += *(tlinein++);
  272. total += *(tlinein++);
  273. total += *(tlinein++);
  274. total += *(tlinein++);
  275. total += *(tlinein++);
  276. total += *(tlinein++);
  277. total += *(tlinein++);
  278. total += *(tlinein++);
  279. total += *(tlinein++);
  280. total += *(tlinein++);
  281. total += *(tlinein++);
  282. total += *(tlinein++);
  283. total += *(tlinein++);
  284. total += *(tlinein++);
  285. total += *(tlinein);
  286. *(lineout + line_size) = OO_SQRT2*total;
  287. for (u = 1; u < LARGE_PATCH_SIZE; u++)
  288. {
  289. tlinein = linein + line_size;
  290. tpcp = pcp + (u<<5);
  291. total = *(tlinein++)*(*(tpcp++));
  292. total += *(tlinein++)*(*(tpcp++));
  293. total += *(tlinein++)*(*(tpcp++));
  294. total += *(tlinein++)*(*(tpcp++));
  295. total += *(tlinein++)*(*(tpcp++));
  296. total += *(tlinein++)*(*(tpcp++));
  297. total += *(tlinein++)*(*(tpcp++));
  298. total += *(tlinein++)*(*(tpcp++));
  299. total += *(tlinein++)*(*(tpcp++));
  300. total += *(tlinein++)*(*(tpcp++));
  301. total += *(tlinein++)*(*(tpcp++));
  302. total += *(tlinein++)*(*(tpcp++));
  303. total += *(tlinein++)*(*(tpcp++));
  304. total += *(tlinein++)*(*(tpcp++));
  305. total += *(tlinein++)*(*(tpcp++));
  306. total += *(tlinein++)*(*(tpcp++));
  307. total += *(tlinein++)*(*(tpcp++));
  308. total += *(tlinein++)*(*(tpcp++));
  309. total += *(tlinein++)*(*(tpcp++));
  310. total += *(tlinein++)*(*(tpcp++));
  311. total += *(tlinein++)*(*(tpcp++));
  312. total += *(tlinein++)*(*(tpcp++));
  313. total += *(tlinein++)*(*(tpcp++));
  314. total += *(tlinein++)*(*(tpcp++));
  315. total += *(tlinein++)*(*(tpcp++));
  316. total += *(tlinein++)*(*(tpcp++));
  317. total += *(tlinein++)*(*(tpcp++));
  318. total += *(tlinein++)*(*(tpcp++));
  319. total += *(tlinein++)*(*(tpcp++));
  320. total += *(tlinein++)*(*(tpcp++));
  321. total += *(tlinein++)*(*(tpcp++));
  322. total += *(tlinein)*(*tpcp);
  323. *(lineout + line_size + u) = total;
  324. }
  325. }
  326. inline void dct_column(F32 *linein, S32 *lineout, S32 column)
  327. {
  328. S32 u;
  329. F32 total;
  330. F32 oosob = 2.f/16.f;
  331. F32 *pcp = gPatchCosines;
  332. S32 *copy_matrix = gCopyMatrix;
  333. F32 *qt = gPatchQuantizeTable;
  334. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  335. F32 *tlinein, *tpcp;
  336. S32 sizeu;
  337. tlinein = linein + column;
  338. total = *(tlinein);
  339. total += *(tlinein += NORMAL_PATCH_SIZE);
  340. total += *(tlinein += NORMAL_PATCH_SIZE);
  341. total += *(tlinein += NORMAL_PATCH_SIZE);
  342. total += *(tlinein += NORMAL_PATCH_SIZE);
  343. total += *(tlinein += NORMAL_PATCH_SIZE);
  344. total += *(tlinein += NORMAL_PATCH_SIZE);
  345. total += *(tlinein += NORMAL_PATCH_SIZE);
  346. total += *(tlinein += NORMAL_PATCH_SIZE);
  347. total += *(tlinein += NORMAL_PATCH_SIZE);
  348. total += *(tlinein += NORMAL_PATCH_SIZE);
  349. total += *(tlinein += NORMAL_PATCH_SIZE);
  350. total += *(tlinein += NORMAL_PATCH_SIZE);
  351. total += *(tlinein += NORMAL_PATCH_SIZE);
  352. total += *(tlinein += NORMAL_PATCH_SIZE);
  353. total += *(tlinein += NORMAL_PATCH_SIZE);
  354. *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
  355. for (u = 1; u < NORMAL_PATCH_SIZE; u++)
  356. {
  357. tlinein = linein + column;
  358. tpcp = pcp + (u<<4);
  359. total = *(tlinein)*(*(tpcp++));
  360. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  361. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  362. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  363. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  364. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  365. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  366. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  367. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  368. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  369. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  370. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  371. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  372. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  373. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  374. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp));
  375. sizeu = NORMAL_PATCH_SIZE*u + column;
  376. *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
  377. }
  378. #else
  379. S32 size = gPatchCompressGlobalData.patch_size;
  380. F32 oosob = 2.f/size;
  381. S32 n;
  382. total = 0.f;
  383. for (n = 0; n < size; n++)
  384. {
  385. total += linein[size*n + column];
  386. }
  387. lineout[copy_matrix[column]] = OO_SQRT2*total*oosob*qt[column];
  388. for (u = 1; u < size; u++)
  389. {
  390. total = 0.f;
  391. for (n = 0; n < size; n++)
  392. {
  393. total += linein[size*n + column]*pcp[u*size+n];
  394. }
  395. lineout[copy_matrix[size*u + column]] = total*oosob*qt[size*u + column];
  396. }
  397. #endif
  398. }
  399. inline void dct_column_large(F32 *linein, S32 *lineout, S32 column)
  400. {
  401. S32 u;
  402. F32 total;
  403. F32 oosob = 2.f/32.f;
  404. F32 *pcp = gPatchCosines;
  405. S32 *copy_matrix = gCopyMatrix;
  406. F32 *qt = gPatchQuantizeTable;
  407. F32 *tlinein, *tpcp;
  408. S32 sizeu;
  409. tlinein = linein + column;
  410. total = *(tlinein);
  411. total += *(tlinein += LARGE_PATCH_SIZE);
  412. total += *(tlinein += LARGE_PATCH_SIZE);
  413. total += *(tlinein += LARGE_PATCH_SIZE);
  414. total += *(tlinein += LARGE_PATCH_SIZE);
  415. total += *(tlinein += LARGE_PATCH_SIZE);
  416. total += *(tlinein += LARGE_PATCH_SIZE);
  417. total += *(tlinein += LARGE_PATCH_SIZE);
  418. total += *(tlinein += LARGE_PATCH_SIZE);
  419. total += *(tlinein += LARGE_PATCH_SIZE);
  420. total += *(tlinein += LARGE_PATCH_SIZE);
  421. total += *(tlinein += LARGE_PATCH_SIZE);
  422. total += *(tlinein += LARGE_PATCH_SIZE);
  423. total += *(tlinein += LARGE_PATCH_SIZE);
  424. total += *(tlinein += LARGE_PATCH_SIZE);
  425. total += *(tlinein += LARGE_PATCH_SIZE);
  426. total += *(tlinein += LARGE_PATCH_SIZE);
  427. total += *(tlinein += LARGE_PATCH_SIZE);
  428. total += *(tlinein += LARGE_PATCH_SIZE);
  429. total += *(tlinein += LARGE_PATCH_SIZE);
  430. total += *(tlinein += LARGE_PATCH_SIZE);
  431. total += *(tlinein += LARGE_PATCH_SIZE);
  432. total += *(tlinein += LARGE_PATCH_SIZE);
  433. total += *(tlinein += LARGE_PATCH_SIZE);
  434. total += *(tlinein += LARGE_PATCH_SIZE);
  435. total += *(tlinein += LARGE_PATCH_SIZE);
  436. total += *(tlinein += LARGE_PATCH_SIZE);
  437. total += *(tlinein += LARGE_PATCH_SIZE);
  438. total += *(tlinein += LARGE_PATCH_SIZE);
  439. total += *(tlinein += LARGE_PATCH_SIZE);
  440. total += *(tlinein += LARGE_PATCH_SIZE);
  441. total += *(tlinein += LARGE_PATCH_SIZE);
  442. *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
  443. for (u = 1; u < LARGE_PATCH_SIZE; u++)
  444. {
  445. tlinein = linein + column;
  446. tpcp = pcp + (u<<5);
  447. total = *(tlinein)*(*(tpcp++));
  448. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  449. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  450. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  451. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  452. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  453. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  454. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  455. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  456. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  457. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  458. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  459. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  460. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  461. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  462. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  463. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  464. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  465. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  466. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  467. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  468. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  469. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  470. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  471. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  472. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  473. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  474. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  475. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  476. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  477. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  478. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp));
  479. sizeu = LARGE_PATCH_SIZE*u + column;
  480. *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
  481. }
  482. }
  483. inline void dct_patch(F32 *block, S32 *cpatch)
  484. {
  485. F32 temp[NORMAL_PATCH_SIZE*NORMAL_PATCH_SIZE];
  486. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  487. dct_line(block, temp, 0);
  488. dct_line(block, temp, 1);
  489. dct_line(block, temp, 2);
  490. dct_line(block, temp, 3);
  491. dct_line(block, temp, 4);
  492. dct_line(block, temp, 5);
  493. dct_line(block, temp, 6);
  494. dct_line(block, temp, 7);
  495. dct_line(block, temp, 8);
  496. dct_line(block, temp, 9);
  497. dct_line(block, temp, 10);
  498. dct_line(block, temp, 11);
  499. dct_line(block, temp, 12);
  500. dct_line(block, temp, 13);
  501. dct_line(block, temp, 14);
  502. dct_line(block, temp, 15);
  503. dct_column(temp, cpatch, 0);
  504. dct_column(temp, cpatch, 1);
  505. dct_column(temp, cpatch, 2);
  506. dct_column(temp, cpatch, 3);
  507. dct_column(temp, cpatch, 4);
  508. dct_column(temp, cpatch, 5);
  509. dct_column(temp, cpatch, 6);
  510. dct_column(temp, cpatch, 7);
  511. dct_column(temp, cpatch, 8);
  512. dct_column(temp, cpatch, 9);
  513. dct_column(temp, cpatch, 10);
  514. dct_column(temp, cpatch, 11);
  515. dct_column(temp, cpatch, 12);
  516. dct_column(temp, cpatch, 13);
  517. dct_column(temp, cpatch, 14);
  518. dct_column(temp, cpatch, 15);
  519. #else
  520. S32 i;
  521. S32 size = gPatchCompressGlobalData.patch_size;
  522. for (i = 0; i < size; i++)
  523. {
  524. dct_line(block, temp, i);
  525. }
  526. for (i = 0; i < size; i++)
  527. {
  528. dct_column(temp, cpatch, i);
  529. }
  530. #endif
  531. }
  532. inline void dct_patch_large(F32 *block, S32 *cpatch)
  533. {
  534. F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  535. dct_line_large(block, temp, 0);
  536. dct_line_large(block, temp, 1);
  537. dct_line_large(block, temp, 2);
  538. dct_line_large(block, temp, 3);
  539. dct_line_large(block, temp, 4);
  540. dct_line_large(block, temp, 5);
  541. dct_line_large(block, temp, 6);
  542. dct_line_large(block, temp, 7);
  543. dct_line_large(block, temp, 8);
  544. dct_line_large(block, temp, 9);
  545. dct_line_large(block, temp, 10);
  546. dct_line_large(block, temp, 11);
  547. dct_line_large(block, temp, 12);
  548. dct_line_large(block, temp, 13);
  549. dct_line_large(block, temp, 14);
  550. dct_line_large(block, temp, 15);
  551. dct_line_large(block, temp, 16);
  552. dct_line_large(block, temp, 17);
  553. dct_line_large(block, temp, 18);
  554. dct_line_large(block, temp, 19);
  555. dct_line_large(block, temp, 20);
  556. dct_line_large(block, temp, 21);
  557. dct_line_large(block, temp, 22);
  558. dct_line_large(block, temp, 23);
  559. dct_line_large(block, temp, 24);
  560. dct_line_large(block, temp, 25);
  561. dct_line_large(block, temp, 26);
  562. dct_line_large(block, temp, 27);
  563. dct_line_large(block, temp, 28);
  564. dct_line_large(block, temp, 29);
  565. dct_line_large(block, temp, 30);
  566. dct_line_large(block, temp, 31);
  567. dct_column_large(temp, cpatch, 0);
  568. dct_column_large(temp, cpatch, 1);
  569. dct_column_large(temp, cpatch, 2);
  570. dct_column_large(temp, cpatch, 3);
  571. dct_column_large(temp, cpatch, 4);
  572. dct_column_large(temp, cpatch, 5);
  573. dct_column_large(temp, cpatch, 6);
  574. dct_column_large(temp, cpatch, 7);
  575. dct_column_large(temp, cpatch, 8);
  576. dct_column_large(temp, cpatch, 9);
  577. dct_column_large(temp, cpatch, 10);
  578. dct_column_large(temp, cpatch, 11);
  579. dct_column_large(temp, cpatch, 12);
  580. dct_column_large(temp, cpatch, 13);
  581. dct_column_large(temp, cpatch, 14);
  582. dct_column_large(temp, cpatch, 15);
  583. dct_column_large(temp, cpatch, 16);
  584. dct_column_large(temp, cpatch, 17);
  585. dct_column_large(temp, cpatch, 18);
  586. dct_column_large(temp, cpatch, 19);
  587. dct_column_large(temp, cpatch, 20);
  588. dct_column_large(temp, cpatch, 21);
  589. dct_column_large(temp, cpatch, 22);
  590. dct_column_large(temp, cpatch, 23);
  591. dct_column_large(temp, cpatch, 24);
  592. dct_column_large(temp, cpatch, 25);
  593. dct_column_large(temp, cpatch, 26);
  594. dct_column_large(temp, cpatch, 27);
  595. dct_column_large(temp, cpatch, 28);
  596. dct_column_large(temp, cpatch, 29);
  597. dct_column_large(temp, cpatch, 30);
  598. dct_column_large(temp, cpatch, 31);
  599. }
  600. void compress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *php, S32 prequant)
  601. {
  602. S32 i, j;
  603. PCGD *pcp = &gPatchCompressGlobalData;
  604. S32 stride = pcp->patch_stride;
  605. S32 size = pcp->patch_size;
  606. F32 block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock;
  607. F32 *tpatch;
  608. S32 wordsize = prequant;
  609. F32 oozrange = 1.f/php->range;
  610. F32 dc = php->dc_offset;
  611. S32 range = (1<<prequant);
  612. F32 premult = oozrange*range;
  613. // F32 sub = (F32)(1<<(prequant - 1));
  614. F32 sub = (F32)(1<<(prequant - 1)) + dc*premult;
  615. php->quant_wbits = wordsize - 2;
  616. php->quant_wbits |= (prequant - 2)<<4;
  617. for (j = 0; j < size; j++)
  618. {
  619. tblock = block + j*size;
  620. tpatch = patch + j*stride;
  621. for (i = 0; i < size; i++)
  622. {
  623. // block[j*size + i] = (patch[j*stride + i] - dc)*premult - sub;
  624. *(tblock++) = *(tpatch++)*premult - sub;
  625. }
  626. }
  627. if (size == 16)
  628. dct_patch(block, cpatch);
  629. else
  630. dct_patch_large(block, cpatch);
  631. }
  632. void get_patch_group_header(LLGroupHeader *gopp)
  633. {
  634. PCGD *pcp = &gPatchCompressGlobalData;
  635. gopp->stride = pcp->patch_stride;
  636. gopp->patch_size = pcp->patch_size;
  637. gopp->layer_type = pcp->layer_type;
  638. }