PageRenderTime 92ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/patch_dct.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 769 lines | 604 code | 137 blank | 28 comment | 38 complexity | eb2764107c34b96e91516bd45199d046 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file patch_dct.cpp
  3. * @brief DCT 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. typedef struct s_patch_compress_global_data
  32. {
  33. S32 patch_size;
  34. S32 patch_stride;
  35. U32 charptr;
  36. S32 layer_type;
  37. } PCGD;
  38. PCGD gPatchCompressGlobalData;
  39. void reset_patch_compressor(void)
  40. {
  41. PCGD *pcp = &gPatchCompressGlobalData;
  42. pcp->charptr = 0;
  43. }
  44. S32 gCurrentSize = 0;
  45. F32 gPatchQuantizeTable[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  46. void build_patch_quantize_table(S32 size)
  47. {
  48. S32 i, j;
  49. for (j = 0; j < size; j++)
  50. {
  51. for (i = 0; i < size; i++)
  52. {
  53. gPatchQuantizeTable[j*size + i] = 1.f/(1.f + 2.f*(i+j));
  54. }
  55. }
  56. }
  57. F32 gPatchCosines[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  58. void setup_patch_cosines(S32 size)
  59. {
  60. S32 n, u;
  61. F32 oosob = F_PI*0.5f/size;
  62. for (u = 0; u < size; u++)
  63. {
  64. for (n = 0; n < size; n++)
  65. {
  66. gPatchCosines[u*size+n] = cosf((2.f*n+1.f)*u*oosob);
  67. }
  68. }
  69. }
  70. S32 gCopyMatrix[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  71. void build_copy_matrix(S32 size)
  72. {
  73. S32 i, j, count;
  74. BOOL b_diag = FALSE;
  75. BOOL b_right = TRUE;
  76. i = 0;
  77. j = 0;
  78. count = 0;
  79. while ( (i < size)
  80. &&(j < size))
  81. {
  82. gCopyMatrix[j*size + i] = count;
  83. count++;
  84. if (!b_diag)
  85. {
  86. if (b_right)
  87. {
  88. if (i < size - 1)
  89. i++;
  90. else
  91. j++;
  92. b_right = FALSE;
  93. b_diag = TRUE;
  94. }
  95. else
  96. {
  97. if (j < size - 1)
  98. j++;
  99. else
  100. i++;
  101. b_right = TRUE;
  102. b_diag = TRUE;
  103. }
  104. }
  105. else
  106. {
  107. if (b_right)
  108. {
  109. i++;
  110. j--;
  111. if ( (i == size - 1)
  112. ||(j == 0))
  113. {
  114. b_diag = FALSE;
  115. }
  116. }
  117. else
  118. {
  119. i--;
  120. j++;
  121. if ( (i == 0)
  122. ||(j == size - 1))
  123. {
  124. b_diag = FALSE;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. void init_patch_compressor(S32 patch_size, S32 patch_stride, S32 layer_type)
  131. {
  132. PCGD *pcp = &gPatchCompressGlobalData;
  133. pcp->charptr = 0;
  134. pcp->patch_size = patch_size;
  135. pcp->patch_stride = patch_stride;
  136. pcp->layer_type = layer_type;
  137. if (patch_size != gCurrentSize)
  138. {
  139. gCurrentSize = patch_size;
  140. build_patch_quantize_table(patch_size);
  141. setup_patch_cosines(patch_size);
  142. build_copy_matrix(patch_size);
  143. }
  144. }
  145. void prescan_patch(F32 *patch, LLPatchHeader *php, F32 &zmax, F32 &zmin)
  146. {
  147. S32 i, j;
  148. PCGD *pcp = &gPatchCompressGlobalData;
  149. S32 stride = pcp->patch_stride;
  150. S32 size = pcp->patch_size;
  151. S32 jstride;
  152. zmax = -99999999.f;
  153. zmin = 99999999.f;
  154. for (j = 0; j < size; j++)
  155. {
  156. jstride = j*stride;
  157. for (i = 0; i < size; i++)
  158. {
  159. if (*(patch + jstride + i) > zmax)
  160. {
  161. zmax = *(patch + jstride + i);
  162. }
  163. if (*(patch + jstride + i) < zmin)
  164. {
  165. zmin = *(patch + jstride + i);
  166. }
  167. }
  168. }
  169. php->dc_offset = zmin;
  170. php->range = (U16) ((zmax - zmin) + 1.f);
  171. }
  172. void dct_line(F32 *linein, F32 *lineout, S32 line)
  173. {
  174. S32 u;
  175. F32 total;
  176. F32 *pcp = gPatchCosines;
  177. S32 line_size = line*NORMAL_PATCH_SIZE;
  178. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  179. F32 *tlinein, *tpcp;
  180. tlinein = linein + line_size;
  181. total = *(tlinein++);
  182. total += *(tlinein++);
  183. total += *(tlinein++);
  184. total += *(tlinein++);
  185. total += *(tlinein++);
  186. total += *(tlinein++);
  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. *(lineout + line_size) = OO_SQRT2*total;
  198. for (u = 1; u < NORMAL_PATCH_SIZE; u++)
  199. {
  200. tlinein = linein + line_size;
  201. tpcp = pcp + (u<<4);
  202. total = *(tlinein++)*(*(tpcp++));
  203. total += *(tlinein++)*(*(tpcp++));
  204. total += *(tlinein++)*(*(tpcp++));
  205. total += *(tlinein++)*(*(tpcp++));
  206. total += *(tlinein++)*(*(tpcp++));
  207. total += *(tlinein++)*(*(tpcp++));
  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. *(lineout + line_size + u) = total;
  219. }
  220. #else
  221. S32 n;
  222. S32 size = gPatchCompressGlobalData.patch_size;
  223. total = 0.f;
  224. for (n = 0; n < size; n++)
  225. {
  226. total += linein[line_size + n];
  227. }
  228. lineout[line_size] = OO_SQRT2*total;
  229. for (u = 1; u < size; u++)
  230. {
  231. total = 0.f;
  232. for (n = 0; n < size; n++)
  233. {
  234. total += linein[line_size + n]*pcp[u*size+n];
  235. }
  236. lineout[line_size + u] = total;
  237. }
  238. #endif
  239. }
  240. void dct_line_large(F32 *linein, F32 *lineout, S32 line)
  241. {
  242. S32 u;
  243. F32 total;
  244. F32 *pcp = gPatchCosines;
  245. S32 line_size = line*LARGE_PATCH_SIZE;
  246. F32 *tlinein, *tpcp;
  247. tlinein = linein + line_size;
  248. total = *(tlinein++);
  249. total += *(tlinein++);
  250. total += *(tlinein++);
  251. total += *(tlinein++);
  252. total += *(tlinein++);
  253. total += *(tlinein++);
  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. *(lineout + line_size) = OO_SQRT2*total;
  281. for (u = 1; u < LARGE_PATCH_SIZE; u++)
  282. {
  283. tlinein = linein + line_size;
  284. tpcp = pcp + (u<<5);
  285. total = *(tlinein++)*(*(tpcp++));
  286. total += *(tlinein++)*(*(tpcp++));
  287. total += *(tlinein++)*(*(tpcp++));
  288. total += *(tlinein++)*(*(tpcp++));
  289. total += *(tlinein++)*(*(tpcp++));
  290. total += *(tlinein++)*(*(tpcp++));
  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. *(lineout + line_size + u) = total;
  318. }
  319. }
  320. inline void dct_column(F32 *linein, S32 *lineout, S32 column)
  321. {
  322. S32 u;
  323. F32 total;
  324. F32 oosob = 2.f/16.f;
  325. F32 *pcp = gPatchCosines;
  326. S32 *copy_matrix = gCopyMatrix;
  327. F32 *qt = gPatchQuantizeTable;
  328. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  329. F32 *tlinein, *tpcp;
  330. S32 sizeu;
  331. tlinein = linein + column;
  332. total = *(tlinein);
  333. total += *(tlinein += NORMAL_PATCH_SIZE);
  334. total += *(tlinein += NORMAL_PATCH_SIZE);
  335. total += *(tlinein += NORMAL_PATCH_SIZE);
  336. total += *(tlinein += NORMAL_PATCH_SIZE);
  337. total += *(tlinein += NORMAL_PATCH_SIZE);
  338. total += *(tlinein += NORMAL_PATCH_SIZE);
  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. *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
  349. for (u = 1; u < NORMAL_PATCH_SIZE; u++)
  350. {
  351. tlinein = linein + column;
  352. tpcp = pcp + (u<<4);
  353. total = *(tlinein)*(*(tpcp++));
  354. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  355. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  356. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  357. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  358. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(tpcp++));
  359. total += *(tlinein += NORMAL_PATCH_SIZE)*(*(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. sizeu = NORMAL_PATCH_SIZE*u + column;
  370. *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
  371. }
  372. #else
  373. S32 size = gPatchCompressGlobalData.patch_size;
  374. F32 oosob = 2.f/size;
  375. S32 n;
  376. total = 0.f;
  377. for (n = 0; n < size; n++)
  378. {
  379. total += linein[size*n + column];
  380. }
  381. lineout[copy_matrix[column]] = OO_SQRT2*total*oosob*qt[column];
  382. for (u = 1; u < size; u++)
  383. {
  384. total = 0.f;
  385. for (n = 0; n < size; n++)
  386. {
  387. total += linein[size*n + column]*pcp[u*size+n];
  388. }
  389. lineout[copy_matrix[size*u + column]] = total*oosob*qt[size*u + column];
  390. }
  391. #endif
  392. }
  393. inline void dct_column_large(F32 *linein, S32 *lineout, S32 column)
  394. {
  395. S32 u;
  396. F32 total;
  397. F32 oosob = 2.f/32.f;
  398. F32 *pcp = gPatchCosines;
  399. S32 *copy_matrix = gCopyMatrix;
  400. F32 *qt = gPatchQuantizeTable;
  401. F32 *tlinein, *tpcp;
  402. S32 sizeu;
  403. tlinein = linein + column;
  404. total = *(tlinein);
  405. total += *(tlinein += LARGE_PATCH_SIZE);
  406. total += *(tlinein += LARGE_PATCH_SIZE);
  407. total += *(tlinein += LARGE_PATCH_SIZE);
  408. total += *(tlinein += LARGE_PATCH_SIZE);
  409. total += *(tlinein += LARGE_PATCH_SIZE);
  410. total += *(tlinein += LARGE_PATCH_SIZE);
  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. *(lineout + *(copy_matrix + column)) = (S32)(OO_SQRT2*total*oosob*(*(qt + column)));
  437. for (u = 1; u < LARGE_PATCH_SIZE; u++)
  438. {
  439. tlinein = linein + column;
  440. tpcp = pcp + (u<<5);
  441. total = *(tlinein)*(*(tpcp++));
  442. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  443. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  444. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  445. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  446. total += *(tlinein += LARGE_PATCH_SIZE)*(*(tpcp++));
  447. total += *(tlinein += LARGE_PATCH_SIZE)*(*(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. sizeu = LARGE_PATCH_SIZE*u + column;
  474. *(lineout + *(copy_matrix + sizeu)) = (S32)(total*oosob*(*(qt+sizeu)));
  475. }
  476. }
  477. inline void dct_patch(F32 *block, S32 *cpatch)
  478. {
  479. F32 temp[NORMAL_PATCH_SIZE*NORMAL_PATCH_SIZE];
  480. #ifdef _PATCH_SIZE_16_AND_32_ONLY
  481. dct_line(block, temp, 0);
  482. dct_line(block, temp, 1);
  483. dct_line(block, temp, 2);
  484. dct_line(block, temp, 3);
  485. dct_line(block, temp, 4);
  486. dct_line(block, temp, 5);
  487. dct_line(block, temp, 6);
  488. dct_line(block, temp, 7);
  489. dct_line(block, temp, 8);
  490. dct_line(block, temp, 9);
  491. dct_line(block, temp, 10);
  492. dct_line(block, temp, 11);
  493. dct_line(block, temp, 12);
  494. dct_line(block, temp, 13);
  495. dct_line(block, temp, 14);
  496. dct_line(block, temp, 15);
  497. dct_column(temp, cpatch, 0);
  498. dct_column(temp, cpatch, 1);
  499. dct_column(temp, cpatch, 2);
  500. dct_column(temp, cpatch, 3);
  501. dct_column(temp, cpatch, 4);
  502. dct_column(temp, cpatch, 5);
  503. dct_column(temp, cpatch, 6);
  504. dct_column(temp, cpatch, 7);
  505. dct_column(temp, cpatch, 8);
  506. dct_column(temp, cpatch, 9);
  507. dct_column(temp, cpatch, 10);
  508. dct_column(temp, cpatch, 11);
  509. dct_column(temp, cpatch, 12);
  510. dct_column(temp, cpatch, 13);
  511. dct_column(temp, cpatch, 14);
  512. dct_column(temp, cpatch, 15);
  513. #else
  514. S32 i;
  515. S32 size = gPatchCompressGlobalData.patch_size;
  516. for (i = 0; i < size; i++)
  517. {
  518. dct_line(block, temp, i);
  519. }
  520. for (i = 0; i < size; i++)
  521. {
  522. dct_column(temp, cpatch, i);
  523. }
  524. #endif
  525. }
  526. inline void dct_patch_large(F32 *block, S32 *cpatch)
  527. {
  528. F32 temp[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
  529. dct_line_large(block, temp, 0);
  530. dct_line_large(block, temp, 1);
  531. dct_line_large(block, temp, 2);
  532. dct_line_large(block, temp, 3);
  533. dct_line_large(block, temp, 4);
  534. dct_line_large(block, temp, 5);
  535. dct_line_large(block, temp, 6);
  536. dct_line_large(block, temp, 7);
  537. dct_line_large(block, temp, 8);
  538. dct_line_large(block, temp, 9);
  539. dct_line_large(block, temp, 10);
  540. dct_line_large(block, temp, 11);
  541. dct_line_large(block, temp, 12);
  542. dct_line_large(block, temp, 13);
  543. dct_line_large(block, temp, 14);
  544. dct_line_large(block, temp, 15);
  545. dct_line_large(block, temp, 16);
  546. dct_line_large(block, temp, 17);
  547. dct_line_large(block, temp, 18);
  548. dct_line_large(block, temp, 19);
  549. dct_line_large(block, temp, 20);
  550. dct_line_large(block, temp, 21);
  551. dct_line_large(block, temp, 22);
  552. dct_line_large(block, temp, 23);
  553. dct_line_large(block, temp, 24);
  554. dct_line_large(block, temp, 25);
  555. dct_line_large(block, temp, 26);
  556. dct_line_large(block, temp, 27);
  557. dct_line_large(block, temp, 28);
  558. dct_line_large(block, temp, 29);
  559. dct_line_large(block, temp, 30);
  560. dct_line_large(block, temp, 31);
  561. dct_column_large(temp, cpatch, 0);
  562. dct_column_large(temp, cpatch, 1);
  563. dct_column_large(temp, cpatch, 2);
  564. dct_column_large(temp, cpatch, 3);
  565. dct_column_large(temp, cpatch, 4);
  566. dct_column_large(temp, cpatch, 5);
  567. dct_column_large(temp, cpatch, 6);
  568. dct_column_large(temp, cpatch, 7);
  569. dct_column_large(temp, cpatch, 8);
  570. dct_column_large(temp, cpatch, 9);
  571. dct_column_large(temp, cpatch, 10);
  572. dct_column_large(temp, cpatch, 11);
  573. dct_column_large(temp, cpatch, 12);
  574. dct_column_large(temp, cpatch, 13);
  575. dct_column_large(temp, cpatch, 14);
  576. dct_column_large(temp, cpatch, 15);
  577. dct_column_large(temp, cpatch, 16);
  578. dct_column_large(temp, cpatch, 17);
  579. dct_column_large(temp, cpatch, 18);
  580. dct_column_large(temp, cpatch, 19);
  581. dct_column_large(temp, cpatch, 20);
  582. dct_column_large(temp, cpatch, 21);
  583. dct_column_large(temp, cpatch, 22);
  584. dct_column_large(temp, cpatch, 23);
  585. dct_column_large(temp, cpatch, 24);
  586. dct_column_large(temp, cpatch, 25);
  587. dct_column_large(temp, cpatch, 26);
  588. dct_column_large(temp, cpatch, 27);
  589. dct_column_large(temp, cpatch, 28);
  590. dct_column_large(temp, cpatch, 29);
  591. dct_column_large(temp, cpatch, 30);
  592. dct_column_large(temp, cpatch, 31);
  593. }
  594. void compress_patch(F32 *patch, S32 *cpatch, LLPatchHeader *php, S32 prequant)
  595. {
  596. S32 i, j;
  597. PCGD *pcp = &gPatchCompressGlobalData;
  598. S32 stride = pcp->patch_stride;
  599. S32 size = pcp->patch_size;
  600. F32 block[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE], *tblock;
  601. F32 *tpatch;
  602. S32 wordsize = prequant;
  603. F32 oozrange = 1.f/php->range;
  604. F32 dc = php->dc_offset;
  605. S32 range = (1<<prequant);
  606. F32 premult = oozrange*range;
  607. // F32 sub = (F32)(1<<(prequant - 1));
  608. F32 sub = (F32)(1<<(prequant - 1)) + dc*premult;
  609. php->quant_wbits = wordsize - 2;
  610. php->quant_wbits |= (prequant - 2)<<4;
  611. for (j = 0; j < size; j++)
  612. {
  613. tblock = block + j*size;
  614. tpatch = patch + j*stride;
  615. for (i = 0; i < size; i++)
  616. {
  617. // block[j*size + i] = (patch[j*stride + i] - dc)*premult - sub;
  618. *(tblock++) = *(tpatch++)*premult - sub;
  619. }
  620. }
  621. if (size == 16)
  622. dct_patch(block, cpatch);
  623. else
  624. dct_patch_large(block, cpatch);
  625. }
  626. void get_patch_group_header(LLGroupHeader *gopp)
  627. {
  628. PCGD *pcp = &gPatchCompressGlobalData;
  629. gopp->stride = pcp->patch_stride;
  630. gopp->patch_size = pcp->patch_size;
  631. gopp->layer_type = pcp->layer_type;
  632. }