ReconIntra.cs 26 KB

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