ReconIntra.cs 26 KB

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