yuv2rgb.h 18 KB

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