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