ReconIntra.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. using Ryujinx.Graphics.Nvdec.Vp9.Common;
  2. using Ryujinx.Graphics.Nvdec.Vp9.Types;
  3. using System;
  4. using static Ryujinx.Graphics.Nvdec.Vp9.Dsp.IntraPred;
  5. namespace Ryujinx.Graphics.Nvdec.Vp9
  6. {
  7. internal static class ReconIntra
  8. {
  9. public static readonly TxType[] IntraModeToTxTypeLookup = {
  10. TxType.DctDct, // DC
  11. TxType.AdstDct, // V
  12. TxType.DctAdst, // H
  13. TxType.DctDct, // D45
  14. TxType.AdstAdst, // D135
  15. TxType.AdstDct, // D117
  16. TxType.DctAdst, // D153
  17. TxType.DctAdst, // D207
  18. TxType.AdstDct, // D63
  19. TxType.AdstAdst, // TM
  20. };
  21. private const int NeedLeft = 1 << 1;
  22. private const int NeedAbove = 1 << 2;
  23. private const int NeedAboveRight = 1 << 3;
  24. private static ReadOnlySpan<byte> ExtendModes => new byte[]
  25. {
  26. NeedAbove | NeedLeft, // DC
  27. NeedAbove, // V
  28. NeedLeft, // H
  29. NeedAboveRight, // D45
  30. NeedLeft | NeedAbove, // D135
  31. NeedLeft | NeedAbove, // D117
  32. NeedLeft | NeedAbove, // D153
  33. NeedLeft, // D207
  34. NeedAboveRight, // D63
  35. NeedLeft | NeedAbove, // TM
  36. };
  37. private unsafe delegate void IntraPredFn(byte* dst, int stride, byte* above, byte* left);
  38. private static readonly unsafe IntraPredFn[][] _pred = {
  39. new IntraPredFn[]
  40. {
  41. null,
  42. null,
  43. null,
  44. null,
  45. },
  46. new IntraPredFn[]
  47. {
  48. VPredictor4x4,
  49. VPredictor8x8,
  50. VPredictor16x16,
  51. VPredictor32x32,
  52. },
  53. new IntraPredFn[]
  54. {
  55. HPredictor4x4,
  56. HPredictor8x8,
  57. HPredictor16x16,
  58. HPredictor32x32,
  59. },
  60. new IntraPredFn[]
  61. {
  62. D45Predictor4x4,
  63. D45Predictor8x8,
  64. D45Predictor16x16,
  65. D45Predictor32x32,
  66. },
  67. new IntraPredFn[]
  68. {
  69. D135Predictor4x4,
  70. D135Predictor8x8,
  71. D135Predictor16x16,
  72. D135Predictor32x32,
  73. },
  74. new IntraPredFn[]
  75. {
  76. D117Predictor4x4,
  77. D117Predictor8x8,
  78. D117Predictor16x16,
  79. D117Predictor32x32,
  80. },
  81. new IntraPredFn[]
  82. {
  83. D153Predictor4x4,
  84. D153Predictor8x8,
  85. D153Predictor16x16,
  86. D153Predictor32x32,
  87. },
  88. new IntraPredFn[]
  89. {
  90. D207Predictor4x4,
  91. D207Predictor8x8,
  92. D207Predictor16x16,
  93. D207Predictor32x32,
  94. },
  95. new IntraPredFn[]
  96. {
  97. D63Predictor4x4,
  98. D63Predictor8x8,
  99. D63Predictor16x16,
  100. D63Predictor32x32,
  101. },
  102. new IntraPredFn[]
  103. {
  104. TMPredictor4x4,
  105. TMPredictor8x8,
  106. TMPredictor16x16,
  107. TMPredictor32x32,
  108. },
  109. };
  110. private static readonly unsafe IntraPredFn[][][] _dcPred = {
  111. new[]
  112. {
  113. new IntraPredFn[]
  114. {
  115. Dc128Predictor4x4,
  116. Dc128Predictor8x8,
  117. Dc128Predictor16x16,
  118. Dc128Predictor32x32,
  119. },
  120. new IntraPredFn[]
  121. {
  122. DcTopPredictor4x4,
  123. DcTopPredictor8x8,
  124. DcTopPredictor16x16,
  125. DcTopPredictor32x32,
  126. },
  127. },
  128. new[]
  129. {
  130. new IntraPredFn[]
  131. {
  132. DcLeftPredictor4x4,
  133. DcLeftPredictor8x8,
  134. DcLeftPredictor16x16,
  135. DcLeftPredictor32x32,
  136. },
  137. new IntraPredFn[]
  138. {
  139. DcPredictor4x4,
  140. DcPredictor8x8,
  141. DcPredictor16x16,
  142. DcPredictor32x32,
  143. },
  144. },
  145. };
  146. private unsafe delegate void IntraHighPredFn(ushort* dst, int stride, ushort* above, ushort* left, int bd);
  147. private static readonly unsafe IntraHighPredFn[][] _predHigh = {
  148. new IntraHighPredFn[]
  149. {
  150. null,
  151. null,
  152. null,
  153. null,
  154. },
  155. new IntraHighPredFn[]
  156. {
  157. HighbdVPredictor4x4,
  158. HighbdVPredictor8x8,
  159. HighbdVPredictor16x16,
  160. HighbdVPredictor32x32,
  161. },
  162. new IntraHighPredFn[]
  163. {
  164. HighbdHPredictor4x4,
  165. HighbdHPredictor8x8,
  166. HighbdHPredictor16x16,
  167. HighbdHPredictor32x32,
  168. },
  169. new IntraHighPredFn[]
  170. {
  171. HighbdD45Predictor4x4,
  172. HighbdD45Predictor8x8,
  173. HighbdD45Predictor16x16,
  174. HighbdD45Predictor32x32,
  175. },
  176. new IntraHighPredFn[]
  177. {
  178. HighbdD135Predictor4x4,
  179. HighbdD135Predictor8x8,
  180. HighbdD135Predictor16x16,
  181. HighbdD135Predictor32x32,
  182. },
  183. new IntraHighPredFn[]
  184. {
  185. HighbdD117Predictor4x4,
  186. HighbdD117Predictor8x8,
  187. HighbdD117Predictor16x16,
  188. HighbdD117Predictor32x32,
  189. },
  190. new IntraHighPredFn[]
  191. {
  192. HighbdD153Predictor4x4,
  193. HighbdD153Predictor8x8,
  194. HighbdD153Predictor16x16,
  195. HighbdD153Predictor32x32,
  196. },
  197. new IntraHighPredFn[]
  198. {
  199. HighbdD207Predictor4x4,
  200. HighbdD207Predictor8x8,
  201. HighbdD207Predictor16x16,
  202. HighbdD207Predictor32x32,
  203. },
  204. new IntraHighPredFn[]
  205. {
  206. HighbdD63Predictor4x4,
  207. HighbdD63Predictor8x8,
  208. HighbdD63Predictor16x16,
  209. HighbdD63Predictor32x32,
  210. },
  211. new IntraHighPredFn[]
  212. {
  213. HighbdTMPredictor4x4,
  214. HighbdTMPredictor8x8,
  215. HighbdTMPredictor16x16,
  216. HighbdTMPredictor32x32,
  217. },
  218. };
  219. private static readonly unsafe IntraHighPredFn[][][] _dcPredHigh = {
  220. new[]
  221. {
  222. new IntraHighPredFn[]
  223. {
  224. HighbdDc128Predictor4x4,
  225. HighbdDc128Predictor8x8,
  226. HighbdDc128Predictor16x16,
  227. HighbdDc128Predictor32x32,
  228. },
  229. new IntraHighPredFn[]
  230. {
  231. HighbdDcTopPredictor4x4,
  232. HighbdDcTopPredictor8x8,
  233. HighbdDcTopPredictor16x16,
  234. HighbdDcTopPredictor32x32,
  235. },
  236. },
  237. new[]
  238. {
  239. new IntraHighPredFn[]
  240. {
  241. HighbdDcLeftPredictor4x4,
  242. HighbdDcLeftPredictor8x8,
  243. HighbdDcLeftPredictor16x16,
  244. HighbdDcLeftPredictor32x32,
  245. },
  246. new IntraHighPredFn[]
  247. {
  248. HighbdDcPredictor4x4,
  249. HighbdDcPredictor8x8,
  250. HighbdDcPredictor16x16,
  251. HighbdDcPredictor32x32,
  252. },
  253. },
  254. };
  255. private static unsafe void BuildIntraPredictorsHigh(
  256. ref MacroBlockD xd,
  257. byte* ref8,
  258. int refStride,
  259. byte* dst8,
  260. int dstStride,
  261. PredictionMode mode,
  262. TxSize txSize,
  263. int upAvailable,
  264. int leftAvailable,
  265. int rightAvailable,
  266. int x,
  267. int y,
  268. int plane)
  269. {
  270. int i;
  271. ushort* dst = (ushort*)dst8;
  272. ushort* refr = (ushort*)ref8;
  273. ushort* leftCol = stackalloc ushort[32];
  274. ushort* aboveData = stackalloc ushort[64 + 16];
  275. ushort* aboveRow = aboveData + 16;
  276. ushort* constAboveRow = aboveRow;
  277. int bs = 4 << (int)txSize;
  278. int frameWidth, frameHeight;
  279. int x0, y0;
  280. ref MacroBlockDPlane pd = ref xd.Plane[plane];
  281. int needLeft = ExtendModes[(int)mode] & NeedLeft;
  282. int needAbove = ExtendModes[(int)mode] & NeedAbove;
  283. int needAboveRight = ExtendModes[(int)mode] & NeedAboveRight;
  284. int baseVal = 128 << (xd.Bd - 8);
  285. // 127 127 127 .. 127 127 127 127 127 127
  286. // 129 A B .. Y Z
  287. // 129 C D .. W X
  288. // 129 E F .. U V
  289. // 129 G H .. S T T T T T
  290. // For 10 bit and 12 bit, 127 and 129 are replaced by base -1 and base + 1.
  291. // Get current frame pointer, width and height.
  292. if (plane == 0)
  293. {
  294. frameWidth = xd.CurBuf.Width;
  295. frameHeight = xd.CurBuf.Height;
  296. }
  297. else
  298. {
  299. frameWidth = xd.CurBuf.UvWidth;
  300. frameHeight = xd.CurBuf.UvHeight;
  301. }
  302. // Get block position in current frame.
  303. x0 = (-xd.MbToLeftEdge >> (3 + pd.SubsamplingX)) + x;
  304. y0 = (-xd.MbToTopEdge >> (3 + pd.SubsamplingY)) + y;
  305. // NEED_LEFT
  306. if (needLeft != 0)
  307. {
  308. if (leftAvailable != 0)
  309. {
  310. if (xd.MbToBottomEdge < 0)
  311. {
  312. /* slower path if the block needs border extension */
  313. if (y0 + bs <= frameHeight)
  314. {
  315. for (i = 0; i < bs; ++i)
  316. {
  317. leftCol[i] = refr[i * refStride - 1];
  318. }
  319. }
  320. else
  321. {
  322. int extendBottom = frameHeight - y0;
  323. for (i = 0; i < extendBottom; ++i)
  324. {
  325. leftCol[i] = refr[i * refStride - 1];
  326. }
  327. for (; i < bs; ++i)
  328. {
  329. leftCol[i] = refr[(extendBottom - 1) * refStride - 1];
  330. }
  331. }
  332. }
  333. else
  334. {
  335. /* faster path if the block does not need extension */
  336. for (i = 0; i < bs; ++i)
  337. {
  338. leftCol[i] = refr[i * refStride - 1];
  339. }
  340. }
  341. }
  342. else
  343. {
  344. MemoryUtil.Fill(leftCol, (ushort)(baseVal + 1), bs);
  345. }
  346. }
  347. // NEED_ABOVE
  348. if (needAbove != 0)
  349. {
  350. if (upAvailable != 0)
  351. {
  352. ushort* aboveRef = refr - refStride;
  353. if (xd.MbToRightEdge < 0)
  354. {
  355. /* slower path if the block needs border extension */
  356. if (x0 + bs <= frameWidth)
  357. {
  358. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  359. }
  360. else if (x0 <= frameWidth)
  361. {
  362. int r = frameWidth - x0;
  363. MemoryUtil.Copy(aboveRow, aboveRef, r);
  364. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + bs - frameWidth);
  365. }
  366. }
  367. else
  368. {
  369. /* faster path if the block does not need extension */
  370. if (bs == 4 && rightAvailable != 0 && leftAvailable != 0)
  371. {
  372. constAboveRow = aboveRef;
  373. }
  374. else
  375. {
  376. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  377. }
  378. }
  379. aboveRow[-1] = leftAvailable != 0 ? aboveRef[-1] : (ushort)(baseVal + 1);
  380. }
  381. else
  382. {
  383. MemoryUtil.Fill(aboveRow, (ushort)(baseVal - 1), bs);
  384. aboveRow[-1] = (ushort)(baseVal - 1);
  385. }
  386. }
  387. // NEED_ABOVERIGHT
  388. if (needAboveRight != 0)
  389. {
  390. if (upAvailable != 0)
  391. {
  392. ushort* aboveRef = refr - refStride;
  393. if (xd.MbToRightEdge < 0)
  394. {
  395. /* slower path if the block needs border extension */
  396. if (x0 + 2 * bs <= frameWidth)
  397. {
  398. if (rightAvailable != 0 && bs == 4)
  399. {
  400. MemoryUtil.Copy(aboveRow, aboveRef, 2 * bs);
  401. }
  402. else
  403. {
  404. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  405. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  406. }
  407. }
  408. else if (x0 + bs <= frameWidth)
  409. {
  410. int r = frameWidth - x0;
  411. if (rightAvailable != 0 && bs == 4)
  412. {
  413. MemoryUtil.Copy(aboveRow, aboveRef, r);
  414. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + 2 * bs - frameWidth);
  415. }
  416. else
  417. {
  418. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  419. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  420. }
  421. }
  422. else if (x0 <= frameWidth)
  423. {
  424. int r = frameWidth - x0;
  425. MemoryUtil.Copy(aboveRow, aboveRef, r);
  426. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + 2 * bs - frameWidth);
  427. }
  428. aboveRow[-1] = leftAvailable != 0 ? aboveRef[-1] : (ushort)(baseVal + 1);
  429. }
  430. else
  431. {
  432. /* faster path if the block does not need extension */
  433. if (bs == 4 && rightAvailable != 0 && leftAvailable != 0)
  434. {
  435. constAboveRow = aboveRef;
  436. }
  437. else
  438. {
  439. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  440. if (bs == 4 && rightAvailable != 0)
  441. {
  442. MemoryUtil.Copy(aboveRow + bs, aboveRef + bs, bs);
  443. }
  444. else
  445. {
  446. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  447. }
  448. aboveRow[-1] = leftAvailable != 0 ? aboveRef[-1] : (ushort)(baseVal + 1);
  449. }
  450. }
  451. }
  452. else
  453. {
  454. MemoryUtil.Fill(aboveRow, (ushort)(baseVal - 1), bs * 2);
  455. aboveRow[-1] = (ushort)(baseVal - 1);
  456. }
  457. }
  458. // Predict
  459. if (mode == PredictionMode.DcPred)
  460. {
  461. _dcPredHigh[leftAvailable][upAvailable][(int)txSize](dst, dstStride, constAboveRow, leftCol, xd.Bd);
  462. }
  463. else
  464. {
  465. _predHigh[(int)mode][(int)txSize](dst, dstStride, constAboveRow, leftCol, xd.Bd);
  466. }
  467. }
  468. public static unsafe void BuildIntraPredictors(
  469. ref MacroBlockD xd,
  470. byte* refr,
  471. int refStride,
  472. byte* dst,
  473. int dstStride,
  474. PredictionMode mode,
  475. TxSize txSize,
  476. int upAvailable,
  477. int leftAvailable,
  478. int rightAvailable,
  479. int x,
  480. int y,
  481. int plane)
  482. {
  483. int i;
  484. byte* leftCol = stackalloc byte[32];
  485. byte* aboveData = stackalloc byte[64 + 16];
  486. byte* aboveRow = aboveData + 16;
  487. byte* constAboveRow = aboveRow;
  488. int bs = 4 << (int)txSize;
  489. int frameWidth, frameHeight;
  490. int x0, y0;
  491. ref MacroBlockDPlane pd = ref xd.Plane[plane];
  492. // 127 127 127 .. 127 127 127 127 127 127
  493. // 129 A B .. Y Z
  494. // 129 C D .. W X
  495. // 129 E F .. U V
  496. // 129 G H .. S T T T T T
  497. // ..
  498. // Get current frame pointer, width and height.
  499. if (plane == 0)
  500. {
  501. frameWidth = xd.CurBuf.Width;
  502. frameHeight = xd.CurBuf.Height;
  503. }
  504. else
  505. {
  506. frameWidth = xd.CurBuf.UvWidth;
  507. frameHeight = xd.CurBuf.UvHeight;
  508. }
  509. // Get block position in current frame.
  510. x0 = (-xd.MbToLeftEdge >> (3 + pd.SubsamplingX)) + x;
  511. y0 = (-xd.MbToTopEdge >> (3 + pd.SubsamplingY)) + y;
  512. // NEED_LEFT
  513. if ((ExtendModes[(int)mode] & NeedLeft) != 0)
  514. {
  515. if (leftAvailable != 0)
  516. {
  517. if (xd.MbToBottomEdge < 0)
  518. {
  519. /* Slower path if the block needs border extension */
  520. if (y0 + bs <= frameHeight)
  521. {
  522. for (i = 0; i < bs; ++i)
  523. {
  524. leftCol[i] = refr[i * refStride - 1];
  525. }
  526. }
  527. else
  528. {
  529. int extendBottom = frameHeight - y0;
  530. for (i = 0; i < extendBottom; ++i)
  531. {
  532. leftCol[i] = refr[i * refStride - 1];
  533. }
  534. for (; i < bs; ++i)
  535. {
  536. leftCol[i] = refr[(extendBottom - 1) * refStride - 1];
  537. }
  538. }
  539. }
  540. else
  541. {
  542. /* Faster path if the block does not need extension */
  543. for (i = 0; i < bs; ++i)
  544. {
  545. leftCol[i] = refr[i * refStride - 1];
  546. }
  547. }
  548. }
  549. else
  550. {
  551. MemoryUtil.Fill(leftCol, (byte)129, bs);
  552. }
  553. }
  554. // NEED_ABOVE
  555. if ((ExtendModes[(int)mode] & NeedAbove) != 0)
  556. {
  557. if (upAvailable != 0)
  558. {
  559. byte* aboveRef = refr - refStride;
  560. if (xd.MbToRightEdge < 0)
  561. {
  562. /* Slower path if the block needs border extension */
  563. if (x0 + bs <= frameWidth)
  564. {
  565. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  566. }
  567. else if (x0 <= frameWidth)
  568. {
  569. int r = frameWidth - x0;
  570. MemoryUtil.Copy(aboveRow, aboveRef, r);
  571. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + bs - frameWidth);
  572. }
  573. }
  574. else
  575. {
  576. /* Faster path if the block does not need extension */
  577. if (bs == 4 && rightAvailable != 0 && leftAvailable != 0)
  578. {
  579. constAboveRow = aboveRef;
  580. }
  581. else
  582. {
  583. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  584. }
  585. }
  586. aboveRow[-1] = leftAvailable != 0 ? aboveRef[-1] : (byte)129;
  587. }
  588. else
  589. {
  590. MemoryUtil.Fill(aboveRow, (byte)127, bs);
  591. aboveRow[-1] = 127;
  592. }
  593. }
  594. // NEED_ABOVERIGHT
  595. if ((ExtendModes[(int)mode] & NeedAboveRight) != 0)
  596. {
  597. if (upAvailable != 0)
  598. {
  599. byte* aboveRef = refr - refStride;
  600. if (xd.MbToRightEdge < 0)
  601. {
  602. /* Slower path if the block needs border extension */
  603. if (x0 + 2 * bs <= frameWidth)
  604. {
  605. if (rightAvailable != 0 && bs == 4)
  606. {
  607. MemoryUtil.Copy(aboveRow, aboveRef, 2 * bs);
  608. }
  609. else
  610. {
  611. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  612. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  613. }
  614. }
  615. else if (x0 + bs <= frameWidth)
  616. {
  617. int r = frameWidth - x0;
  618. if (rightAvailable != 0 && bs == 4)
  619. {
  620. MemoryUtil.Copy(aboveRow, aboveRef, r);
  621. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + 2 * bs - frameWidth);
  622. }
  623. else
  624. {
  625. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  626. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  627. }
  628. }
  629. else if (x0 <= frameWidth)
  630. {
  631. int r = frameWidth - x0;
  632. MemoryUtil.Copy(aboveRow, aboveRef, r);
  633. MemoryUtil.Fill(aboveRow + r, aboveRow[r - 1], x0 + 2 * bs - frameWidth);
  634. }
  635. }
  636. else
  637. {
  638. /* Faster path if the block does not need extension */
  639. if (bs == 4 && rightAvailable != 0 && leftAvailable != 0)
  640. {
  641. constAboveRow = aboveRef;
  642. }
  643. else
  644. {
  645. MemoryUtil.Copy(aboveRow, aboveRef, bs);
  646. if (bs == 4 && rightAvailable != 0)
  647. {
  648. MemoryUtil.Copy(aboveRow + bs, aboveRef + bs, bs);
  649. }
  650. else
  651. {
  652. MemoryUtil.Fill(aboveRow + bs, aboveRow[bs - 1], bs);
  653. }
  654. }
  655. }
  656. aboveRow[-1] = leftAvailable != 0 ? aboveRef[-1] : (byte)129;
  657. }
  658. else
  659. {
  660. MemoryUtil.Fill(aboveRow, (byte)127, bs * 2);
  661. aboveRow[-1] = 127;
  662. }
  663. }
  664. // Predict
  665. if (mode == PredictionMode.DcPred)
  666. {
  667. _dcPred[leftAvailable][upAvailable][(int)txSize](dst, dstStride, constAboveRow, leftCol);
  668. }
  669. else
  670. {
  671. _pred[(int)mode][(int)txSize](dst, dstStride, constAboveRow, leftCol);
  672. }
  673. }
  674. public static unsafe void PredictIntraBlock(
  675. ref MacroBlockD xd,
  676. int bwlIn,
  677. TxSize txSize,
  678. PredictionMode mode,
  679. byte* refr,
  680. int refStride,
  681. byte* dst,
  682. int dstStride,
  683. int aoff,
  684. int loff,
  685. int plane)
  686. {
  687. int bw = 1 << bwlIn;
  688. int txw = 1 << (int)txSize;
  689. int haveTop = loff != 0 || !xd.AboveMi.IsNull ? 1 : 0;
  690. int haveLeft = aoff != 0 || !xd.LeftMi.IsNull ? 1 : 0;
  691. int haveRight = (aoff + txw) < bw ? 1 : 0;
  692. int x = aoff * 4;
  693. int y = loff * 4;
  694. if (xd.CurBuf.HighBd)
  695. {
  696. BuildIntraPredictorsHigh(
  697. ref xd,
  698. refr,
  699. refStride,
  700. dst,
  701. dstStride,
  702. mode,
  703. txSize,
  704. haveTop,
  705. haveLeft,
  706. haveRight,
  707. x,
  708. y,
  709. plane);
  710. return;
  711. }
  712. BuildIntraPredictors(
  713. ref xd,
  714. refr,
  715. refStride,
  716. dst,
  717. dstStride,
  718. mode,
  719. txSize,
  720. haveTop,
  721. haveLeft,
  722. haveRight,
  723. x,
  724. y,
  725. plane);
  726. }
  727. }
  728. }