IntraPred.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. using Ryujinx.Graphics.Nvdec.Vp9.Common;
  2. namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
  3. {
  4. internal static class IntraPred
  5. {
  6. private static unsafe ref byte Dst(byte* dst, int stride, int x, int y)
  7. {
  8. return ref dst[x + y * stride];
  9. }
  10. private static unsafe ref ushort Dst(ushort* dst, int stride, int x, int y)
  11. {
  12. return ref dst[x + y * stride];
  13. }
  14. private static byte Avg3(byte a, byte b, byte c)
  15. {
  16. return (byte)((a + 2 * b + c + 2) >> 2);
  17. }
  18. private static ushort Avg3(ushort a, ushort b, ushort c)
  19. {
  20. return (ushort)((a + 2 * b + c + 2) >> 2);
  21. }
  22. private static byte Avg2(byte a, byte b)
  23. {
  24. return (byte)((a + b + 1) >> 1);
  25. }
  26. private static ushort Avg2(ushort a, ushort b)
  27. {
  28. return (ushort)((a + b + 1) >> 1);
  29. }
  30. public static unsafe void D207Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  31. {
  32. D207Predictor(dst, stride, 8, above, left);
  33. }
  34. public static unsafe void D207Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  35. {
  36. D207Predictor(dst, stride, 16, above, left);
  37. }
  38. public static unsafe void D207Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  39. {
  40. D207Predictor(dst, stride, 32, above, left);
  41. }
  42. private static unsafe void D207Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  43. {
  44. int r, c;
  45. // First column
  46. for (r = 0; r < bs - 1; ++r)
  47. {
  48. dst[r * stride] = Avg2(left[r], left[r + 1]);
  49. }
  50. dst[(bs - 1) * stride] = left[bs - 1];
  51. dst++;
  52. // Second column
  53. for (r = 0; r < bs - 2; ++r)
  54. {
  55. dst[r * stride] = Avg3(left[r], left[r + 1], left[r + 2]);
  56. }
  57. dst[(bs - 2) * stride] = Avg3(left[bs - 2], left[bs - 1], left[bs - 1]);
  58. dst[(bs - 1) * stride] = left[bs - 1];
  59. dst++;
  60. // Rest of last row
  61. for (c = 0; c < bs - 2; ++c)
  62. {
  63. dst[(bs - 1) * stride + c] = left[bs - 1];
  64. }
  65. for (r = bs - 2; r >= 0; --r)
  66. {
  67. for (c = 0; c < bs - 2; ++c)
  68. {
  69. dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
  70. }
  71. }
  72. }
  73. public static unsafe void D63Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  74. {
  75. D63Predictor(dst, stride, 8, above, left);
  76. }
  77. public static unsafe void D63Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  78. {
  79. D63Predictor(dst, stride, 16, above, left);
  80. }
  81. public static unsafe void D63Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  82. {
  83. D63Predictor(dst, stride, 32, above, left);
  84. }
  85. private static unsafe void D63Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  86. {
  87. int r, c;
  88. int size;
  89. for (c = 0; c < bs; ++c)
  90. {
  91. dst[c] = Avg2(above[c], above[c + 1]);
  92. dst[stride + c] = Avg3(above[c], above[c + 1], above[c + 2]);
  93. }
  94. for (r = 2, size = bs - 2; r < bs; r += 2, --size)
  95. {
  96. MemoryUtil.Copy(dst + (r + 0) * stride, dst + (r >> 1), size);
  97. MemoryUtil.Fill(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
  98. MemoryUtil.Copy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
  99. MemoryUtil.Fill(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
  100. }
  101. }
  102. public static unsafe void D45Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  103. {
  104. D45Predictor(dst, stride, 8, above, left);
  105. }
  106. public static unsafe void D45Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  107. {
  108. D45Predictor(dst, stride, 16, above, left);
  109. }
  110. public static unsafe void D45Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  111. {
  112. D45Predictor(dst, stride, 32, above, left);
  113. }
  114. private static unsafe void D45Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  115. {
  116. byte aboveRight = above[bs - 1];
  117. byte* dstRow0 = dst;
  118. int x, size;
  119. for (x = 0; x < bs - 1; ++x)
  120. {
  121. dst[x] = Avg3(above[x], above[x + 1], above[x + 2]);
  122. }
  123. dst[bs - 1] = aboveRight;
  124. dst += stride;
  125. for (x = 1, size = bs - 2; x < bs; ++x, --size)
  126. {
  127. MemoryUtil.Copy(dst, dstRow0 + x, size);
  128. MemoryUtil.Fill(dst + size, aboveRight, x + 1);
  129. dst += stride;
  130. }
  131. }
  132. public static unsafe void D117Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  133. {
  134. D117Predictor(dst, stride, 8, above, left);
  135. }
  136. public static unsafe void D117Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  137. {
  138. D117Predictor(dst, stride, 16, above, left);
  139. }
  140. public static unsafe void D117Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  141. {
  142. D117Predictor(dst, stride, 32, above, left);
  143. }
  144. private static unsafe void D117Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  145. {
  146. int r, c;
  147. // First row
  148. for (c = 0; c < bs; c++)
  149. {
  150. dst[c] = Avg2(above[c - 1], above[c]);
  151. }
  152. dst += stride;
  153. // Second row
  154. dst[0] = Avg3(left[0], above[-1], above[0]);
  155. for (c = 1; c < bs; c++)
  156. {
  157. dst[c] = Avg3(above[c - 2], above[c - 1], above[c]);
  158. }
  159. dst += stride;
  160. // The rest of first col
  161. dst[0] = Avg3(above[-1], left[0], left[1]);
  162. for (r = 3; r < bs; ++r)
  163. {
  164. dst[(r - 2) * stride] = Avg3(left[r - 3], left[r - 2], left[r - 1]);
  165. }
  166. // The rest of the block
  167. for (r = 2; r < bs; ++r)
  168. {
  169. for (c = 1; c < bs; c++)
  170. {
  171. dst[c] = dst[-2 * stride + c - 1];
  172. }
  173. dst += stride;
  174. }
  175. }
  176. public static unsafe void D135Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  177. {
  178. D135Predictor(dst, stride, 8, above, left);
  179. }
  180. public static unsafe void D135Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  181. {
  182. D135Predictor(dst, stride, 16, above, left);
  183. }
  184. public static unsafe void D135Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  185. {
  186. D135Predictor(dst, stride, 32, above, left);
  187. }
  188. private static unsafe void D135Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  189. {
  190. int i;
  191. byte* border = stackalloc byte[32 + 32 - 1]; // outer border from bottom-left to top-right
  192. // Dst(dst, stride, bs, bs - 2)[0], i.e., border starting at bottom-left
  193. for (i = 0; i < bs - 2; ++i)
  194. {
  195. border[i] = Avg3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
  196. }
  197. border[bs - 2] = Avg3(above[-1], left[0], left[1]);
  198. border[bs - 1] = Avg3(left[0], above[-1], above[0]);
  199. border[bs - 0] = Avg3(above[-1], above[0], above[1]);
  200. // dst[0][2, size), i.e., remaining top border ascending
  201. for (i = 0; i < bs - 2; ++i)
  202. {
  203. border[bs + 1 + i] = Avg3(above[i], above[i + 1], above[i + 2]);
  204. }
  205. for (i = 0; i < bs; ++i)
  206. {
  207. MemoryUtil.Copy(dst + i * stride, border + bs - 1 - i, bs);
  208. }
  209. }
  210. public static unsafe void D153Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  211. {
  212. D153Predictor(dst, stride, 8, above, left);
  213. }
  214. public static unsafe void D153Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  215. {
  216. D153Predictor(dst, stride, 16, above, left);
  217. }
  218. public static unsafe void D153Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  219. {
  220. D153Predictor(dst, stride, 32, above, left);
  221. }
  222. private static unsafe void D153Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  223. {
  224. int r, c;
  225. dst[0] = Avg2(above[-1], left[0]);
  226. for (r = 1; r < bs; r++)
  227. {
  228. dst[r * stride] = Avg2(left[r - 1], left[r]);
  229. }
  230. dst++;
  231. dst[0] = Avg3(left[0], above[-1], above[0]);
  232. dst[stride] = Avg3(above[-1], left[0], left[1]);
  233. for (r = 2; r < bs; r++)
  234. {
  235. dst[r * stride] = Avg3(left[r - 2], left[r - 1], left[r]);
  236. }
  237. dst++;
  238. for (c = 0; c < bs - 2; c++)
  239. {
  240. dst[c] = Avg3(above[c - 1], above[c], above[c + 1]);
  241. }
  242. dst += stride;
  243. for (r = 1; r < bs; ++r)
  244. {
  245. for (c = 0; c < bs - 2; c++)
  246. {
  247. dst[c] = dst[-stride + c - 2];
  248. }
  249. dst += stride;
  250. }
  251. }
  252. public static unsafe void VPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  253. {
  254. VPredictor(dst, stride, 4, above, left);
  255. }
  256. public static unsafe void VPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  257. {
  258. VPredictor(dst, stride, 8, above, left);
  259. }
  260. public static unsafe void VPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  261. {
  262. VPredictor(dst, stride, 16, above, left);
  263. }
  264. public static unsafe void VPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  265. {
  266. VPredictor(dst, stride, 32, above, left);
  267. }
  268. private static unsafe void VPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  269. {
  270. int r;
  271. for (r = 0; r < bs; r++)
  272. {
  273. MemoryUtil.Copy(dst, above, bs);
  274. dst += stride;
  275. }
  276. }
  277. public static unsafe void HPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  278. {
  279. HPredictor(dst, stride, 4, above, left);
  280. }
  281. public static unsafe void HPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  282. {
  283. HPredictor(dst, stride, 8, above, left);
  284. }
  285. public static unsafe void HPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  286. {
  287. HPredictor(dst, stride, 16, above, left);
  288. }
  289. public static unsafe void HPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  290. {
  291. HPredictor(dst, stride, 32, above, left);
  292. }
  293. private static unsafe void HPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  294. {
  295. int r;
  296. for (r = 0; r < bs; r++)
  297. {
  298. MemoryUtil.Fill(dst, left[r], bs);
  299. dst += stride;
  300. }
  301. }
  302. public static unsafe void TMPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  303. {
  304. TMPredictor(dst, stride, 4, above, left);
  305. }
  306. public static unsafe void TMPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  307. {
  308. TMPredictor(dst, stride, 8, above, left);
  309. }
  310. public static unsafe void TMPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  311. {
  312. TMPredictor(dst, stride, 16, above, left);
  313. }
  314. public static unsafe void TMPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  315. {
  316. TMPredictor(dst, stride, 32, above, left);
  317. }
  318. private static unsafe void TMPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  319. {
  320. int r, c;
  321. int yTopLeft = above[-1];
  322. for (r = 0; r < bs; r++)
  323. {
  324. for (c = 0; c < bs; c++)
  325. {
  326. dst[c] = BitUtils.ClipPixel(left[r] + above[c] - yTopLeft);
  327. }
  328. dst += stride;
  329. }
  330. }
  331. public static unsafe void Dc128Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  332. {
  333. Dc128Predictor(dst, stride, 4, above, left);
  334. }
  335. public static unsafe void Dc128Predictor8x8(byte* dst, int stride, byte* above, byte* left)
  336. {
  337. Dc128Predictor(dst, stride, 8, above, left);
  338. }
  339. public static unsafe void Dc128Predictor16x16(byte* dst, int stride, byte* above, byte* left)
  340. {
  341. Dc128Predictor(dst, stride, 16, above, left);
  342. }
  343. public static unsafe void Dc128Predictor32x32(byte* dst, int stride, byte* above, byte* left)
  344. {
  345. Dc128Predictor(dst, stride, 32, above, left);
  346. }
  347. private static unsafe void Dc128Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
  348. {
  349. int r;
  350. for (r = 0; r < bs; r++)
  351. {
  352. MemoryUtil.Fill(dst, (byte)128, bs);
  353. dst += stride;
  354. }
  355. }
  356. public static unsafe void DcLeftPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  357. {
  358. DcLeftPredictor(dst, stride, 4, above, left);
  359. }
  360. public static unsafe void DcLeftPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  361. {
  362. DcLeftPredictor(dst, stride, 8, above, left);
  363. }
  364. public static unsafe void DcLeftPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  365. {
  366. DcLeftPredictor(dst, stride, 16, above, left);
  367. }
  368. public static unsafe void DcLeftPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  369. {
  370. DcLeftPredictor(dst, stride, 32, above, left);
  371. }
  372. private static unsafe void DcLeftPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  373. {
  374. int i, r, expectedDc, sum = 0;
  375. for (i = 0; i < bs; i++)
  376. {
  377. sum += left[i];
  378. }
  379. expectedDc = (sum + (bs >> 1)) / bs;
  380. for (r = 0; r < bs; r++)
  381. {
  382. MemoryUtil.Fill(dst, (byte)expectedDc, bs);
  383. dst += stride;
  384. }
  385. }
  386. public static unsafe void DcTopPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  387. {
  388. DcTopPredictor(dst, stride, 4, above, left);
  389. }
  390. public static unsafe void DcTopPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  391. {
  392. DcTopPredictor(dst, stride, 8, above, left);
  393. }
  394. public static unsafe void DcTopPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  395. {
  396. DcTopPredictor(dst, stride, 16, above, left);
  397. }
  398. public static unsafe void DcTopPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  399. {
  400. DcTopPredictor(dst, stride, 32, above, left);
  401. }
  402. private static unsafe void DcTopPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  403. {
  404. int i, r, expectedDc, sum = 0;
  405. for (i = 0; i < bs; i++)
  406. {
  407. sum += above[i];
  408. }
  409. expectedDc = (sum + (bs >> 1)) / bs;
  410. for (r = 0; r < bs; r++)
  411. {
  412. MemoryUtil.Fill(dst, (byte)expectedDc, bs);
  413. dst += stride;
  414. }
  415. }
  416. public static unsafe void DcPredictor4x4(byte* dst, int stride, byte* above, byte* left)
  417. {
  418. DcPredictor(dst, stride, 4, above, left);
  419. }
  420. public static unsafe void DcPredictor8x8(byte* dst, int stride, byte* above, byte* left)
  421. {
  422. DcPredictor(dst, stride, 8, above, left);
  423. }
  424. public static unsafe void DcPredictor16x16(byte* dst, int stride, byte* above, byte* left)
  425. {
  426. DcPredictor(dst, stride, 16, above, left);
  427. }
  428. public static unsafe void DcPredictor32x32(byte* dst, int stride, byte* above, byte* left)
  429. {
  430. DcPredictor(dst, stride, 32, above, left);
  431. }
  432. private static unsafe void DcPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
  433. {
  434. int i, r, expectedDc, sum = 0;
  435. int count = 2 * bs;
  436. for (i = 0; i < bs; i++)
  437. {
  438. sum += above[i];
  439. sum += left[i];
  440. }
  441. expectedDc = (sum + (count >> 1)) / count;
  442. for (r = 0; r < bs; r++)
  443. {
  444. MemoryUtil.Fill(dst, (byte)expectedDc, bs);
  445. dst += stride;
  446. }
  447. }
  448. public static unsafe void HePredictor4x4(byte* dst, int stride, byte* above, byte* left)
  449. {
  450. byte h = above[-1];
  451. byte I = left[0];
  452. byte j = left[1];
  453. byte k = left[2];
  454. byte l = left[3];
  455. MemoryUtil.Fill(dst + stride * 0, Avg3(h, I, j), 4);
  456. MemoryUtil.Fill(dst + stride * 1, Avg3(I, j, k), 4);
  457. MemoryUtil.Fill(dst + stride * 2, Avg3(j, k, l), 4);
  458. MemoryUtil.Fill(dst + stride * 3, Avg3(k, l, l), 4);
  459. }
  460. public static unsafe void VePredictor4x4(byte* dst, int stride, byte* above, byte* left)
  461. {
  462. byte h = above[-1];
  463. byte I = above[0];
  464. byte j = above[1];
  465. byte k = above[2];
  466. byte l = above[3];
  467. byte m = above[4];
  468. dst[0] = Avg3(h, I, j);
  469. dst[1] = Avg3(I, j, k);
  470. dst[2] = Avg3(j, k, l);
  471. dst[3] = Avg3(k, l, m);
  472. MemoryUtil.Copy(dst + stride * 1, dst, 4);
  473. MemoryUtil.Copy(dst + stride * 2, dst, 4);
  474. MemoryUtil.Copy(dst + stride * 3, dst, 4);
  475. }
  476. public static unsafe void D207Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  477. {
  478. byte I = left[0];
  479. byte j = left[1];
  480. byte k = left[2];
  481. byte l = left[3];
  482. Dst(dst, stride, 0, 0) = Avg2(I, j);
  483. Dst(dst, stride, 2, 0) = Dst(dst, stride, 0, 1) = Avg2(j, k);
  484. Dst(dst, stride, 2, 1) = Dst(dst, stride, 0, 2) = Avg2(k, l);
  485. Dst(dst, stride, 1, 0) = Avg3(I, j, k);
  486. Dst(dst, stride, 3, 0) = Dst(dst, stride, 1, 1) = Avg3(j, k, l);
  487. Dst(dst, stride, 3, 1) = Dst(dst, stride, 1, 2) = Avg3(k, l, l);
  488. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) = Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
  489. }
  490. public static unsafe void D63Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  491. {
  492. byte a = above[0];
  493. byte b = above[1];
  494. byte c = above[2];
  495. byte d = above[3];
  496. byte e = above[4];
  497. byte f = above[5];
  498. byte g = above[6];
  499. Dst(dst, stride, 0, 0) = Avg2(a, b);
  500. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 2) = Avg2(b, c);
  501. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 2) = Avg2(c, d);
  502. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 2) = Avg2(d, e);
  503. Dst(dst, stride, 3, 2) = Avg2(e, f); // Differs from vp8
  504. Dst(dst, stride, 0, 1) = Avg3(a, b, c);
  505. Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 3) = Avg3(b, c, d);
  506. Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 3) = Avg3(c, d, e);
  507. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 3) = Avg3(d, e, f);
  508. Dst(dst, stride, 3, 3) = Avg3(e, f, g); // Differs from vp8
  509. }
  510. public static unsafe void D63ePredictor4x4(byte* dst, int stride, byte* above, byte* left)
  511. {
  512. byte a = above[0];
  513. byte b = above[1];
  514. byte c = above[2];
  515. byte d = above[3];
  516. byte e = above[4];
  517. byte f = above[5];
  518. byte g = above[6];
  519. byte h = above[7];
  520. Dst(dst, stride, 0, 0) = Avg2(a, b);
  521. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 2) = Avg2(b, c);
  522. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 2) = Avg2(c, d);
  523. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 2) = Avg2(d, e);
  524. Dst(dst, stride, 3, 2) = Avg3(e, f, g);
  525. Dst(dst, stride, 0, 1) = Avg3(a, b, c);
  526. Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 3) = Avg3(b, c, d);
  527. Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 3) = Avg3(c, d, e);
  528. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 3) = Avg3(d, e, f);
  529. Dst(dst, stride, 3, 3) = Avg3(f, g, h);
  530. }
  531. public static unsafe void D45Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  532. {
  533. byte a = above[0];
  534. byte b = above[1];
  535. byte c = above[2];
  536. byte d = above[3];
  537. byte e = above[4];
  538. byte f = above[5];
  539. byte g = above[6];
  540. byte h = above[7];
  541. Dst(dst, stride, 0, 0) = Avg3(a, b, c);
  542. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
  543. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
  544. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
  545. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
  546. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
  547. Dst(dst, stride, 3, 3) = h; // differs from vp8
  548. }
  549. public static unsafe void D45ePredictor4x4(byte* dst, int stride, byte* above, byte* left)
  550. {
  551. byte a = above[0];
  552. byte b = above[1];
  553. byte c = above[2];
  554. byte d = above[3];
  555. byte e = above[4];
  556. byte f = above[5];
  557. byte g = above[6];
  558. byte h = above[7];
  559. Dst(dst, stride, 0, 0) = Avg3(a, b, c);
  560. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
  561. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
  562. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
  563. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
  564. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
  565. Dst(dst, stride, 3, 3) = Avg3(g, h, h);
  566. }
  567. public static unsafe void D117Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  568. {
  569. byte I = left[0];
  570. byte j = left[1];
  571. byte k = left[2];
  572. byte x = above[-1];
  573. byte a = above[0];
  574. byte b = above[1];
  575. byte c = above[2];
  576. byte d = above[3];
  577. Dst(dst, stride, 0, 0) = Dst(dst, stride, 1, 2) = Avg2(x, a);
  578. Dst(dst, stride, 1, 0) = Dst(dst, stride, 2, 2) = Avg2(a, b);
  579. Dst(dst, stride, 2, 0) = Dst(dst, stride, 3, 2) = Avg2(b, c);
  580. Dst(dst, stride, 3, 0) = Avg2(c, d);
  581. Dst(dst, stride, 0, 3) = Avg3(k, j, I);
  582. Dst(dst, stride, 0, 2) = Avg3(j, I, x);
  583. Dst(dst, stride, 0, 1) = Dst(dst, stride, 1, 3) = Avg3(I, x, a);
  584. Dst(dst, stride, 1, 1) = Dst(dst, stride, 2, 3) = Avg3(x, a, b);
  585. Dst(dst, stride, 2, 1) = Dst(dst, stride, 3, 3) = Avg3(a, b, c);
  586. Dst(dst, stride, 3, 1) = Avg3(b, c, d);
  587. }
  588. public static unsafe void D135Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  589. {
  590. byte I = left[0];
  591. byte j = left[1];
  592. byte k = left[2];
  593. byte l = left[3];
  594. byte x = above[-1];
  595. byte a = above[0];
  596. byte b = above[1];
  597. byte c = above[2];
  598. byte d = above[3];
  599. Dst(dst, stride, 0, 3) = Avg3(j, k, l);
  600. Dst(dst, stride, 1, 3) = Dst(dst, stride, 0, 2) = Avg3(I, j, k);
  601. Dst(dst, stride, 2, 3) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 1) = Avg3(x, I, j);
  602. Dst(dst, stride, 3, 3) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
  603. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 0) = Avg3(b, a, x);
  604. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 0) = Avg3(c, b, a);
  605. Dst(dst, stride, 3, 0) = Avg3(d, c, b);
  606. }
  607. public static unsafe void D153Predictor4x4(byte* dst, int stride, byte* above, byte* left)
  608. {
  609. byte I = left[0];
  610. byte j = left[1];
  611. byte k = left[2];
  612. byte l = left[3];
  613. byte x = above[-1];
  614. byte a = above[0];
  615. byte b = above[1];
  616. byte c = above[2];
  617. Dst(dst, stride, 0, 0) = Dst(dst, stride, 2, 1) = Avg2(I, x);
  618. Dst(dst, stride, 0, 1) = Dst(dst, stride, 2, 2) = Avg2(j, I);
  619. Dst(dst, stride, 0, 2) = Dst(dst, stride, 2, 3) = Avg2(k, j);
  620. Dst(dst, stride, 0, 3) = Avg2(l, k);
  621. Dst(dst, stride, 3, 0) = Avg3(a, b, c);
  622. Dst(dst, stride, 2, 0) = Avg3(x, a, b);
  623. Dst(dst, stride, 1, 0) = Dst(dst, stride, 3, 1) = Avg3(I, x, a);
  624. Dst(dst, stride, 1, 1) = Dst(dst, stride, 3, 2) = Avg3(j, I, x);
  625. Dst(dst, stride, 1, 2) = Dst(dst, stride, 3, 3) = Avg3(k, j, I);
  626. Dst(dst, stride, 1, 3) = Avg3(l, k, j);
  627. }
  628. public static unsafe void HighbdD207Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  629. {
  630. HighbdD207Predictor(dst, stride, 8, above, left, bd);
  631. }
  632. public static unsafe void HighbdD207Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  633. {
  634. HighbdD207Predictor(dst, stride, 16, above, left, bd);
  635. }
  636. public static unsafe void HighbdD207Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  637. {
  638. HighbdD207Predictor(dst, stride, 32, above, left, bd);
  639. }
  640. private static unsafe void HighbdD207Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  641. {
  642. int r, c;
  643. // First column.
  644. for (r = 0; r < bs - 1; ++r)
  645. {
  646. dst[r * stride] = Avg2(left[r], left[r + 1]);
  647. }
  648. dst[(bs - 1) * stride] = left[bs - 1];
  649. dst++;
  650. // Second column.
  651. for (r = 0; r < bs - 2; ++r)
  652. {
  653. dst[r * stride] = Avg3(left[r], left[r + 1], left[r + 2]);
  654. }
  655. dst[(bs - 2) * stride] = Avg3(left[bs - 2], left[bs - 1], left[bs - 1]);
  656. dst[(bs - 1) * stride] = left[bs - 1];
  657. dst++;
  658. // Rest of last row.
  659. for (c = 0; c < bs - 2; ++c)
  660. {
  661. dst[(bs - 1) * stride + c] = left[bs - 1];
  662. }
  663. for (r = bs - 2; r >= 0; --r)
  664. {
  665. for (c = 0; c < bs - 2; ++c)
  666. {
  667. dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
  668. }
  669. }
  670. }
  671. public static unsafe void HighbdD63Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  672. {
  673. HighbdD63Predictor(dst, stride, 8, above, left, bd);
  674. }
  675. public static unsafe void HighbdD63Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  676. {
  677. HighbdD63Predictor(dst, stride, 16, above, left, bd);
  678. }
  679. public static unsafe void HighbdD63Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  680. {
  681. HighbdD63Predictor(dst, stride, 32, above, left, bd);
  682. }
  683. private static unsafe void HighbdD63Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  684. {
  685. int r, c;
  686. int size;
  687. for (c = 0; c < bs; ++c)
  688. {
  689. dst[c] = Avg2(above[c], above[c + 1]);
  690. dst[stride + c] = Avg3(above[c], above[c + 1], above[c + 2]);
  691. }
  692. for (r = 2, size = bs - 2; r < bs; r += 2, --size)
  693. {
  694. MemoryUtil.Copy(dst + (r + 0) * stride, dst + (r >> 1), size);
  695. MemoryUtil.Fill(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
  696. MemoryUtil.Copy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
  697. MemoryUtil.Fill(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
  698. }
  699. }
  700. public static unsafe void HighbdD45Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  701. {
  702. HighbdD45Predictor(dst, stride, 8, above, left, bd);
  703. }
  704. public static unsafe void HighbdD45Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  705. {
  706. HighbdD45Predictor(dst, stride, 16, above, left, bd);
  707. }
  708. public static unsafe void HighbdD45Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  709. {
  710. HighbdD45Predictor(dst, stride, 32, above, left, bd);
  711. }
  712. private static unsafe void HighbdD45Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  713. {
  714. ushort aboveRight = above[bs - 1];
  715. ushort* dstRow0 = dst;
  716. int x, size;
  717. for (x = 0; x < bs - 1; ++x)
  718. {
  719. dst[x] = Avg3(above[x], above[x + 1], above[x + 2]);
  720. }
  721. dst[bs - 1] = aboveRight;
  722. dst += stride;
  723. for (x = 1, size = bs - 2; x < bs; ++x, --size)
  724. {
  725. MemoryUtil.Copy(dst, dstRow0 + x, size);
  726. MemoryUtil.Fill(dst + size, aboveRight, x + 1);
  727. dst += stride;
  728. }
  729. }
  730. public static unsafe void HighbdD117Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  731. {
  732. HighbdD117Predictor(dst, stride, 8, above, left, bd);
  733. }
  734. public static unsafe void HighbdD117Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  735. {
  736. HighbdD117Predictor(dst, stride, 16, above, left, bd);
  737. }
  738. public static unsafe void HighbdD117Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  739. {
  740. HighbdD117Predictor(dst, stride, 32, above, left, bd);
  741. }
  742. private static unsafe void HighbdD117Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  743. {
  744. int r, c;
  745. // First row
  746. for (c = 0; c < bs; c++)
  747. {
  748. dst[c] = Avg2(above[c - 1], above[c]);
  749. }
  750. dst += stride;
  751. // Second row
  752. dst[0] = Avg3(left[0], above[-1], above[0]);
  753. for (c = 1; c < bs; c++)
  754. {
  755. dst[c] = Avg3(above[c - 2], above[c - 1], above[c]);
  756. }
  757. dst += stride;
  758. // The rest of first col
  759. dst[0] = Avg3(above[-1], left[0], left[1]);
  760. for (r = 3; r < bs; ++r)
  761. {
  762. dst[(r - 2) * stride] = Avg3(left[r - 3], left[r - 2], left[r - 1]);
  763. }
  764. // The rest of the block
  765. for (r = 2; r < bs; ++r)
  766. {
  767. for (c = 1; c < bs; c++)
  768. {
  769. dst[c] = dst[-2 * stride + c - 1];
  770. }
  771. dst += stride;
  772. }
  773. }
  774. public static unsafe void HighbdD135Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  775. {
  776. HighbdD135Predictor(dst, stride, 8, above, left, bd);
  777. }
  778. public static unsafe void HighbdD135Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  779. {
  780. HighbdD135Predictor(dst, stride, 16, above, left, bd);
  781. }
  782. public static unsafe void HighbdD135Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  783. {
  784. HighbdD135Predictor(dst, stride, 32, above, left, bd);
  785. }
  786. private static unsafe void HighbdD135Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  787. {
  788. int i;
  789. ushort* border = stackalloc ushort[32 + 32 - 1]; // Outer border from bottom-left to top-right
  790. // Dst(dst, stride, bs, bs - 2)[0], i.e., border starting at bottom-left
  791. for (i = 0; i < bs - 2; ++i)
  792. {
  793. border[i] = Avg3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
  794. }
  795. border[bs - 2] = Avg3(above[-1], left[0], left[1]);
  796. border[bs - 1] = Avg3(left[0], above[-1], above[0]);
  797. border[bs - 0] = Avg3(above[-1], above[0], above[1]);
  798. // dst[0][2, size), i.e., remaining top border ascending
  799. for (i = 0; i < bs - 2; ++i)
  800. {
  801. border[bs + 1 + i] = Avg3(above[i], above[i + 1], above[i + 2]);
  802. }
  803. for (i = 0; i < bs; ++i)
  804. {
  805. MemoryUtil.Copy(dst + i * stride, border + bs - 1 - i, bs);
  806. }
  807. }
  808. public static unsafe void HighbdD153Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  809. {
  810. HighbdD153Predictor(dst, stride, 8, above, left, bd);
  811. }
  812. public static unsafe void HighbdD153Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  813. {
  814. HighbdD153Predictor(dst, stride, 16, above, left, bd);
  815. }
  816. public static unsafe void HighbdD153Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  817. {
  818. HighbdD153Predictor(dst, stride, 32, above, left, bd);
  819. }
  820. private static unsafe void HighbdD153Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  821. {
  822. int r, c;
  823. dst[0] = Avg2(above[-1], left[0]);
  824. for (r = 1; r < bs; r++)
  825. {
  826. dst[r * stride] = Avg2(left[r - 1], left[r]);
  827. }
  828. dst++;
  829. dst[0] = Avg3(left[0], above[-1], above[0]);
  830. dst[stride] = Avg3(above[-1], left[0], left[1]);
  831. for (r = 2; r < bs; r++)
  832. {
  833. dst[r * stride] = Avg3(left[r - 2], left[r - 1], left[r]);
  834. }
  835. dst++;
  836. for (c = 0; c < bs - 2; c++)
  837. {
  838. dst[c] = Avg3(above[c - 1], above[c], above[c + 1]);
  839. }
  840. dst += stride;
  841. for (r = 1; r < bs; ++r)
  842. {
  843. for (c = 0; c < bs - 2; c++)
  844. {
  845. dst[c] = dst[-stride + c - 2];
  846. }
  847. dst += stride;
  848. }
  849. }
  850. public static unsafe void HighbdVPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  851. {
  852. HighbdVPredictor(dst, stride, 4, above, left, bd);
  853. }
  854. public static unsafe void HighbdVPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  855. {
  856. HighbdVPredictor(dst, stride, 8, above, left, bd);
  857. }
  858. public static unsafe void HighbdVPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  859. {
  860. HighbdVPredictor(dst, stride, 16, above, left, bd);
  861. }
  862. public static unsafe void HighbdVPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  863. {
  864. HighbdVPredictor(dst, stride, 32, above, left, bd);
  865. }
  866. private static unsafe void HighbdVPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  867. {
  868. int r;
  869. for (r = 0; r < bs; r++)
  870. {
  871. MemoryUtil.Copy(dst, above, bs);
  872. dst += stride;
  873. }
  874. }
  875. public static unsafe void HighbdHPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  876. {
  877. HighbdHPredictor(dst, stride, 4, above, left, bd);
  878. }
  879. public static unsafe void HighbdHPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  880. {
  881. HighbdHPredictor(dst, stride, 8, above, left, bd);
  882. }
  883. public static unsafe void HighbdHPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  884. {
  885. HighbdHPredictor(dst, stride, 16, above, left, bd);
  886. }
  887. public static unsafe void HighbdHPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  888. {
  889. HighbdHPredictor(dst, stride, 32, above, left, bd);
  890. }
  891. private static unsafe void HighbdHPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  892. {
  893. int r;
  894. for (r = 0; r < bs; r++)
  895. {
  896. MemoryUtil.Fill(dst, left[r], bs);
  897. dst += stride;
  898. }
  899. }
  900. public static unsafe void HighbdTMPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  901. {
  902. HighbdTMPredictor(dst, stride, 4, above, left, bd);
  903. }
  904. public static unsafe void HighbdTMPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  905. {
  906. HighbdTMPredictor(dst, stride, 8, above, left, bd);
  907. }
  908. public static unsafe void HighbdTMPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  909. {
  910. HighbdTMPredictor(dst, stride, 16, above, left, bd);
  911. }
  912. public static unsafe void HighbdTMPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  913. {
  914. HighbdTMPredictor(dst, stride, 32, above, left, bd);
  915. }
  916. private static unsafe void HighbdTMPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  917. {
  918. int r, c;
  919. int yTopLeft = above[-1];
  920. for (r = 0; r < bs; r++)
  921. {
  922. for (c = 0; c < bs; c++)
  923. {
  924. dst[c] = BitUtils.ClipPixelHighbd(left[r] + above[c] - yTopLeft, bd);
  925. }
  926. dst += stride;
  927. }
  928. }
  929. public static unsafe void HighbdDc128Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  930. {
  931. HighbdDc128Predictor(dst, stride, 4, above, left, bd);
  932. }
  933. public static unsafe void HighbdDc128Predictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  934. {
  935. HighbdDc128Predictor(dst, stride, 8, above, left, bd);
  936. }
  937. public static unsafe void HighbdDc128Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  938. {
  939. HighbdDc128Predictor(dst, stride, 16, above, left, bd);
  940. }
  941. public static unsafe void HighbdDc128Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  942. {
  943. HighbdDc128Predictor(dst, stride, 32, above, left, bd);
  944. }
  945. private static unsafe void HighbdDc128Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  946. {
  947. int r;
  948. for (r = 0; r < bs; r++)
  949. {
  950. MemoryUtil.Fill(dst, (ushort)(128 << (bd - 8)), bs);
  951. dst += stride;
  952. }
  953. }
  954. public static unsafe void HighbdDcLeftPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  955. {
  956. HighbdDcLeftPredictor(dst, stride, 4, above, left, bd);
  957. }
  958. public static unsafe void HighbdDcLeftPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  959. {
  960. HighbdDcLeftPredictor(dst, stride, 8, above, left, bd);
  961. }
  962. public static unsafe void HighbdDcLeftPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  963. {
  964. HighbdDcLeftPredictor(dst, stride, 16, above, left, bd);
  965. }
  966. public static unsafe void HighbdDcLeftPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  967. {
  968. HighbdDcLeftPredictor(dst, stride, 32, above, left, bd);
  969. }
  970. private static unsafe void HighbdDcLeftPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  971. {
  972. int i, r, expectedDc, sum = 0;
  973. for (i = 0; i < bs; i++)
  974. {
  975. sum += left[i];
  976. }
  977. expectedDc = (sum + (bs >> 1)) / bs;
  978. for (r = 0; r < bs; r++)
  979. {
  980. MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
  981. dst += stride;
  982. }
  983. }
  984. public static unsafe void HighbdDcTopPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  985. {
  986. HighbdDcTopPredictor(dst, stride, 4, above, left, bd);
  987. }
  988. public static unsafe void HighbdDcTopPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  989. {
  990. HighbdDcTopPredictor(dst, stride, 8, above, left, bd);
  991. }
  992. public static unsafe void HighbdDcTopPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  993. {
  994. HighbdDcTopPredictor(dst, stride, 16, above, left, bd);
  995. }
  996. public static unsafe void HighbdDcTopPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  997. {
  998. HighbdDcTopPredictor(dst, stride, 32, above, left, bd);
  999. }
  1000. private static unsafe void HighbdDcTopPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  1001. {
  1002. int i, r, expectedDc, sum = 0;
  1003. for (i = 0; i < bs; i++)
  1004. {
  1005. sum += above[i];
  1006. }
  1007. expectedDc = (sum + (bs >> 1)) / bs;
  1008. for (r = 0; r < bs; r++)
  1009. {
  1010. MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
  1011. dst += stride;
  1012. }
  1013. }
  1014. public static unsafe void HighbdDcPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1015. {
  1016. HighbdDcPredictor(dst, stride, 4, above, left, bd);
  1017. }
  1018. public static unsafe void HighbdDcPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1019. {
  1020. HighbdDcPredictor(dst, stride, 8, above, left, bd);
  1021. }
  1022. public static unsafe void HighbdDcPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1023. {
  1024. HighbdDcPredictor(dst, stride, 16, above, left, bd);
  1025. }
  1026. public static unsafe void HighbdDcPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1027. {
  1028. HighbdDcPredictor(dst, stride, 32, above, left, bd);
  1029. }
  1030. private static unsafe void HighbdDcPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
  1031. {
  1032. int i, r, expectedDc, sum = 0;
  1033. int count = 2 * bs;
  1034. for (i = 0; i < bs; i++)
  1035. {
  1036. sum += above[i];
  1037. sum += left[i];
  1038. }
  1039. expectedDc = (sum + (count >> 1)) / count;
  1040. for (r = 0; r < bs; r++)
  1041. {
  1042. MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
  1043. dst += stride;
  1044. }
  1045. }
  1046. public static unsafe void HighbdD207Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1047. {
  1048. ushort I = left[0];
  1049. ushort j = left[1];
  1050. ushort k = left[2];
  1051. ushort l = left[3];
  1052. Dst(dst, stride, 0, 0) = Avg2(I, j);
  1053. Dst(dst, stride, 2, 0) = Dst(dst, stride, 0, 1) = Avg2(j, k);
  1054. Dst(dst, stride, 2, 1) = Dst(dst, stride, 0, 2) = Avg2(k, l);
  1055. Dst(dst, stride, 1, 0) = Avg3(I, j, k);
  1056. Dst(dst, stride, 3, 0) = Dst(dst, stride, 1, 1) = Avg3(j, k, l);
  1057. Dst(dst, stride, 3, 1) = Dst(dst, stride, 1, 2) = Avg3(k, l, l);
  1058. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) = Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
  1059. }
  1060. public static unsafe void HighbdD63Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1061. {
  1062. ushort a = above[0];
  1063. ushort b = above[1];
  1064. ushort c = above[2];
  1065. ushort d = above[3];
  1066. ushort e = above[4];
  1067. ushort f = above[5];
  1068. ushort g = above[6];
  1069. Dst(dst, stride, 0, 0) = Avg2(a, b);
  1070. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 2) = Avg2(b, c);
  1071. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 2) = Avg2(c, d);
  1072. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 2) = Avg2(d, e);
  1073. Dst(dst, stride, 3, 2) = Avg2(e, f); // Differs from vp8
  1074. Dst(dst, stride, 0, 1) = Avg3(a, b, c);
  1075. Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 3) = Avg3(b, c, d);
  1076. Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 3) = Avg3(c, d, e);
  1077. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 3) = Avg3(d, e, f);
  1078. Dst(dst, stride, 3, 3) = Avg3(e, f, g); // Differs from vp8
  1079. }
  1080. public static unsafe void HighbdD45Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1081. {
  1082. ushort a = above[0];
  1083. ushort b = above[1];
  1084. ushort c = above[2];
  1085. ushort d = above[3];
  1086. ushort e = above[4];
  1087. ushort f = above[5];
  1088. ushort g = above[6];
  1089. ushort h = above[7];
  1090. Dst(dst, stride, 0, 0) = Avg3(a, b, c);
  1091. Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
  1092. Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
  1093. Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
  1094. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
  1095. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
  1096. Dst(dst, stride, 3, 3) = h; // Differs from vp8
  1097. }
  1098. public static unsafe void HighbdD117Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1099. {
  1100. ushort I = left[0];
  1101. ushort j = left[1];
  1102. ushort k = left[2];
  1103. ushort x = above[-1];
  1104. ushort a = above[0];
  1105. ushort b = above[1];
  1106. ushort c = above[2];
  1107. ushort d = above[3];
  1108. Dst(dst, stride, 0, 0) = Dst(dst, stride, 1, 2) = Avg2(x, a);
  1109. Dst(dst, stride, 1, 0) = Dst(dst, stride, 2, 2) = Avg2(a, b);
  1110. Dst(dst, stride, 2, 0) = Dst(dst, stride, 3, 2) = Avg2(b, c);
  1111. Dst(dst, stride, 3, 0) = Avg2(c, d);
  1112. Dst(dst, stride, 0, 3) = Avg3(k, j, I);
  1113. Dst(dst, stride, 0, 2) = Avg3(j, I, x);
  1114. Dst(dst, stride, 0, 1) = Dst(dst, stride, 1, 3) = Avg3(I, x, a);
  1115. Dst(dst, stride, 1, 1) = Dst(dst, stride, 2, 3) = Avg3(x, a, b);
  1116. Dst(dst, stride, 2, 1) = Dst(dst, stride, 3, 3) = Avg3(a, b, c);
  1117. Dst(dst, stride, 3, 1) = Avg3(b, c, d);
  1118. }
  1119. public static unsafe void HighbdD135Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1120. {
  1121. ushort I = left[0];
  1122. ushort j = left[1];
  1123. ushort k = left[2];
  1124. ushort l = left[3];
  1125. ushort x = above[-1];
  1126. ushort a = above[0];
  1127. ushort b = above[1];
  1128. ushort c = above[2];
  1129. ushort d = above[3];
  1130. Dst(dst, stride, 0, 3) = Avg3(j, k, l);
  1131. Dst(dst, stride, 1, 3) = Dst(dst, stride, 0, 2) = Avg3(I, j, k);
  1132. Dst(dst, stride, 2, 3) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 1) = Avg3(x, I, j);
  1133. Dst(dst, stride, 3, 3) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
  1134. Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 0) = Avg3(b, a, x);
  1135. Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 0) = Avg3(c, b, a);
  1136. Dst(dst, stride, 3, 0) = Avg3(d, c, b);
  1137. }
  1138. public static unsafe void HighbdD153Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
  1139. {
  1140. ushort I = left[0];
  1141. ushort j = left[1];
  1142. ushort k = left[2];
  1143. ushort l = left[3];
  1144. ushort x = above[-1];
  1145. ushort a = above[0];
  1146. ushort b = above[1];
  1147. ushort c = above[2];
  1148. Dst(dst, stride, 0, 0) = Dst(dst, stride, 2, 1) = Avg2(I, x);
  1149. Dst(dst, stride, 0, 1) = Dst(dst, stride, 2, 2) = Avg2(j, I);
  1150. Dst(dst, stride, 0, 2) = Dst(dst, stride, 2, 3) = Avg2(k, j);
  1151. Dst(dst, stride, 0, 3) = Avg2(l, k);
  1152. Dst(dst, stride, 3, 0) = Avg3(a, b, c);
  1153. Dst(dst, stride, 2, 0) = Avg3(x, a, b);
  1154. Dst(dst, stride, 1, 0) = Dst(dst, stride, 3, 1) = Avg3(I, x, a);
  1155. Dst(dst, stride, 1, 1) = Dst(dst, stride, 3, 2) = Avg3(j, I, x);
  1156. Dst(dst, stride, 1, 2) = Dst(dst, stride, 3, 3) = Avg3(k, j, I);
  1157. Dst(dst, stride, 1, 3) = Avg3(l, k, j);
  1158. }
  1159. }
  1160. }