yuv2rgb.h 19 KB

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