1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28
29 /**
30 * @file
31 * YUV and RGB subsampled formats conversion.
32 *
33 * @author Jose Fonseca <jfonseca@vmware.com>
34 */
35
36
37 #include "util/u_debug.h"
38 #include "util/format/u_format_yuv.h"
39
40
41 void
util_format_r8g8_b8g8_unorm_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)42 util_format_r8g8_b8g8_unorm_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
43 const uint8_t *restrict src_row, unsigned src_stride,
44 unsigned width, unsigned height)
45 {
46 unsigned x, y;
47
48 for (y = 0; y < height; y += 1) {
49 float *dst = dst_row;
50 const uint32_t *src = (const uint32_t *)src_row;
51 uint32_t value;
52 float r, g0, g1, b;
53
54 for (x = 0; x + 1 < width; x += 2) {
55 value = util_cpu_to_le32(*src++);
56
57 r = ubyte_to_float((value >> 0) & 0xff);
58 g0 = ubyte_to_float((value >> 8) & 0xff);
59 b = ubyte_to_float((value >> 16) & 0xff);
60 g1 = ubyte_to_float((value >> 24) & 0xff);
61
62 dst[0] = r; /* r */
63 dst[1] = g0; /* g */
64 dst[2] = b; /* b */
65 dst[3] = 1.0f; /* a */
66 dst += 4;
67
68 dst[0] = r; /* r */
69 dst[1] = g1; /* g */
70 dst[2] = b; /* b */
71 dst[3] = 1.0f; /* a */
72 dst += 4;
73 }
74
75 if (x < width) {
76 value = util_cpu_to_le32(*src);
77
78 r = ubyte_to_float((value >> 0) & 0xff);
79 g0 = ubyte_to_float((value >> 8) & 0xff);
80 b = ubyte_to_float((value >> 16) & 0xff);
81 g1 = ubyte_to_float((value >> 24) & 0xff);
82
83 dst[0] = r; /* r */
84 dst[1] = g0; /* g */
85 dst[2] = b; /* b */
86 dst[3] = 1.0f; /* a */
87 }
88
89 src_row = (uint8_t *)src_row + src_stride;
90 dst_row = (uint8_t *)dst_row + dst_stride;
91 }
92 }
93
94
95 void
util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)96 util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
97 const uint8_t *restrict src_row, unsigned src_stride,
98 unsigned width, unsigned height)
99 {
100 unsigned x, y;
101
102 for (y = 0; y < height; y += 1) {
103 uint8_t *dst = dst_row;
104 const uint32_t *src = (const uint32_t *)src_row;
105 uint32_t value;
106 uint8_t r, g0, g1, b;
107
108 for (x = 0; x + 1 < width; x += 2) {
109 value = util_cpu_to_le32(*src++);
110
111 r = (value >> 0) & 0xff;
112 g0 = (value >> 8) & 0xff;
113 b = (value >> 16) & 0xff;
114 g1 = (value >> 24) & 0xff;
115
116 dst[0] = r; /* r */
117 dst[1] = g0; /* g */
118 dst[2] = b; /* b */
119 dst[3] = 0xff; /* a */
120 dst += 4;
121
122 dst[0] = r; /* r */
123 dst[1] = g1; /* g */
124 dst[2] = b; /* b */
125 dst[3] = 0xff; /* a */
126 dst += 4;
127 }
128
129 if (x < width) {
130 value = util_cpu_to_le32(*src);
131
132 r = (value >> 0) & 0xff;
133 g0 = (value >> 8) & 0xff;
134 b = (value >> 16) & 0xff;
135 g1 = (value >> 24) & 0xff;
136
137 dst[0] = r; /* r */
138 dst[1] = g0; /* g */
139 dst[2] = b; /* b */
140 dst[3] = 0xff; /* a */
141 }
142
143 src_row += src_stride/sizeof(*src_row);
144 dst_row += dst_stride/sizeof(*dst_row);
145 }
146 }
147
148
149 void
util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)150 util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
151 const float *restrict src_row, unsigned src_stride,
152 unsigned width, unsigned height)
153 {
154 unsigned x, y;
155
156 for (y = 0; y < height; y += 1) {
157 const float *src = src_row;
158 uint32_t *dst = (uint32_t *)dst_row;
159 float r, g0, g1, b;
160 uint32_t value;
161
162 for (x = 0; x + 1 < width; x += 2) {
163 r = 0.5f*(src[0] + src[4]);
164 g0 = src[1];
165 g1 = src[5];
166 b = 0.5f*(src[2] + src[6]);
167
168 value = (uint32_t)float_to_ubyte(r);
169 value |= (uint32_t)float_to_ubyte(g0) << 8;
170 value |= (uint32_t)float_to_ubyte(b) << 16;
171 value |= (uint32_t)float_to_ubyte(g1) << 24;
172
173 *dst++ = util_le32_to_cpu(value);
174
175 src += 8;
176 }
177
178 if (x < width) {
179 r = src[0];
180 g0 = src[1];
181 g1 = 0;
182 b = src[2];
183
184 value = (uint32_t)float_to_ubyte(r);
185 value |= (uint32_t)float_to_ubyte(g0) << 8;
186 value |= (uint32_t)float_to_ubyte(b) << 16;
187 value |= (uint32_t)float_to_ubyte(g1) << 24;
188
189 *dst = util_le32_to_cpu(value);
190 }
191
192 dst_row += dst_stride/sizeof(*dst_row);
193 src_row += src_stride/sizeof(*src_row);
194 }
195 }
196
197
198 void
util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)199 util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
200 const uint8_t *restrict src_row, unsigned src_stride,
201 unsigned width, unsigned height)
202 {
203 unsigned x, y;
204
205 for (y = 0; y < height; y += 1) {
206 const uint8_t *src = src_row;
207 uint32_t *dst = (uint32_t *)dst_row;
208 uint32_t r, g0, g1, b;
209 uint32_t value;
210
211 for (x = 0; x + 1 < width; x += 2) {
212 r = (src[0] + src[4] + 1) >> 1;
213 g0 = src[1];
214 g1 = src[5];
215 b = (src[2] + src[6] + 1) >> 1;
216
217 value = r;
218 value |= (uint32_t)g0 << 8;
219 value |= (uint32_t)b << 16;
220 value |= (uint32_t)g1 << 24;
221
222 *dst++ = util_le32_to_cpu(value);
223
224 src += 8;
225 }
226
227 if (x < width) {
228 r = src[0];
229 g0 = src[1];
230 g1 = 0;
231 b = src[2];
232
233 value = r;
234 value |= (uint32_t)g0 << 8;
235 value |= (uint32_t)b << 16;
236 value |= (uint32_t)g1 << 24;
237
238 *dst = util_le32_to_cpu(value);
239 }
240
241 dst_row += dst_stride/sizeof(*dst_row);
242 src_row += src_stride/sizeof(*src_row);
243 }
244 }
245
246
247 void
util_format_r8g8_b8g8_unorm_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)248 util_format_r8g8_b8g8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
249 unsigned i, ASSERTED unsigned j)
250 {
251 float *dst = in_dst;
252
253 assert(i < 2);
254 assert(j < 1);
255
256 dst[0] = ubyte_to_float(src[0]); /* r */
257 dst[1] = ubyte_to_float(src[1 + 2*i]); /* g */
258 dst[2] = ubyte_to_float(src[2]); /* b */
259 dst[3] = 1.0f; /* a */
260 }
261
262
263 void
util_format_g8r8_g8b8_unorm_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)264 util_format_g8r8_g8b8_unorm_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
265 const uint8_t *restrict src_row, unsigned src_stride,
266 unsigned width, unsigned height)
267 {
268 unsigned x, y;
269
270 for (y = 0; y < height; y += 1) {
271 float *dst = dst_row;
272 const uint32_t *src = (const uint32_t *)src_row;
273 uint32_t value;
274 float r, g0, g1, b;
275
276 for (x = 0; x + 1 < width; x += 2) {
277 value = util_cpu_to_le32(*src++);
278
279 g0 = ubyte_to_float((value >> 0) & 0xff);
280 r = ubyte_to_float((value >> 8) & 0xff);
281 g1 = ubyte_to_float((value >> 16) & 0xff);
282 b = ubyte_to_float((value >> 24) & 0xff);
283
284 dst[0] = r; /* r */
285 dst[1] = g0; /* g */
286 dst[2] = b; /* b */
287 dst[3] = 1.0f; /* a */
288 dst += 4;
289
290 dst[0] = r; /* r */
291 dst[1] = g1; /* g */
292 dst[2] = b; /* b */
293 dst[3] = 1.0f; /* a */
294 dst += 4;
295 }
296
297 if (x < width) {
298 value = util_cpu_to_le32(*src);
299
300 g0 = ubyte_to_float((value >> 0) & 0xff);
301 r = ubyte_to_float((value >> 8) & 0xff);
302 g1 = ubyte_to_float((value >> 16) & 0xff);
303 b = ubyte_to_float((value >> 24) & 0xff);
304
305 dst[0] = r; /* r */
306 dst[1] = g0; /* g */
307 dst[2] = b; /* b */
308 dst[3] = 1.0f; /* a */
309 }
310
311 src_row = (uint8_t *)src_row + src_stride;
312 dst_row = (uint8_t *)dst_row + dst_stride;
313 }
314 }
315
316
317 void
util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)318 util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
319 const uint8_t *restrict src_row, unsigned src_stride,
320 unsigned width, unsigned height)
321 {
322 unsigned x, y;
323
324 for (y = 0; y < height; y += 1) {
325 uint8_t *dst = dst_row;
326 const uint32_t *src = (const uint32_t *)src_row;
327 uint32_t value;
328 uint8_t r, g0, g1, b;
329
330 for (x = 0; x + 1 < width; x += 2) {
331 value = util_cpu_to_le32(*src++);
332
333 g0 = (value >> 0) & 0xff;
334 r = (value >> 8) & 0xff;
335 g1 = (value >> 16) & 0xff;
336 b = (value >> 24) & 0xff;
337
338 dst[0] = r; /* r */
339 dst[1] = g0; /* g */
340 dst[2] = b; /* b */
341 dst[3] = 0xff; /* a */
342 dst += 4;
343
344 dst[0] = r; /* r */
345 dst[1] = g1; /* g */
346 dst[2] = b; /* b */
347 dst[3] = 0xff; /* a */
348 dst += 4;
349 }
350
351 if (x < width) {
352 value = util_cpu_to_le32(*src);
353
354 g0 = (value >> 0) & 0xff;
355 r = (value >> 8) & 0xff;
356 g1 = (value >> 16) & 0xff;
357 b = (value >> 24) & 0xff;
358
359 dst[0] = r; /* r */
360 dst[1] = g0; /* g */
361 dst[2] = b; /* b */
362 dst[3] = 0xff; /* a */
363 }
364
365 src_row += src_stride/sizeof(*src_row);
366 dst_row += dst_stride/sizeof(*dst_row);
367 }
368 }
369
370
371 void
util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)372 util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
373 const float *restrict src_row, unsigned src_stride,
374 unsigned width, unsigned height)
375 {
376 unsigned x, y;
377
378 for (y = 0; y < height; y += 1) {
379 const float *src = src_row;
380 uint32_t *dst = (uint32_t *)dst_row;
381 float r, g0, g1, b;
382 uint32_t value;
383
384 for (x = 0; x + 1 < width; x += 2) {
385 r = 0.5f*(src[0] + src[4]);
386 g0 = src[1];
387 g1 = src[5];
388 b = 0.5f*(src[2] + src[6]);
389
390 value = (uint32_t)float_to_ubyte(g0);
391 value |= (uint32_t)float_to_ubyte(r) << 8;
392 value |= (uint32_t)float_to_ubyte(g1) << 16;
393 value |= (uint32_t)float_to_ubyte(b) << 24;
394
395 *dst++ = util_le32_to_cpu(value);
396
397 src += 8;
398 }
399
400 if (x < width) {
401 r = src[0];
402 g0 = src[1];
403 g1 = 0;
404 b = src[2];
405
406 value = (uint32_t)float_to_ubyte(g0);
407 value |= (uint32_t)float_to_ubyte(r) << 8;
408 value |= (uint32_t)float_to_ubyte(g1) << 16;
409 value |= (uint32_t)float_to_ubyte(b) << 24;
410
411 *dst = util_le32_to_cpu(value);
412 }
413
414 dst_row += dst_stride/sizeof(*dst_row);
415 src_row += src_stride/sizeof(*src_row);
416 }
417 }
418
419
420 void
util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)421 util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
422 const uint8_t *restrict src_row, unsigned src_stride,
423 unsigned width, unsigned height)
424 {
425 unsigned x, y;
426
427 for (y = 0; y < height; y += 1) {
428 const uint8_t *src = src_row;
429 uint32_t *dst = (uint32_t *)dst_row;
430 uint32_t r, g0, g1, b;
431 uint32_t value;
432
433 for (x = 0; x + 1 < width; x += 2) {
434 r = (src[0] + src[4] + 1) >> 1;
435 g0 = src[1];
436 g1 = src[5];
437 b = (src[2] + src[6] + 1) >> 1;
438
439 value = g0;
440 value |= (uint32_t)r << 8;
441 value |= (uint32_t)g1 << 16;
442 value |= (uint32_t)b << 24;
443
444 *dst++ = util_le32_to_cpu(value);
445
446 src += 8;
447 }
448
449 if (x < width) {
450 r = src[0];
451 g0 = src[1];
452 g1 = 0;
453 b = src[2];
454
455 value = g0;
456 value |= (uint32_t)r << 8;
457 value |= (uint32_t)g1 << 16;
458 value |= (uint32_t)b << 24;
459
460 *dst = util_le32_to_cpu(value);
461 }
462
463 dst_row += dst_stride/sizeof(*dst_row);
464 src_row += src_stride/sizeof(*src_row);
465 }
466 }
467
468
469 void
util_format_g8r8_g8b8_unorm_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)470 util_format_g8r8_g8b8_unorm_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
471 unsigned i, ASSERTED unsigned j)
472 {
473 float *dst = in_dst;
474
475 assert(i < 2);
476 assert(j < 1);
477
478 dst[0] = ubyte_to_float(src[1]); /* r */
479 dst[1] = ubyte_to_float(src[0 + 2*i]); /* g */
480 dst[2] = ubyte_to_float(src[3]); /* b */
481 dst[3] = 1.0f; /* a */
482 }
483
484
485 void
util_format_uyvy_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)486 util_format_uyvy_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
487 const uint8_t *restrict src_row, unsigned src_stride,
488 unsigned width, unsigned height)
489 {
490 unsigned x, y;
491
492 for (y = 0; y < height; y += 1) {
493 float *dst = dst_row;
494 const uint32_t *src = (const uint32_t *)src_row;
495 uint32_t value;
496 uint8_t y0, y1, u, v;
497
498 for (x = 0; x + 1 < width; x += 2) {
499 value = util_cpu_to_le32(*src++);
500
501 u = (value >> 0) & 0xff;
502 y0 = (value >> 8) & 0xff;
503 v = (value >> 16) & 0xff;
504 y1 = (value >> 24) & 0xff;
505
506 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
507 dst[3] = 1.0f; /* a */
508 dst += 4;
509
510 util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
511 dst[3] = 1.0f; /* a */
512 dst += 4;
513 }
514
515 if (x < width) {
516 value = util_cpu_to_le32(*src);
517
518 u = (value >> 0) & 0xff;
519 y0 = (value >> 8) & 0xff;
520 v = (value >> 16) & 0xff;
521 y1 = (value >> 24) & 0xff;
522
523 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
524 dst[3] = 1.0f; /* a */
525 }
526
527 src_row = (uint8_t *)src_row + src_stride;
528 dst_row = (uint8_t *)dst_row + dst_stride;
529 }
530 }
531
532 void
util_format_vyuy_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)533 util_format_vyuy_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
534 const uint8_t *restrict src_row, unsigned src_stride,
535 unsigned width, unsigned height)
536 {
537 unsigned x, y;
538
539 for (y = 0; y < height; y += 1) {
540 float *dst = dst_row;
541 const uint32_t *src = (const uint32_t *)src_row;
542 uint32_t value;
543 uint8_t y0, y1, u, v;
544
545 for (x = 0; x + 1 < width; x += 2) {
546 value = util_cpu_to_le32(*src++);
547
548 v = (value >> 0) & 0xff;
549 y0 = (value >> 8) & 0xff;
550 u = (value >> 16) & 0xff;
551 y1 = (value >> 24) & 0xff;
552
553 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
554 dst[3] = 1.0f; /* a */
555 dst += 4;
556
557 util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
558 dst[3] = 1.0f; /* a */
559 dst += 4;
560 }
561
562 if (x < width) {
563 value = util_cpu_to_le32(*src);
564
565 v = (value >> 0) & 0xff;
566 y0 = (value >> 8) & 0xff;
567 u = (value >> 16) & 0xff;
568 y1 = (value >> 24) & 0xff;
569
570 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
571 dst[3] = 1.0f; /* a */
572 }
573
574 src_row = (uint8_t *)src_row + src_stride;
575 dst_row = (uint8_t *)dst_row + dst_stride;
576 }
577 }
578
579 void
util_format_uyvy_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)580 util_format_uyvy_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
581 const uint8_t *restrict src_row, unsigned src_stride,
582 unsigned width, unsigned height)
583 {
584 unsigned x, y;
585
586 for (y = 0; y < height; y += 1) {
587 uint8_t *dst = dst_row;
588 const uint32_t *src = (const uint32_t *)src_row;
589 uint32_t value;
590 uint8_t y0, y1, u, v;
591
592 for (x = 0; x + 1 < width; x += 2) {
593 value = util_cpu_to_le32(*src++);
594
595 u = (value >> 0) & 0xff;
596 y0 = (value >> 8) & 0xff;
597 v = (value >> 16) & 0xff;
598 y1 = (value >> 24) & 0xff;
599
600 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
601 dst[3] = 0xff; /* a */
602 dst += 4;
603
604 util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
605 dst[3] = 0xff; /* a */
606 dst += 4;
607 }
608
609 if (x < width) {
610 value = util_cpu_to_le32(*src);
611
612 u = (value >> 0) & 0xff;
613 y0 = (value >> 8) & 0xff;
614 v = (value >> 16) & 0xff;
615 y1 = (value >> 24) & 0xff;
616
617 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
618 dst[3] = 0xff; /* a */
619 }
620
621 src_row += src_stride/sizeof(*src_row);
622 dst_row += dst_stride/sizeof(*dst_row);
623 }
624 }
625
626 void
util_format_vyuy_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)627 util_format_vyuy_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
628 const uint8_t *restrict src_row, unsigned src_stride,
629 unsigned width, unsigned height)
630 {
631 unsigned x, y;
632
633 for (y = 0; y < height; y += 1) {
634 uint8_t *dst = dst_row;
635 const uint32_t *src = (const uint32_t *)src_row;
636 uint32_t value;
637 uint8_t y0, y1, u, v;
638
639 for (x = 0; x + 1 < width; x += 2) {
640 value = util_cpu_to_le32(*src++);
641
642 v = (value >> 0) & 0xff;
643 y0 = (value >> 8) & 0xff;
644 u = (value >> 16) & 0xff;
645 y1 = (value >> 24) & 0xff;
646
647 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
648 dst[3] = 0xff; /* a */
649 dst += 4;
650
651 util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
652 dst[3] = 0xff; /* a */
653 dst += 4;
654 }
655
656 if (x < width) {
657 value = util_cpu_to_le32(*src);
658
659 v = (value >> 0) & 0xff;
660 y0 = (value >> 8) & 0xff;
661 u = (value >> 16) & 0xff;
662 y1 = (value >> 24) & 0xff;
663
664 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
665 dst[3] = 0xff; /* a */
666 }
667
668 src_row += src_stride/sizeof(*src_row);
669 dst_row += dst_stride/sizeof(*dst_row);
670 }
671 }
672
673 void
util_format_uyvy_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)674 util_format_uyvy_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
675 const float *restrict src_row, unsigned src_stride,
676 unsigned width, unsigned height)
677 {
678 unsigned x, y;
679
680 for (y = 0; y < height; y += 1) {
681 const float *src = src_row;
682 uint32_t *dst = (uint32_t *)dst_row;
683 uint8_t y0, y1, u, v;
684 uint32_t value;
685
686 for (x = 0; x + 1 < width; x += 2) {
687 uint8_t y0, y1, u0, u1, v0, v1, u, v;
688
689 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
690 &y0, &u0, &v0);
691 util_format_rgb_float_to_yuv(src[4], src[5], src[6],
692 &y1, &u1, &v1);
693
694 u = (u0 + u1 + 1) >> 1;
695 v = (v0 + v1 + 1) >> 1;
696
697 value = u;
698 value |= (uint32_t)y0 << 8;
699 value |= (uint32_t)v << 16;
700 value |= (uint32_t)y1 << 24;
701
702 *dst++ = util_le32_to_cpu(value);
703
704 src += 8;
705 }
706
707 if (x < width) {
708 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
709 &y0, &u, &v);
710 y1 = 0;
711
712 value = u;
713 value |= (uint32_t)y0 << 8;
714 value |= (uint32_t)v << 16;
715 value |= (uint32_t)y1 << 24;
716
717 *dst = util_le32_to_cpu(value);
718 }
719
720 dst_row += dst_stride/sizeof(*dst_row);
721 src_row += src_stride/sizeof(*src_row);
722 }
723 }
724
725 void
util_format_vyuy_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)726 util_format_vyuy_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
727 const float *restrict src_row, unsigned src_stride,
728 unsigned width, unsigned height)
729 {
730 unsigned x, y;
731
732 for (y = 0; y < height; y += 1) {
733 const float *src = src_row;
734 uint32_t *dst = (uint32_t *)dst_row;
735 uint8_t y0, y1, u, v;
736 uint32_t value;
737
738 for (x = 0; x + 1 < width; x += 2) {
739 uint8_t y0, y1, u0, u1, v0, v1, u, v;
740
741 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
742 &y0, &u0, &v0);
743 util_format_rgb_float_to_yuv(src[4], src[5], src[6],
744 &y1, &u1, &v1);
745
746 u = (u0 + u1 + 1) >> 1;
747 v = (v0 + v1 + 1) >> 1;
748
749 value = v;
750 value |= (uint32_t)y0 << 8;
751 value |= (uint32_t)u << 16;
752 value |= (uint32_t)y1 << 24;
753
754 *dst++ = util_le32_to_cpu(value);
755
756 src += 8;
757 }
758
759 if (x < width) {
760 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
761 &y0, &u, &v);
762 y1 = 0;
763
764 value = v;
765 value |= (uint32_t)y0 << 8;
766 value |= (uint32_t)u << 16;
767 value |= (uint32_t)y1 << 24;
768
769 *dst = util_le32_to_cpu(value);
770 }
771
772 dst_row += dst_stride/sizeof(*dst_row);
773 src_row += src_stride/sizeof(*src_row);
774 }
775 }
776
777
778 void
util_format_uyvy_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)779 util_format_uyvy_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
780 const uint8_t *restrict src_row, unsigned src_stride,
781 unsigned width, unsigned height)
782 {
783 unsigned x, y;
784
785 for (y = 0; y < height; y += 1) {
786 const uint8_t *src = src_row;
787 uint32_t *dst = (uint32_t *)dst_row;
788 uint8_t y0, y1, u, v;
789 uint32_t value;
790
791 for (x = 0; x + 1 < width; x += 2) {
792 uint8_t y0, y1, u0, u1, v0, v1, u, v;
793
794 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
795 &y0, &u0, &v0);
796 util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
797 &y1, &u1, &v1);
798
799 u = (u0 + u1 + 1) >> 1;
800 v = (v0 + v1 + 1) >> 1;
801
802 value = u;
803 value |= (uint32_t)y0 << 8;
804 value |= (uint32_t)v << 16;
805 value |= (uint32_t)y1 << 24;
806
807 *dst++ = util_le32_to_cpu(value);
808
809 src += 8;
810 }
811
812 if (x < width) {
813 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
814 &y0, &u, &v);
815 y1 = 0;
816
817 value = u;
818 value |= (uint32_t)y0 << 8;
819 value |= (uint32_t)v << 16;
820 value |= (uint32_t)y1 << 24;
821
822 *dst = util_le32_to_cpu(value);
823 }
824
825 dst_row += dst_stride/sizeof(*dst_row);
826 src_row += src_stride/sizeof(*src_row);
827 }
828 }
829
830 void
util_format_vyuy_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)831 util_format_vyuy_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
832 const uint8_t *restrict src_row, unsigned src_stride,
833 unsigned width, unsigned height)
834 {
835 unsigned x, y;
836
837 for (y = 0; y < height; y += 1) {
838 const uint8_t *src = src_row;
839 uint32_t *dst = (uint32_t *)dst_row;
840 uint8_t y0, y1, u, v;
841 uint32_t value;
842
843 for (x = 0; x + 1 < width; x += 2) {
844 uint8_t y0, y1, u0, u1, v0, v1, u, v;
845
846 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
847 &y0, &u0, &v0);
848 util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
849 &y1, &u1, &v1);
850
851 u = (u0 + u1 + 1) >> 1;
852 v = (v0 + v1 + 1) >> 1;
853
854 value = v;
855 value |= (uint32_t)y0 << 8;
856 value |= (uint32_t)u << 16;
857 value |= (uint32_t)y1 << 24;
858
859 *dst++ = util_le32_to_cpu(value);
860
861 src += 8;
862 }
863
864 if (x < width) {
865 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
866 &y0, &u, &v);
867 y1 = 0;
868
869 value = v;
870 value |= (uint32_t)y0 << 8;
871 value |= (uint32_t)u << 16;
872 value |= (uint32_t)y1 << 24;
873
874 *dst = util_le32_to_cpu(value);
875 }
876
877 dst_row += dst_stride/sizeof(*dst_row);
878 src_row += src_stride/sizeof(*src_row);
879 }
880 }
881
882 void
util_format_uyvy_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)883 util_format_uyvy_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
884 unsigned i, ASSERTED unsigned j)
885 {
886 float *dst = in_dst;
887 uint8_t y, u, v;
888
889 assert(i < 2);
890 assert(j < 1);
891
892 y = src[1 + i*2];
893 u = src[0];
894 v = src[2];
895
896 util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
897
898 dst[3] = 1.0f;
899 }
900
901
902 void
util_format_vyuy_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)903 util_format_vyuy_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
904 unsigned i, ASSERTED unsigned j)
905 {
906 float *dst = in_dst;
907 uint8_t y, u, v;
908
909 assert(i < 2);
910 assert(j < 1);
911
912 y = src[1 + i*2];
913 v = src[0];
914 u = src[2];
915
916 util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
917
918 dst[3] = 1.0f;
919 }
920
921
922 void
util_format_yuyv_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)923 util_format_yuyv_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
924 const uint8_t *restrict src_row, unsigned src_stride,
925 unsigned width, unsigned height)
926 {
927 unsigned x, y;
928
929 for (y = 0; y < height; y += 1) {
930 float *dst = dst_row;
931 const uint32_t *src = (const uint32_t *)src_row;
932 uint32_t value;
933 uint8_t y0, y1, u, v;
934
935 for (x = 0; x + 1 < width; x += 2) {
936 value = util_cpu_to_le32(*src++);
937
938 y0 = (value >> 0) & 0xff;
939 u = (value >> 8) & 0xff;
940 y1 = (value >> 16) & 0xff;
941 v = (value >> 24) & 0xff;
942
943 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
944 dst[3] = 1.0f; /* a */
945 dst += 4;
946
947 util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
948 dst[3] = 1.0f; /* a */
949 dst += 4;
950 }
951
952 if (x < width) {
953 value = util_cpu_to_le32(*src);
954
955 y0 = (value >> 0) & 0xff;
956 u = (value >> 8) & 0xff;
957 y1 = (value >> 16) & 0xff;
958 v = (value >> 24) & 0xff;
959
960 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
961 dst[3] = 1.0f; /* a */
962 }
963
964 src_row = (uint8_t *)src_row + src_stride;
965 dst_row = (uint8_t *)dst_row + dst_stride;
966 }
967 }
968
969 void
util_format_yvyu_unpack_rgba_float(void * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)970 util_format_yvyu_unpack_rgba_float(void *restrict dst_row, unsigned dst_stride,
971 const uint8_t *restrict src_row, unsigned src_stride,
972 unsigned width, unsigned height)
973 {
974 unsigned x, y;
975
976 for (y = 0; y < height; y += 1) {
977 float *dst = dst_row;
978 const uint32_t *src = (const uint32_t *)src_row;
979 uint32_t value;
980 uint8_t y0, y1, u, v;
981
982 for (x = 0; x + 1 < width; x += 2) {
983 value = util_cpu_to_le32(*src++);
984
985 y0 = (value >> 0) & 0xff;
986 u = (value >> 24) & 0xff;
987 y1 = (value >> 16) & 0xff;
988 v = (value >> 8) & 0xff;
989
990 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
991 dst[3] = 1.0f; /* a */
992 dst += 4;
993
994 util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]);
995 dst[3] = 1.0f; /* a */
996 dst += 4;
997 }
998
999 if (x < width) {
1000 value = util_cpu_to_le32(*src);
1001
1002 y0 = (value >> 0) & 0xff;
1003 u = (value >> 24) & 0xff;
1004 y1 = (value >> 16) & 0xff;
1005 v = (value >> 8) & 0xff;
1006
1007 util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]);
1008 dst[3] = 1.0f; /* a */
1009 }
1010
1011 src_row = (uint8_t *)src_row + src_stride;
1012 dst_row = (uint8_t *)dst_row + dst_stride;
1013 }
1014 }
1015
1016
1017 void
util_format_yuyv_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1018 util_format_yuyv_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
1019 const uint8_t *restrict src_row, unsigned src_stride,
1020 unsigned width, unsigned height)
1021 {
1022 unsigned x, y;
1023
1024 for (y = 0; y < height; y += 1) {
1025 uint8_t *dst = dst_row;
1026 const uint32_t *src = (const uint32_t *)src_row;
1027 uint32_t value;
1028 uint8_t y0, y1, u, v;
1029
1030 for (x = 0; x + 1 < width; x += 2) {
1031 value = util_cpu_to_le32(*src++);
1032
1033 y0 = (value >> 0) & 0xff;
1034 u = (value >> 8) & 0xff;
1035 y1 = (value >> 16) & 0xff;
1036 v = (value >> 24) & 0xff;
1037
1038 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
1039 dst[3] = 0xff; /* a */
1040 dst += 4;
1041
1042 util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
1043 dst[3] = 0xff; /* a */
1044 dst += 4;
1045 }
1046
1047 if (x < width) {
1048 value = util_cpu_to_le32(*src);
1049
1050 y0 = (value >> 0) & 0xff;
1051 u = (value >> 8) & 0xff;
1052 y1 = (value >> 16) & 0xff;
1053 v = (value >> 24) & 0xff;
1054
1055 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
1056 dst[3] = 0xff; /* a */
1057 }
1058
1059 src_row += src_stride/sizeof(*src_row);
1060 dst_row += dst_stride/sizeof(*dst_row);
1061 }
1062 }
1063
1064 void
util_format_yvyu_unpack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1065 util_format_yvyu_unpack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
1066 const uint8_t *restrict src_row, unsigned src_stride,
1067 unsigned width, unsigned height)
1068 {
1069 unsigned x, y;
1070
1071 for (y = 0; y < height; y += 1) {
1072 uint8_t *dst = dst_row;
1073 const uint32_t *src = (const uint32_t *)src_row;
1074 uint32_t value;
1075 uint8_t y0, y1, u, v;
1076
1077 for (x = 0; x + 1 < width; x += 2) {
1078 value = util_cpu_to_le32(*src++);
1079
1080 y0 = (value >> 0) & 0xff;
1081 v = (value >> 8) & 0xff;
1082 y1 = (value >> 16) & 0xff;
1083 u = (value >> 24) & 0xff;
1084
1085 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
1086 dst[3] = 0xff; /* a */
1087 dst += 4;
1088
1089 util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]);
1090 dst[3] = 0xff; /* a */
1091 dst += 4;
1092 }
1093
1094 if (x < width) {
1095 value = util_cpu_to_le32(*src);
1096
1097 y0 = (value >> 0) & 0xff;
1098 v = (value >> 8) & 0xff;
1099 y1 = (value >> 16) & 0xff;
1100 u = (value >> 24) & 0xff;
1101
1102 util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]);
1103 dst[3] = 0xff; /* a */
1104 }
1105
1106 src_row += src_stride/sizeof(*src_row);
1107 dst_row += dst_stride/sizeof(*dst_row);
1108 }
1109 }
1110
1111
1112 void
util_format_yuyv_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1113 util_format_yuyv_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
1114 const float *restrict src_row, unsigned src_stride,
1115 unsigned width, unsigned height)
1116 {
1117 unsigned x, y;
1118
1119 for (y = 0; y < height; y += 1) {
1120 const float *src = src_row;
1121 uint32_t *dst = (uint32_t *)dst_row;
1122 uint8_t y0, y1, u, v;
1123 uint32_t value;
1124
1125 for (x = 0; x + 1 < width; x += 2) {
1126 uint8_t y0, y1, u0, u1, v0, v1, u, v;
1127
1128 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
1129 &y0, &u0, &v0);
1130 util_format_rgb_float_to_yuv(src[4], src[5], src[6],
1131 &y1, &u1, &v1);
1132
1133 u = (u0 + u1 + 1) >> 1;
1134 v = (v0 + v1 + 1) >> 1;
1135
1136 value = y0;
1137 value |= (uint32_t)u << 8;
1138 value |= (uint32_t)y1 << 16;
1139 value |= (uint32_t)v << 24;
1140
1141 *dst++ = util_le32_to_cpu(value);
1142
1143 src += 8;
1144 }
1145
1146 if (x < width) {
1147 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
1148 &y0, &u, &v);
1149 y1 = 0;
1150
1151 value = y0;
1152 value |= (uint32_t)u << 8;
1153 value |= (uint32_t)y1 << 16;
1154 value |= (uint32_t)v << 24;
1155
1156 *dst = util_le32_to_cpu(value);
1157 }
1158
1159 dst_row += dst_stride/sizeof(*dst_row);
1160 src_row += src_stride/sizeof(*src_row);
1161 }
1162 }
1163
1164 void
util_format_yvyu_pack_rgba_float(uint8_t * restrict dst_row,unsigned dst_stride,const float * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1165 util_format_yvyu_pack_rgba_float(uint8_t *restrict dst_row, unsigned dst_stride,
1166 const float *restrict src_row, unsigned src_stride,
1167 unsigned width, unsigned height)
1168 {
1169 unsigned x, y;
1170
1171 for (y = 0; y < height; y += 1) {
1172 const float *src = src_row;
1173 uint32_t *dst = (uint32_t *)dst_row;
1174 uint8_t y0, y1, u, v;
1175 uint32_t value;
1176
1177 for (x = 0; x + 1 < width; x += 2) {
1178 uint8_t y0, y1, u0, u1, v0, v1, u, v;
1179
1180 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
1181 &y0, &u0, &v0);
1182 util_format_rgb_float_to_yuv(src[4], src[5], src[6],
1183 &y1, &u1, &v1);
1184
1185 u = (u0 + u1 + 1) >> 1;
1186 v = (v0 + v1 + 1) >> 1;
1187
1188 value = y0;
1189 value |= (uint32_t)v << 8;
1190 value |= (uint32_t)y1 << 16;
1191 value |= (uint32_t)u << 24;
1192
1193 *dst++ = util_le32_to_cpu(value);
1194
1195 src += 8;
1196 }
1197
1198 if (x < width) {
1199 util_format_rgb_float_to_yuv(src[0], src[1], src[2],
1200 &y0, &u, &v);
1201 y1 = 0;
1202
1203 value = y0;
1204 value |= (uint32_t)v << 8;
1205 value |= (uint32_t)y1 << 16;
1206 value |= (uint32_t)u << 24;
1207
1208 *dst = util_le32_to_cpu(value);
1209 }
1210
1211 dst_row += dst_stride/sizeof(*dst_row);
1212 src_row += src_stride/sizeof(*src_row);
1213 }
1214 }
1215
1216 void
util_format_yuyv_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1217 util_format_yuyv_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
1218 const uint8_t *restrict src_row, unsigned src_stride,
1219 unsigned width, unsigned height)
1220 {
1221 unsigned x, y;
1222
1223 for (y = 0; y < height; y += 1) {
1224 const uint8_t *src = src_row;
1225 uint32_t *dst = (uint32_t *)dst_row;
1226 uint8_t y0, y1, u, v;
1227 uint32_t value;
1228
1229 for (x = 0; x + 1 < width; x += 2) {
1230 uint8_t y0, y1, u0, u1, v0, v1, u, v;
1231
1232 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
1233 &y0, &u0, &v0);
1234 util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
1235 &y1, &u1, &v1);
1236
1237 u = (u0 + u1 + 1) >> 1;
1238 v = (v0 + v1 + 1) >> 1;
1239
1240 value = y0;
1241 value |= (uint32_t)u << 8;
1242 value |= (uint32_t)y1 << 16;
1243 value |= (uint32_t)v << 24;
1244
1245 *dst++ = util_le32_to_cpu(value);
1246
1247 src += 8;
1248 }
1249
1250 if (x < width) {
1251 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
1252 &y0, &u, &v);
1253 y1 = 0;
1254
1255 value = y0;
1256 value |= (uint32_t)u << 8;
1257 value |= (uint32_t)y1 << 16;
1258 value |= (uint32_t)v << 24;
1259
1260 *dst = util_le32_to_cpu(value);
1261 }
1262
1263 dst_row += dst_stride/sizeof(*dst_row);
1264 src_row += src_stride/sizeof(*src_row);
1265 }
1266 }
1267
1268 void
util_format_yvyu_pack_rgba_8unorm(uint8_t * restrict dst_row,unsigned dst_stride,const uint8_t * restrict src_row,unsigned src_stride,unsigned width,unsigned height)1269 util_format_yvyu_pack_rgba_8unorm(uint8_t *restrict dst_row, unsigned dst_stride,
1270 const uint8_t *restrict src_row, unsigned src_stride,
1271 unsigned width, unsigned height)
1272 {
1273 unsigned x, y;
1274
1275 for (y = 0; y < height; y += 1) {
1276 const uint8_t *src = src_row;
1277 uint32_t *dst = (uint32_t *)dst_row;
1278 uint8_t y0, y1, u, v;
1279 uint32_t value;
1280
1281 for (x = 0; x + 1 < width; x += 2) {
1282 uint8_t y0, y1, u0, u1, v0, v1, u, v;
1283
1284 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
1285 &y0, &u0, &v0);
1286 util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6],
1287 &y1, &u1, &v1);
1288
1289 u = (u0 + u1 + 1) >> 1;
1290 v = (v0 + v1 + 1) >> 1;
1291
1292 value = y0;
1293 value |= (uint32_t)v << 8;
1294 value |= (uint32_t)y1 << 16;
1295 value |= (uint32_t)u << 24;
1296
1297 *dst++ = util_le32_to_cpu(value);
1298
1299 src += 8;
1300 }
1301
1302 if (x < width) {
1303 util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2],
1304 &y0, &u, &v);
1305 y1 = 0;
1306
1307 value = y0;
1308 value |= (uint32_t)v << 8;
1309 value |= (uint32_t)y1 << 16;
1310 value |= (uint32_t)u << 24;
1311
1312 *dst = util_le32_to_cpu(value);
1313 }
1314
1315 dst_row += dst_stride/sizeof(*dst_row);
1316 src_row += src_stride/sizeof(*src_row);
1317 }
1318 }
1319
1320
1321 void
util_format_yuyv_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)1322 util_format_yuyv_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
1323 unsigned i, ASSERTED unsigned j)
1324 {
1325 float *dst = in_dst;
1326 uint8_t y, u, v;
1327
1328 assert(i < 2);
1329 assert(j < 1);
1330
1331 y = src[0 + i*2];
1332 u = src[1];
1333 v = src[3];
1334
1335 util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
1336
1337 dst[3] = 1.0f;
1338 }
1339
1340 void
util_format_yvyu_fetch_rgba(void * restrict in_dst,const uint8_t * restrict src,unsigned i,ASSERTED unsigned j)1341 util_format_yvyu_fetch_rgba(void *restrict in_dst, const uint8_t *restrict src,
1342 unsigned i, ASSERTED unsigned j)
1343 {
1344 float *dst = in_dst;
1345 uint8_t y, u, v;
1346
1347 assert(i < 2);
1348 assert(j < 1);
1349
1350 y = src[0 + i*2];
1351 u = src[3];
1352 v = src[1];
1353
1354 util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]);
1355
1356 dst[3] = 1.0f;
1357 }
1358