yuv2rgb.h 18 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /* Thirdparty code presumably from http://wss.co.uk/pinknoise/yuv2rgb/ */
  2. /*
  3. This YUV2RGB code is Copyright (C) 2008-11 Robin Watts
  4. <[email protected]>.
  5. The software is released under the BSD license.
  6. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
  10. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. In particular, I warrant absolutely nothing about how patent free
  18. this method is. It is your responsibility to ensure that this code
  19. does not infringe any patents that apply in your area before you
  20. ship it.
  21. */
  22. /*
  23. * Please note that this version has been modified for various reasons:
  24. * 1. Using the Godot core typedefs
  25. * 2. At some point or another the code relied on the byte order of a uint32_t, this has been fixed
  26. * 3. Output has been reordered to struct { uint8_t r, g, b, a; } precisely in accordance with the function names
  27. * 4. Removing unused 'dither' parameter
  28. * 5. Fix last line not being converted (and therefore was transparent)
  29. */
  30. #ifndef YUV2RGB_H
  31. #define YUV2RGB_H
  32. #include "core/typedefs.h"
  33. static const uint32_t tables[256*3] = {
  34. /* y_table */
  35. 0x7FFFFFEDU,
  36. 0x7FFFFFEFU,
  37. 0x7FFFFFF0U,
  38. 0x7FFFFFF1U,
  39. 0x7FFFFFF2U,
  40. 0x7FFFFFF3U,
  41. 0x7FFFFFF4U,
  42. 0x7FFFFFF6U,
  43. 0x7FFFFFF7U,
  44. 0x7FFFFFF8U,
  45. 0x7FFFFFF9U,
  46. 0x7FFFFFFAU,
  47. 0x7FFFFFFBU,
  48. 0x7FFFFFFDU,
  49. 0x7FFFFFFEU,
  50. 0x7FFFFFFFU,
  51. 0x80000000U,
  52. 0x80400801U,
  53. 0x80A01002U,
  54. 0x80E01803U,
  55. 0x81202805U,
  56. 0x81803006U,
  57. 0x81C03807U,
  58. 0x82004008U,
  59. 0x82604809U,
  60. 0x82A0500AU,
  61. 0x82E0600CU,
  62. 0x8340680DU,
  63. 0x8380700EU,
  64. 0x83C0780FU,
  65. 0x84208010U,
  66. 0x84608811U,
  67. 0x84A09813U,
  68. 0x8500A014U,
  69. 0x8540A815U,
  70. 0x8580B016U,
  71. 0x85E0B817U,
  72. 0x8620C018U,
  73. 0x8660D01AU,
  74. 0x86C0D81BU,
  75. 0x8700E01CU,
  76. 0x8740E81DU,
  77. 0x87A0F01EU,
  78. 0x87E0F81FU,
  79. 0x88210821U,
  80. 0x88811022U,
  81. 0x88C11823U,
  82. 0x89012024U,
  83. 0x89412825U,
  84. 0x89A13026U,
  85. 0x89E14028U,
  86. 0x8A214829U,
  87. 0x8A81502AU,
  88. 0x8AC1582BU,
  89. 0x8B01602CU,
  90. 0x8B61682DU,
  91. 0x8BA1782FU,
  92. 0x8BE18030U,
  93. 0x8C418831U,
  94. 0x8C819032U,
  95. 0x8CC19833U,
  96. 0x8D21A034U,
  97. 0x8D61B036U,
  98. 0x8DA1B837U,
  99. 0x8E01C038U,
  100. 0x8E41C839U,
  101. 0x8E81D03AU,
  102. 0x8EE1D83BU,
  103. 0x8F21E83DU,
  104. 0x8F61F03EU,
  105. 0x8FC1F83FU,
  106. 0x90020040U,
  107. 0x90420841U,
  108. 0x90A21042U,
  109. 0x90E22044U,
  110. 0x91222845U,
  111. 0x91823046U,
  112. 0x91C23847U,
  113. 0x92024048U,
  114. 0x92624849U,
  115. 0x92A2504AU,
  116. 0x92E2604CU,
  117. 0x9342684DU,
  118. 0x9382704EU,
  119. 0x93C2784FU,
  120. 0x94228050U,
  121. 0x94628851U,
  122. 0x94A29853U,
  123. 0x9502A054U,
  124. 0x9542A855U,
  125. 0x9582B056U,
  126. 0x95E2B857U,
  127. 0x9622C058U,
  128. 0x9662D05AU,
  129. 0x96C2D85BU,
  130. 0x9702E05CU,
  131. 0x9742E85DU,
  132. 0x97A2F05EU,
  133. 0x97E2F85FU,
  134. 0x98230861U,
  135. 0x98831062U,
  136. 0x98C31863U,
  137. 0x99032064U,
  138. 0x99632865U,
  139. 0x99A33066U,
  140. 0x99E34068U,
  141. 0x9A434869U,
  142. 0x9A83506AU,
  143. 0x9AC3586BU,
  144. 0x9B23606CU,
  145. 0x9B63686DU,
  146. 0x9BA3786FU,
  147. 0x9BE38070U,
  148. 0x9C438871U,
  149. 0x9C839072U,
  150. 0x9CC39873U,
  151. 0x9D23A074U,
  152. 0x9D63B076U,
  153. 0x9DA3B877U,
  154. 0x9E03C078U,
  155. 0x9E43C879U,
  156. 0x9E83D07AU,
  157. 0x9EE3D87BU,
  158. 0x9F23E87DU,
  159. 0x9F63F07EU,
  160. 0x9FC3F87FU,
  161. 0xA0040080U,
  162. 0xA0440881U,
  163. 0xA0A41082U,
  164. 0xA0E42084U,
  165. 0xA1242885U,
  166. 0xA1843086U,
  167. 0xA1C43887U,
  168. 0xA2044088U,
  169. 0xA2644889U,
  170. 0xA2A4588BU,
  171. 0xA2E4608CU,
  172. 0xA344688DU,
  173. 0xA384708EU,
  174. 0xA3C4788FU,
  175. 0xA4248090U,
  176. 0xA4649092U,
  177. 0xA4A49893U,
  178. 0xA504A094U,
  179. 0xA544A895U,
  180. 0xA584B096U,
  181. 0xA5E4B897U,
  182. 0xA624C098U,
  183. 0xA664D09AU,
  184. 0xA6C4D89BU,
  185. 0xA704E09CU,
  186. 0xA744E89DU,
  187. 0xA7A4F09EU,
  188. 0xA7E4F89FU,
  189. 0xA82508A1U,
  190. 0xA88510A2U,
  191. 0xA8C518A3U,
  192. 0xA90520A4U,
  193. 0xA96528A5U,
  194. 0xA9A530A6U,
  195. 0xA9E540A8U,
  196. 0xAA4548A9U,
  197. 0xAA8550AAU,
  198. 0xAAC558ABU,
  199. 0xAB2560ACU,
  200. 0xAB6568ADU,
  201. 0xABA578AFU,
  202. 0xAC0580B0U,
  203. 0xAC4588B1U,
  204. 0xAC8590B2U,
  205. 0xACE598B3U,
  206. 0xAD25A0B4U,
  207. 0xAD65B0B6U,
  208. 0xADA5B8B7U,
  209. 0xAE05C0B8U,
  210. 0xAE45C8B9U,
  211. 0xAE85D0BAU,
  212. 0xAEE5D8BBU,
  213. 0xAF25E8BDU,
  214. 0xAF65F0BEU,
  215. 0xAFC5F8BFU,
  216. 0xB00600C0U,
  217. 0xB04608C1U,
  218. 0xB0A610C2U,
  219. 0xB0E620C4U,
  220. 0xB12628C5U,
  221. 0xB18630C6U,
  222. 0xB1C638C7U,
  223. 0xB20640C8U,
  224. 0xB26648C9U,
  225. 0xB2A658CBU,
  226. 0xB2E660CCU,
  227. 0xB34668CDU,
  228. 0xB38670CEU,
  229. 0xB3C678CFU,
  230. 0xB42680D0U,
  231. 0xB46690D2U,
  232. 0xB4A698D3U,
  233. 0xB506A0D4U,
  234. 0xB546A8D5U,
  235. 0xB586B0D6U,
  236. 0xB5E6B8D7U,
  237. 0xB626C8D9U,
  238. 0xB666D0DAU,
  239. 0xB6C6D8DBU,
  240. 0xB706E0DCU,
  241. 0xB746E8DDU,
  242. 0xB7A6F0DEU,
  243. 0xB7E6F8DFU,
  244. 0xB82708E1U,
  245. 0xB88710E2U,
  246. 0xB8C718E3U,
  247. 0xB90720E4U,
  248. 0xB96728E5U,
  249. 0xB9A730E6U,
  250. 0xB9E740E8U,
  251. 0xBA4748E9U,
  252. 0xBA8750EAU,
  253. 0xBAC758EBU,
  254. 0xBB2760ECU,
  255. 0xBB6768EDU,
  256. 0xBBA778EFU,
  257. 0xBC0780F0U,
  258. 0xBC4788F1U,
  259. 0xBC8790F2U,
  260. 0xBCE798F3U,
  261. 0xBD27A0F4U,
  262. 0xBD67B0F6U,
  263. 0xBDC7B8F7U,
  264. 0xBE07C0F8U,
  265. 0xBE47C8F9U,
  266. 0xBEA7D0FAU,
  267. 0xBEE7D8FBU,
  268. 0xBF27E8FDU,
  269. 0xBF87F0FEU,
  270. 0xBFC7F8FFU,
  271. 0xC0080100U,
  272. 0xC0480901U,
  273. 0xC0A81102U,
  274. 0xC0E82104U,
  275. 0xC0E82104U,
  276. 0xC0E82104U,
  277. 0xC0E82104U,
  278. 0xC0E82104U,
  279. 0xC0E82104U,
  280. 0xC0E82104U,
  281. 0xC0E82104U,
  282. 0xC0E82104U,
  283. 0xC0E82104U,
  284. 0xC0E82104U,
  285. 0xC0E82104U,
  286. 0xC0E82104U,
  287. 0xC0E82104U,
  288. 0xC0E82104U,
  289. 0xC0E82104U,
  290. 0xC0E82104U,
  291. /* u_table */
  292. 0x0C400103U,
  293. 0x0C200105U,
  294. 0x0C200107U,
  295. 0x0C000109U,
  296. 0x0BE0010BU,
  297. 0x0BC0010DU,
  298. 0x0BA0010FU,
  299. 0x0BA00111U,
  300. 0x0B800113U,
  301. 0x0B600115U,
  302. 0x0B400117U,
  303. 0x0B400119U,
  304. 0x0B20011BU,
  305. 0x0B00011DU,
  306. 0x0AE0011FU,
  307. 0x0AE00121U,
  308. 0x0AC00123U,
  309. 0x0AA00125U,
  310. 0x0A800127U,
  311. 0x0A600129U,
  312. 0x0A60012BU,
  313. 0x0A40012DU,
  314. 0x0A20012FU,
  315. 0x0A000131U,
  316. 0x0A000132U,
  317. 0x09E00134U,
  318. 0x09C00136U,
  319. 0x09A00138U,
  320. 0x09A0013AU,
  321. 0x0980013CU,
  322. 0x0960013EU,
  323. 0x09400140U,
  324. 0x09400142U,
  325. 0x09200144U,
  326. 0x09000146U,
  327. 0x08E00148U,
  328. 0x08C0014AU,
  329. 0x08C0014CU,
  330. 0x08A0014EU,
  331. 0x08800150U,
  332. 0x08600152U,
  333. 0x08600154U,
  334. 0x08400156U,
  335. 0x08200158U,
  336. 0x0800015AU,
  337. 0x0800015CU,
  338. 0x07E0015EU,
  339. 0x07C00160U,
  340. 0x07A00162U,
  341. 0x07A00164U,
  342. 0x07800166U,
  343. 0x07600168U,
  344. 0x0740016AU,
  345. 0x0720016CU,
  346. 0x0720016EU,
  347. 0x07000170U,
  348. 0x06E00172U,
  349. 0x06C00174U,
  350. 0x06C00176U,
  351. 0x06A00178U,
  352. 0x0680017AU,
  353. 0x0660017CU,
  354. 0x0660017EU,
  355. 0x06400180U,
  356. 0x06200182U,
  357. 0x06000184U,
  358. 0x05E00185U,
  359. 0x05E00187U,
  360. 0x05C00189U,
  361. 0x05A0018BU,
  362. 0x0580018DU,
  363. 0x0580018FU,
  364. 0x05600191U,
  365. 0x05400193U,
  366. 0x05200195U,
  367. 0x05200197U,
  368. 0x05000199U,
  369. 0x04E0019BU,
  370. 0x04C0019DU,
  371. 0x04C0019FU,
  372. 0x04A001A1U,
  373. 0x048001A3U,
  374. 0x046001A5U,
  375. 0x044001A7U,
  376. 0x044001A9U,
  377. 0x042001ABU,
  378. 0x040001ADU,
  379. 0x03E001AFU,
  380. 0x03E001B1U,
  381. 0x03C001B3U,
  382. 0x03A001B5U,
  383. 0x038001B7U,
  384. 0x038001B9U,
  385. 0x036001BBU,
  386. 0x034001BDU,
  387. 0x032001BFU,
  388. 0x032001C1U,
  389. 0x030001C3U,
  390. 0x02E001C5U,
  391. 0x02C001C7U,
  392. 0x02A001C9U,
  393. 0x02A001CBU,
  394. 0x028001CDU,
  395. 0x026001CFU,
  396. 0x024001D1U,
  397. 0x024001D3U,
  398. 0x022001D5U,
  399. 0x020001D7U,
  400. 0x01E001D8U,
  401. 0x01E001DAU,
  402. 0x01C001DCU,
  403. 0x01A001DEU,
  404. 0x018001E0U,
  405. 0x016001E2U,
  406. 0x016001E4U,
  407. 0x014001E6U,
  408. 0x012001E8U,
  409. 0x010001EAU,
  410. 0x010001ECU,
  411. 0x00E001EEU,
  412. 0x00C001F0U,
  413. 0x00A001F2U,
  414. 0x00A001F4U,
  415. 0x008001F6U,
  416. 0x006001F8U,
  417. 0x004001FAU,
  418. 0x004001FCU,
  419. 0x002001FEU,
  420. 0x00000200U,
  421. 0xFFE00202U,
  422. 0xFFC00204U,
  423. 0xFFC00206U,
  424. 0xFFA00208U,
  425. 0xFF80020AU,
  426. 0xFF60020CU,
  427. 0xFF60020EU,
  428. 0xFF400210U,
  429. 0xFF200212U,
  430. 0xFF000214U,
  431. 0xFF000216U,
  432. 0xFEE00218U,
  433. 0xFEC0021AU,
  434. 0xFEA0021CU,
  435. 0xFEA0021EU,
  436. 0xFE800220U,
  437. 0xFE600222U,
  438. 0xFE400224U,
  439. 0xFE200226U,
  440. 0xFE200228U,
  441. 0xFE000229U,
  442. 0xFDE0022BU,
  443. 0xFDC0022DU,
  444. 0xFDC0022FU,
  445. 0xFDA00231U,
  446. 0xFD800233U,
  447. 0xFD600235U,
  448. 0xFD600237U,
  449. 0xFD400239U,
  450. 0xFD20023BU,
  451. 0xFD00023DU,
  452. 0xFCE0023FU,
  453. 0xFCE00241U,
  454. 0xFCC00243U,
  455. 0xFCA00245U,
  456. 0xFC800247U,
  457. 0xFC800249U,
  458. 0xFC60024BU,
  459. 0xFC40024DU,
  460. 0xFC20024FU,
  461. 0xFC200251U,
  462. 0xFC000253U,
  463. 0xFBE00255U,
  464. 0xFBC00257U,
  465. 0xFBC00259U,
  466. 0xFBA0025BU,
  467. 0xFB80025DU,
  468. 0xFB60025FU,
  469. 0xFB400261U,
  470. 0xFB400263U,
  471. 0xFB200265U,
  472. 0xFB000267U,
  473. 0xFAE00269U,
  474. 0xFAE0026BU,
  475. 0xFAC0026DU,
  476. 0xFAA0026FU,
  477. 0xFA800271U,
  478. 0xFA800273U,
  479. 0xFA600275U,
  480. 0xFA400277U,
  481. 0xFA200279U,
  482. 0xFA20027BU,
  483. 0xFA00027CU,
  484. 0xF9E0027EU,
  485. 0xF9C00280U,
  486. 0xF9A00282U,
  487. 0xF9A00284U,
  488. 0xF9800286U,
  489. 0xF9600288U,
  490. 0xF940028AU,
  491. 0xF940028CU,
  492. 0xF920028EU,
  493. 0xF9000290U,
  494. 0xF8E00292U,
  495. 0xF8E00294U,
  496. 0xF8C00296U,
  497. 0xF8A00298U,
  498. 0xF880029AU,
  499. 0xF860029CU,
  500. 0xF860029EU,
  501. 0xF84002A0U,
  502. 0xF82002A2U,
  503. 0xF80002A4U,
  504. 0xF80002A6U,
  505. 0xF7E002A8U,
  506. 0xF7C002AAU,
  507. 0xF7A002ACU,
  508. 0xF7A002AEU,
  509. 0xF78002B0U,
  510. 0xF76002B2U,
  511. 0xF74002B4U,
  512. 0xF74002B6U,
  513. 0xF72002B8U,
  514. 0xF70002BAU,
  515. 0xF6E002BCU,
  516. 0xF6C002BEU,
  517. 0xF6C002C0U,
  518. 0xF6A002C2U,
  519. 0xF68002C4U,
  520. 0xF66002C6U,
  521. 0xF66002C8U,
  522. 0xF64002CAU,
  523. 0xF62002CCU,
  524. 0xF60002CEU,
  525. 0xF60002CFU,
  526. 0xF5E002D1U,
  527. 0xF5C002D3U,
  528. 0xF5A002D5U,
  529. 0xF5A002D7U,
  530. 0xF58002D9U,
  531. 0xF56002DBU,
  532. 0xF54002DDU,
  533. 0xF52002DFU,
  534. 0xF52002E1U,
  535. 0xF50002E3U,
  536. 0xF4E002E5U,
  537. 0xF4C002E7U,
  538. 0xF4C002E9U,
  539. 0xF4A002EBU,
  540. 0xF48002EDU,
  541. 0xF46002EFU,
  542. 0xF46002F1U,
  543. 0xF44002F3U,
  544. 0xF42002F5U,
  545. 0xF40002F7U,
  546. 0xF3E002F9U,
  547. 0xF3E002FBU,
  548. /* v_table */
  549. 0x1A09A000U,
  550. 0x19E9A800U,
  551. 0x19A9B800U,
  552. 0x1969C800U,
  553. 0x1949D000U,
  554. 0x1909E000U,
  555. 0x18C9E800U,
  556. 0x18A9F800U,
  557. 0x186A0000U,
  558. 0x182A1000U,
  559. 0x180A2000U,
  560. 0x17CA2800U,
  561. 0x17AA3800U,
  562. 0x176A4000U,
  563. 0x172A5000U,
  564. 0x170A6000U,
  565. 0x16CA6800U,
  566. 0x168A7800U,
  567. 0x166A8000U,
  568. 0x162A9000U,
  569. 0x160AA000U,
  570. 0x15CAA800U,
  571. 0x158AB800U,
  572. 0x156AC000U,
  573. 0x152AD000U,
  574. 0x14EAE000U,
  575. 0x14CAE800U,
  576. 0x148AF800U,
  577. 0x146B0000U,
  578. 0x142B1000U,
  579. 0x13EB2000U,
  580. 0x13CB2800U,
  581. 0x138B3800U,
  582. 0x134B4000U,
  583. 0x132B5000U,
  584. 0x12EB6000U,
  585. 0x12CB6800U,
  586. 0x128B7800U,
  587. 0x124B8000U,
  588. 0x122B9000U,
  589. 0x11EBA000U,
  590. 0x11ABA800U,
  591. 0x118BB800U,
  592. 0x114BC000U,
  593. 0x112BD000U,
  594. 0x10EBE000U,
  595. 0x10ABE800U,
  596. 0x108BF800U,
  597. 0x104C0000U,
  598. 0x100C1000U,
  599. 0x0FEC2000U,
  600. 0x0FAC2800U,
  601. 0x0F8C3800U,
  602. 0x0F4C4000U,
  603. 0x0F0C5000U,
  604. 0x0EEC5800U,
  605. 0x0EAC6800U,
  606. 0x0E6C7800U,
  607. 0x0E4C8000U,
  608. 0x0E0C9000U,
  609. 0x0DEC9800U,
  610. 0x0DACA800U,
  611. 0x0D6CB800U,
  612. 0x0D4CC000U,
  613. 0x0D0CD000U,
  614. 0x0CCCD800U,
  615. 0x0CACE800U,
  616. 0x0C6CF800U,
  617. 0x0C4D0000U,
  618. 0x0C0D1000U,
  619. 0x0BCD1800U,
  620. 0x0BAD2800U,
  621. 0x0B6D3800U,
  622. 0x0B2D4000U,
  623. 0x0B0D5000U,
  624. 0x0ACD5800U,
  625. 0x0AAD6800U,
  626. 0x0A6D7800U,
  627. 0x0A2D8000U,
  628. 0x0A0D9000U,
  629. 0x09CD9800U,
  630. 0x098DA800U,
  631. 0x096DB800U,
  632. 0x092DC000U,
  633. 0x090DD000U,
  634. 0x08CDD800U,
  635. 0x088DE800U,
  636. 0x086DF800U,
  637. 0x082E0000U,
  638. 0x07EE1000U,
  639. 0x07CE1800U,
  640. 0x078E2800U,
  641. 0x076E3800U,
  642. 0x072E4000U,
  643. 0x06EE5000U,
  644. 0x06CE5800U,
  645. 0x068E6800U,
  646. 0x064E7800U,
  647. 0x062E8000U,
  648. 0x05EE9000U,
  649. 0x05CE9800U,
  650. 0x058EA800U,
  651. 0x054EB800U,
  652. 0x052EC000U,
  653. 0x04EED000U,
  654. 0x04AED800U,
  655. 0x048EE800U,
  656. 0x044EF000U,
  657. 0x042F0000U,
  658. 0x03EF1000U,
  659. 0x03AF1800U,
  660. 0x038F2800U,
  661. 0x034F3000U,
  662. 0x030F4000U,
  663. 0x02EF5000U,
  664. 0x02AF5800U,
  665. 0x028F6800U,
  666. 0x024F7000U,
  667. 0x020F8000U,
  668. 0x01EF9000U,
  669. 0x01AF9800U,
  670. 0x016FA800U,
  671. 0x014FB000U,
  672. 0x010FC000U,
  673. 0x00EFD000U,
  674. 0x00AFD800U,
  675. 0x006FE800U,
  676. 0x004FF000U,
  677. 0x00100000U,
  678. 0xFFD01000U,
  679. 0xFFB01800U,
  680. 0xFF702800U,
  681. 0xFF303000U,
  682. 0xFF104000U,
  683. 0xFED05000U,
  684. 0xFEB05800U,
  685. 0xFE706800U,
  686. 0xFE307000U,
  687. 0xFE108000U,
  688. 0xFDD09000U,
  689. 0xFD909800U,
  690. 0xFD70A800U,
  691. 0xFD30B000U,
  692. 0xFD10C000U,
  693. 0xFCD0D000U,
  694. 0xFC90D800U,
  695. 0xFC70E800U,
  696. 0xFC30F000U,
  697. 0xFBF10000U,
  698. 0xFBD11000U,
  699. 0xFB911800U,
  700. 0xFB712800U,
  701. 0xFB313000U,
  702. 0xFAF14000U,
  703. 0xFAD14800U,
  704. 0xFA915800U,
  705. 0xFA516800U,
  706. 0xFA317000U,
  707. 0xF9F18000U,
  708. 0xF9D18800U,
  709. 0xF9919800U,
  710. 0xF951A800U,
  711. 0xF931B000U,
  712. 0xF8F1C000U,
  713. 0xF8B1C800U,
  714. 0xF891D800U,
  715. 0xF851E800U,
  716. 0xF831F000U,
  717. 0xF7F20000U,
  718. 0xF7B20800U,
  719. 0xF7921800U,
  720. 0xF7522800U,
  721. 0xF7123000U,
  722. 0xF6F24000U,
  723. 0xF6B24800U,
  724. 0xF6925800U,
  725. 0xF6526800U,
  726. 0xF6127000U,
  727. 0xF5F28000U,
  728. 0xF5B28800U,
  729. 0xF5729800U,
  730. 0xF552A800U,
  731. 0xF512B000U,
  732. 0xF4F2C000U,
  733. 0xF4B2C800U,
  734. 0xF472D800U,
  735. 0xF452E800U,
  736. 0xF412F000U,
  737. 0xF3D30000U,
  738. 0xF3B30800U,
  739. 0xF3731800U,
  740. 0xF3532800U,
  741. 0xF3133000U,
  742. 0xF2D34000U,
  743. 0xF2B34800U,
  744. 0xF2735800U,
  745. 0xF2336800U,
  746. 0xF2137000U,
  747. 0xF1D38000U,
  748. 0xF1B38800U,
  749. 0xF1739800U,
  750. 0xF133A800U,
  751. 0xF113B000U,
  752. 0xF0D3C000U,
  753. 0xF093C800U,
  754. 0xF073D800U,
  755. 0xF033E000U,
  756. 0xF013F000U,
  757. 0xEFD40000U,
  758. 0xEF940800U,
  759. 0xEF741800U,
  760. 0xEF342000U,
  761. 0xEEF43000U,
  762. 0xEED44000U,
  763. 0xEE944800U,
  764. 0xEE745800U,
  765. 0xEE346000U,
  766. 0xEDF47000U,
  767. 0xEDD48000U,
  768. 0xED948800U,
  769. 0xED549800U,
  770. 0xED34A000U,
  771. 0xECF4B000U,
  772. 0xECD4C000U,
  773. 0xEC94C800U,
  774. 0xEC54D800U,
  775. 0xEC34E000U,
  776. 0xEBF4F000U,
  777. 0xEBB50000U,
  778. 0xEB950800U,
  779. 0xEB551800U,
  780. 0xEB352000U,
  781. 0xEAF53000U,
  782. 0xEAB54000U,
  783. 0xEA954800U,
  784. 0xEA555800U,
  785. 0xEA156000U,
  786. 0xE9F57000U,
  787. 0xE9B58000U,
  788. 0xE9958800U,
  789. 0xE9559800U,
  790. 0xE915A000U,
  791. 0xE8F5B000U,
  792. 0xE8B5C000U,
  793. 0xE875C800U,
  794. 0xE855D800U,
  795. 0xE815E000U,
  796. 0xE7F5F000U,
  797. 0xE7B60000U,
  798. 0xE7760800U,
  799. 0xE7561800U,
  800. 0xE7162000U,
  801. 0xE6D63000U,
  802. 0xE6B64000U,
  803. 0xE6764800U,
  804. 0xE6365800U
  805. };
  806. /* -- Common -- */
  807. #define FLAGS 0x40080100
  808. #define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)])
  809. #define READY(Y) tables[Y]
  810. #define FIXUP(Y) \
  811. do { \
  812. int tmp = (Y) & FLAGS; \
  813. if (tmp != 0) \
  814. { \
  815. tmp -= tmp>>8; \
  816. (Y) |= tmp; \
  817. tmp = FLAGS & ~(Y>>1); \
  818. (Y) += tmp>>8; \
  819. } \
  820. } while (0 == 1)
  821. #define STORE(Y,DSTPTR) \
  822. do { \
  823. *(DSTPTR)++ = (Y)>>11; \
  824. *(DSTPTR)++ = (Y)>>22; \
  825. *(DSTPTR)++ = (Y); \
  826. *(DSTPTR)++ = 255; \
  827. } while (0 == 1)
  828. /* -- End Common -- */
  829. static void yuv422_2_rgb8888(uint8_t *dst_ptr,
  830. const uint8_t *y_ptr,
  831. const uint8_t *u_ptr,
  832. const uint8_t *v_ptr,
  833. int32_t width,
  834. int32_t height,
  835. int32_t y_span,
  836. int32_t uv_span,
  837. int32_t dst_span)
  838. {
  839. while (height > 0)
  840. {
  841. height -= width<<16;
  842. height += 1<<16;
  843. while (height < 0)
  844. {
  845. /* Do top row pair */
  846. uint32_t uv, y0, y1;
  847. uv = READUV(*u_ptr++,*v_ptr++);
  848. y0 = uv + READY(*y_ptr++);
  849. y1 = uv + READY(*y_ptr++);
  850. FIXUP(y0);
  851. FIXUP(y1);
  852. STORE(y0, dst_ptr);
  853. STORE(y1, dst_ptr);
  854. height += (2<<16);
  855. }
  856. if ((height>>16) == 0)
  857. {
  858. /* Trailing top row pix */
  859. uint32_t uv, y0;
  860. uv = READUV(*u_ptr,*v_ptr);
  861. y0 = uv + READY(*y_ptr++);
  862. FIXUP(y0);
  863. STORE(y0, dst_ptr);
  864. }
  865. dst_ptr += dst_span-width*4;
  866. y_ptr += y_span-width;
  867. u_ptr += uv_span-(width>>1);
  868. v_ptr += uv_span-(width>>1);
  869. height = (height<<16)>>16;
  870. height -= 1;
  871. if (height == 0)
  872. break;
  873. height -= width<<16;
  874. height += 1<<16;
  875. while (height < 0)
  876. {
  877. /* Do second row pair */
  878. uint32_t uv, y0, y1;
  879. uv = READUV(*u_ptr++,*v_ptr++);
  880. y0 = uv + READY(*y_ptr++);
  881. y1 = uv + READY(*y_ptr++);
  882. FIXUP(y0);
  883. FIXUP(y1);
  884. STORE(y0, dst_ptr);
  885. STORE(y1, dst_ptr);
  886. height += (2<<16);
  887. }
  888. if ((height>>16) == 0)
  889. {
  890. /* Trailing bottom row pix */
  891. uint32_t uv, y0;
  892. uv = READUV(*u_ptr,*v_ptr);
  893. y0 = uv + READY(*y_ptr++);
  894. FIXUP(y0);
  895. STORE(y0, dst_ptr);
  896. }
  897. dst_ptr += dst_span-width*4;
  898. y_ptr += y_span-width;
  899. u_ptr += uv_span-(width>>1);
  900. v_ptr += uv_span-(width>>1);
  901. height = (height<<16)>>16;
  902. height -= 1;
  903. }
  904. }
  905. static void yuv420_2_rgb8888(uint8_t *dst_ptr,
  906. const uint8_t *y_ptr,
  907. const uint8_t *u_ptr,
  908. const uint8_t *v_ptr,
  909. int32_t width,
  910. int32_t height,
  911. int32_t y_span,
  912. int32_t uv_span,
  913. int32_t dst_span)
  914. {
  915. /* The 'dst_ptr as uint32_t' thing is not endianness-aware, so that's been removed. */
  916. height -= 1;
  917. while (height > 0)
  918. {
  919. height -= width<<16;
  920. height += 1<<16;
  921. while (height < 0)
  922. {
  923. /* Do 2 column pairs */
  924. uint32_t uv, y0, y1;
  925. uint8_t * dst_ptr_1span = dst_ptr + dst_span;
  926. uv = READUV(*u_ptr++,*v_ptr++);
  927. y1 = uv + READY(y_ptr[y_span]);
  928. y0 = uv + READY(*y_ptr++);
  929. FIXUP(y1);
  930. FIXUP(y0);
  931. STORE(y1, dst_ptr_1span);
  932. STORE(y0, dst_ptr);
  933. y1 = uv + READY(y_ptr[y_span]);
  934. y0 = uv + READY(*y_ptr++);
  935. FIXUP(y1);
  936. FIXUP(y0);
  937. STORE(y1, dst_ptr_1span);
  938. STORE(y0, dst_ptr);
  939. height += (2<<16);
  940. }
  941. if ((height>>16) == 0)
  942. {
  943. /* Trailing column pair */
  944. uint32_t uv, y0, y1;
  945. uint8_t * dst_ptr_1span = dst_ptr + dst_span;
  946. uv = READUV(*u_ptr,*v_ptr);
  947. y1 = uv + READY(y_ptr[y_span]);
  948. y0 = uv + READY(*y_ptr++);
  949. FIXUP(y1);
  950. FIXUP(y0);
  951. STORE(y0, dst_ptr_1span);
  952. STORE(y1, dst_ptr);
  953. }
  954. dst_ptr += (dst_span * 2) - (width * 4);
  955. y_ptr += y_span*2-width;
  956. u_ptr += uv_span-(width>>1);
  957. v_ptr += uv_span-(width>>1);
  958. height = (height<<16)>>16;
  959. height -= 2;
  960. }
  961. if (height == 0)
  962. {
  963. /* Trail row */
  964. height -= width<<16;
  965. height += 1<<16;
  966. while (height < 0)
  967. {
  968. /* Do a row pair */
  969. uint32_t uv, y0, y1;
  970. uv = READUV(*u_ptr++,*v_ptr++);
  971. y1 = uv + READY(*y_ptr++);
  972. y0 = uv + READY(*y_ptr++);
  973. FIXUP(y1);
  974. FIXUP(y0);
  975. STORE(y1, dst_ptr);
  976. STORE(y0, dst_ptr);
  977. height += (2<<16);
  978. }
  979. if ((height>>16) == 0)
  980. {
  981. /* Trailing pix */
  982. uint32_t uv, y0;
  983. uv = READUV(*u_ptr++,*v_ptr++);
  984. y0 = uv + READY(*y_ptr++);
  985. FIXUP(y0);
  986. STORE(y0, dst_ptr);
  987. }
  988. }
  989. }
  990. static void yuv444_2_rgb8888(uint8_t *dst_ptr,
  991. const uint8_t *y_ptr,
  992. const uint8_t *u_ptr,
  993. const uint8_t *v_ptr,
  994. int32_t width,
  995. int32_t height,
  996. int32_t y_span,
  997. int32_t uv_span,
  998. int32_t dst_span)
  999. {
  1000. while (height > 0)
  1001. {
  1002. height -= width<<16;
  1003. height += 1<<16;
  1004. while (height < 0)
  1005. {
  1006. /* Do top row pair */
  1007. uint32_t uv, y0, y1;
  1008. uv = READUV(*u_ptr++,*v_ptr++);
  1009. y0 = uv + READY(*y_ptr++);
  1010. FIXUP(y0);
  1011. STORE(y0, dst_ptr);
  1012. uv = READUV(*u_ptr++,*v_ptr++);
  1013. y1 = uv + READY(*y_ptr++);
  1014. FIXUP(y1);
  1015. STORE(y1, dst_ptr);
  1016. height += (2<<16);
  1017. }
  1018. if ((height>>16) == 0)
  1019. {
  1020. /* Trailing top row pix */
  1021. uint32_t uv, y0;
  1022. uv = READUV(*u_ptr++,*v_ptr++);
  1023. y0 = uv + READY(*y_ptr++);
  1024. FIXUP(y0);
  1025. STORE(y0, dst_ptr);
  1026. }
  1027. dst_ptr += dst_span-width*4;
  1028. y_ptr += y_span-width;
  1029. u_ptr += uv_span-width;
  1030. v_ptr += uv_span-width;
  1031. height = (height<<16)>>16;
  1032. height -= 1;
  1033. if (height == 0)
  1034. break;
  1035. height -= width<<16;
  1036. height += 1<<16;
  1037. while (height < 0)
  1038. {
  1039. /* Do second row pair */
  1040. uint32_t uv, y0, y1;
  1041. uv = READUV(*u_ptr++,*v_ptr++);
  1042. y0 = uv + READY(*y_ptr++);
  1043. FIXUP(y0);
  1044. STORE(y0, dst_ptr);
  1045. uv = READUV(*u_ptr++,*v_ptr++);
  1046. y1 = uv + READY(*y_ptr++);
  1047. FIXUP(y1);
  1048. STORE(y1, dst_ptr);
  1049. height += (2<<16);
  1050. }
  1051. if ((height>>16) == 0)
  1052. {
  1053. /* Trailing bottom row pix */
  1054. uint32_t uv, y0;
  1055. uv = READUV(*u_ptr++,*v_ptr++);
  1056. y0 = uv + READY(*y_ptr++);
  1057. FIXUP(y0);
  1058. STORE(y0, dst_ptr);
  1059. }
  1060. dst_ptr += dst_span-width*4;
  1061. y_ptr += y_span-width;
  1062. u_ptr += uv_span-width;
  1063. v_ptr += uv_span-width;
  1064. height = (height<<16)>>16;
  1065. height -= 1;
  1066. }
  1067. }
  1068. #undef FLAGS
  1069. #undef READUV
  1070. #undef READY
  1071. #undef FIXUP
  1072. #undef STORE
  1073. #endif // YUV2RGB_H