1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 **************************************************************************/
31 * YUV and RGB subsampled formats conversion.
33 * @author Jose Fonseca <jfonseca@vmware.com>
37 #include "util/u_debug.h"
38 #include "util/format/u_format_yuv.h"
42 util_format_r8g8_b8g8_unorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
43 const uint8_t *src_row
, unsigned src_stride
,
44 unsigned width
, unsigned height
)
48 for (y
= 0; y
< height
; y
+= 1) {
50 const uint32_t *src
= (const uint32_t *)src_row
;
54 for (x
= 0; x
+ 1 < width
; x
+= 2) {
55 value
= util_cpu_to_le32(*src
++);
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);
65 dst
[3] = 1.0f
; /* a */
71 dst
[3] = 1.0f
; /* a */
76 value
= util_cpu_to_le32(*src
);
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);
86 dst
[3] = 1.0f
; /* a */
89 src_row
= (uint8_t *)src_row
+ src_stride
;
90 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
96 util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
97 const uint8_t *src_row
, unsigned src_stride
,
98 unsigned width
, unsigned height
)
102 for (y
= 0; y
< height
; y
+= 1) {
103 uint8_t *dst
= dst_row
;
104 const uint32_t *src
= (const uint32_t *)src_row
;
106 uint8_t r
, g0
, g1
, b
;
108 for (x
= 0; x
+ 1 < width
; x
+= 2) {
109 value
= util_cpu_to_le32(*src
++);
111 r
= (value
>> 0) & 0xff;
112 g0
= (value
>> 8) & 0xff;
113 b
= (value
>> 16) & 0xff;
114 g1
= (value
>> 24) & 0xff;
119 dst
[3] = 0xff; /* a */
125 dst
[3] = 0xff; /* a */
130 value
= util_cpu_to_le32(*src
);
132 r
= (value
>> 0) & 0xff;
133 g0
= (value
>> 8) & 0xff;
134 b
= (value
>> 16) & 0xff;
135 g1
= (value
>> 24) & 0xff;
140 dst
[3] = 0xff; /* a */
143 src_row
+= src_stride
/sizeof(*src_row
);
144 dst_row
+= dst_stride
/sizeof(*dst_row
);
150 util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
151 const float *src_row
, unsigned src_stride
,
152 unsigned width
, unsigned height
)
156 for (y
= 0; y
< height
; y
+= 1) {
157 const float *src
= src_row
;
158 uint32_t *dst
= (uint32_t *)dst_row
;
162 for (x
= 0; x
+ 1 < width
; x
+= 2) {
163 r
= 0.5f
*(src
[0] + src
[4]);
166 b
= 0.5f
*(src
[2] + src
[6]);
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;
173 *dst
++ = util_le32_to_cpu(value
);
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;
189 *dst
= util_le32_to_cpu(value
);
192 dst_row
+= dst_stride
/sizeof(*dst_row
);
193 src_row
+= src_stride
/sizeof(*src_row
);
199 util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
200 const uint8_t *src_row
, unsigned src_stride
,
201 unsigned width
, unsigned height
)
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
;
211 for (x
= 0; x
+ 1 < width
; x
+= 2) {
212 r
= (src
[0] + src
[4] + 1) >> 1;
215 b
= (src
[2] + src
[6] + 1) >> 1;
218 value
|= (uint32_t)g0
<< 8;
219 value
|= (uint32_t)b
<< 16;
220 value
|= (uint32_t)g1
<< 24;
222 *dst
++ = util_le32_to_cpu(value
);
234 value
|= (uint32_t)g0
<< 8;
235 value
|= (uint32_t)b
<< 16;
236 value
|= (uint32_t)g1
<< 24;
238 *dst
= util_le32_to_cpu(value
);
241 dst_row
+= dst_stride
/sizeof(*dst_row
);
242 src_row
+= src_stride
/sizeof(*src_row
);
248 util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
,
249 unsigned i
, ASSERTED
unsigned j
)
254 dst
[0] = ubyte_to_float(src
[0]); /* r */
255 dst
[1] = ubyte_to_float(src
[1 + 2*i
]); /* g */
256 dst
[2] = ubyte_to_float(src
[2]); /* b */
257 dst
[3] = 1.0f
; /* a */
262 util_format_g8r8_g8b8_unorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
263 const uint8_t *src_row
, unsigned src_stride
,
264 unsigned width
, unsigned height
)
268 for (y
= 0; y
< height
; y
+= 1) {
269 float *dst
= dst_row
;
270 const uint32_t *src
= (const uint32_t *)src_row
;
274 for (x
= 0; x
+ 1 < width
; x
+= 2) {
275 value
= util_cpu_to_le32(*src
++);
277 g0
= ubyte_to_float((value
>> 0) & 0xff);
278 r
= ubyte_to_float((value
>> 8) & 0xff);
279 g1
= ubyte_to_float((value
>> 16) & 0xff);
280 b
= ubyte_to_float((value
>> 24) & 0xff);
285 dst
[3] = 1.0f
; /* a */
291 dst
[3] = 1.0f
; /* a */
296 value
= util_cpu_to_le32(*src
);
298 g0
= ubyte_to_float((value
>> 0) & 0xff);
299 r
= ubyte_to_float((value
>> 8) & 0xff);
300 g1
= ubyte_to_float((value
>> 16) & 0xff);
301 b
= ubyte_to_float((value
>> 24) & 0xff);
306 dst
[3] = 1.0f
; /* a */
309 src_row
= (uint8_t *)src_row
+ src_stride
;
310 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
316 util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
317 const uint8_t *src_row
, unsigned src_stride
,
318 unsigned width
, unsigned height
)
322 for (y
= 0; y
< height
; y
+= 1) {
323 uint8_t *dst
= dst_row
;
324 const uint32_t *src
= (const uint32_t *)src_row
;
326 uint8_t r
, g0
, g1
, b
;
328 for (x
= 0; x
+ 1 < width
; x
+= 2) {
329 value
= util_cpu_to_le32(*src
++);
331 g0
= (value
>> 0) & 0xff;
332 r
= (value
>> 8) & 0xff;
333 g1
= (value
>> 16) & 0xff;
334 b
= (value
>> 24) & 0xff;
339 dst
[3] = 0xff; /* a */
345 dst
[3] = 0xff; /* a */
350 value
= util_cpu_to_le32(*src
);
352 g0
= (value
>> 0) & 0xff;
353 r
= (value
>> 8) & 0xff;
354 g1
= (value
>> 16) & 0xff;
355 b
= (value
>> 24) & 0xff;
360 dst
[3] = 0xff; /* a */
363 src_row
+= src_stride
/sizeof(*src_row
);
364 dst_row
+= dst_stride
/sizeof(*dst_row
);
370 util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
371 const float *src_row
, unsigned src_stride
,
372 unsigned width
, unsigned height
)
376 for (y
= 0; y
< height
; y
+= 1) {
377 const float *src
= src_row
;
378 uint32_t *dst
= (uint32_t *)dst_row
;
382 for (x
= 0; x
+ 1 < width
; x
+= 2) {
383 r
= 0.5f
*(src
[0] + src
[4]);
386 b
= 0.5f
*(src
[2] + src
[6]);
388 value
= (uint32_t)float_to_ubyte(g0
);
389 value
|= (uint32_t)float_to_ubyte(r
) << 8;
390 value
|= (uint32_t)float_to_ubyte(g1
) << 16;
391 value
|= (uint32_t)float_to_ubyte(b
) << 24;
393 *dst
++ = util_le32_to_cpu(value
);
404 value
= (uint32_t)float_to_ubyte(g0
);
405 value
|= (uint32_t)float_to_ubyte(r
) << 8;
406 value
|= (uint32_t)float_to_ubyte(g1
) << 16;
407 value
|= (uint32_t)float_to_ubyte(b
) << 24;
409 *dst
= util_le32_to_cpu(value
);
412 dst_row
+= dst_stride
/sizeof(*dst_row
);
413 src_row
+= src_stride
/sizeof(*src_row
);
419 util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
420 const uint8_t *src_row
, unsigned src_stride
,
421 unsigned width
, unsigned height
)
425 for (y
= 0; y
< height
; y
+= 1) {
426 const uint8_t *src
= src_row
;
427 uint32_t *dst
= (uint32_t *)dst_row
;
428 uint32_t r
, g0
, g1
, b
;
431 for (x
= 0; x
+ 1 < width
; x
+= 2) {
432 r
= (src
[0] + src
[4] + 1) >> 1;
435 b
= (src
[2] + src
[6] + 1) >> 1;
438 value
|= (uint32_t)r
<< 8;
439 value
|= (uint32_t)g1
<< 16;
440 value
|= (uint32_t)b
<< 24;
442 *dst
++ = util_le32_to_cpu(value
);
454 value
|= (uint32_t)r
<< 8;
455 value
|= (uint32_t)g1
<< 16;
456 value
|= (uint32_t)b
<< 24;
458 *dst
= util_le32_to_cpu(value
);
461 dst_row
+= dst_stride
/sizeof(*dst_row
);
462 src_row
+= src_stride
/sizeof(*src_row
);
468 util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
,
469 unsigned i
, ASSERTED
unsigned j
)
474 dst
[0] = ubyte_to_float(src
[1]); /* r */
475 dst
[1] = ubyte_to_float(src
[0 + 2*i
]); /* g */
476 dst
[2] = ubyte_to_float(src
[3]); /* b */
477 dst
[3] = 1.0f
; /* a */
482 util_format_uyvy_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
483 const uint8_t *src_row
, unsigned src_stride
,
484 unsigned width
, unsigned height
)
488 for (y
= 0; y
< height
; y
+= 1) {
489 float *dst
= dst_row
;
490 const uint32_t *src
= (const uint32_t *)src_row
;
492 uint8_t y0
, y1
, u
, v
;
494 for (x
= 0; x
+ 1 < width
; x
+= 2) {
495 value
= util_cpu_to_le32(*src
++);
497 u
= (value
>> 0) & 0xff;
498 y0
= (value
>> 8) & 0xff;
499 v
= (value
>> 16) & 0xff;
500 y1
= (value
>> 24) & 0xff;
502 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
503 dst
[3] = 1.0f
; /* a */
506 util_format_yuv_to_rgb_float(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
507 dst
[3] = 1.0f
; /* a */
512 value
= util_cpu_to_le32(*src
);
514 u
= (value
>> 0) & 0xff;
515 y0
= (value
>> 8) & 0xff;
516 v
= (value
>> 16) & 0xff;
517 y1
= (value
>> 24) & 0xff;
519 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
520 dst
[3] = 1.0f
; /* a */
523 src_row
= (uint8_t *)src_row
+ src_stride
;
524 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
530 util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
531 const uint8_t *src_row
, unsigned src_stride
,
532 unsigned width
, unsigned height
)
536 for (y
= 0; y
< height
; y
+= 1) {
537 uint8_t *dst
= dst_row
;
538 const uint32_t *src
= (const uint32_t *)src_row
;
540 uint8_t y0
, y1
, u
, v
;
542 for (x
= 0; x
+ 1 < width
; x
+= 2) {
543 value
= util_cpu_to_le32(*src
++);
545 u
= (value
>> 0) & 0xff;
546 y0
= (value
>> 8) & 0xff;
547 v
= (value
>> 16) & 0xff;
548 y1
= (value
>> 24) & 0xff;
550 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
551 dst
[3] = 0xff; /* a */
554 util_format_yuv_to_rgb_8unorm(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
555 dst
[3] = 0xff; /* a */
560 value
= util_cpu_to_le32(*src
);
562 u
= (value
>> 0) & 0xff;
563 y0
= (value
>> 8) & 0xff;
564 v
= (value
>> 16) & 0xff;
565 y1
= (value
>> 24) & 0xff;
567 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
568 dst
[3] = 0xff; /* a */
571 src_row
+= src_stride
/sizeof(*src_row
);
572 dst_row
+= dst_stride
/sizeof(*dst_row
);
578 util_format_uyvy_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
579 const float *src_row
, unsigned src_stride
,
580 unsigned width
, unsigned height
)
584 for (y
= 0; y
< height
; y
+= 1) {
585 const float *src
= src_row
;
586 uint32_t *dst
= (uint32_t *)dst_row
;
587 uint8_t y0
, y1
, u
, v
;
590 for (x
= 0; x
+ 1 < width
; x
+= 2) {
591 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
593 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
595 util_format_rgb_float_to_yuv(src
[4], src
[5], src
[6],
598 u
= (u0
+ u1
+ 1) >> 1;
599 v
= (v0
+ v1
+ 1) >> 1;
602 value
|= (uint32_t)y0
<< 8;
603 value
|= (uint32_t)v
<< 16;
604 value
|= (uint32_t)y1
<< 24;
606 *dst
++ = util_le32_to_cpu(value
);
612 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
617 value
|= (uint32_t)y0
<< 8;
618 value
|= (uint32_t)v
<< 16;
619 value
|= (uint32_t)y1
<< 24;
621 *dst
= util_le32_to_cpu(value
);
624 dst_row
+= dst_stride
/sizeof(*dst_row
);
625 src_row
+= src_stride
/sizeof(*src_row
);
631 util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
632 const uint8_t *src_row
, unsigned src_stride
,
633 unsigned width
, unsigned height
)
637 for (y
= 0; y
< height
; y
+= 1) {
638 const uint8_t *src
= src_row
;
639 uint32_t *dst
= (uint32_t *)dst_row
;
640 uint8_t y0
, y1
, u
, v
;
643 for (x
= 0; x
+ 1 < width
; x
+= 2) {
644 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
646 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
648 util_format_rgb_8unorm_to_yuv(src
[4], src
[5], src
[6],
651 u
= (u0
+ u1
+ 1) >> 1;
652 v
= (v0
+ v1
+ 1) >> 1;
655 value
|= (uint32_t)y0
<< 8;
656 value
|= (uint32_t)v
<< 16;
657 value
|= (uint32_t)y1
<< 24;
659 *dst
++ = util_le32_to_cpu(value
);
665 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
670 value
|= (uint32_t)y0
<< 8;
671 value
|= (uint32_t)v
<< 16;
672 value
|= (uint32_t)y1
<< 24;
674 *dst
= util_le32_to_cpu(value
);
677 dst_row
+= dst_stride
/sizeof(*dst_row
);
678 src_row
+= src_stride
/sizeof(*src_row
);
684 util_format_uyvy_fetch_rgba_float(float *dst
, const uint8_t *src
,
685 unsigned i
, ASSERTED
unsigned j
)
696 util_format_yuv_to_rgb_float(y
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
703 util_format_yuyv_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
704 const uint8_t *src_row
, unsigned src_stride
,
705 unsigned width
, unsigned height
)
709 for (y
= 0; y
< height
; y
+= 1) {
710 float *dst
= dst_row
;
711 const uint32_t *src
= (const uint32_t *)src_row
;
713 uint8_t y0
, y1
, u
, v
;
715 for (x
= 0; x
+ 1 < width
; x
+= 2) {
716 value
= util_cpu_to_le32(*src
++);
718 y0
= (value
>> 0) & 0xff;
719 u
= (value
>> 8) & 0xff;
720 y1
= (value
>> 16) & 0xff;
721 v
= (value
>> 24) & 0xff;
723 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
724 dst
[3] = 1.0f
; /* a */
727 util_format_yuv_to_rgb_float(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
728 dst
[3] = 1.0f
; /* a */
733 value
= util_cpu_to_le32(*src
);
735 y0
= (value
>> 0) & 0xff;
736 u
= (value
>> 8) & 0xff;
737 y1
= (value
>> 16) & 0xff;
738 v
= (value
>> 24) & 0xff;
740 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
741 dst
[3] = 1.0f
; /* a */
744 src_row
= (uint8_t *)src_row
+ src_stride
;
745 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
751 util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
752 const uint8_t *src_row
, unsigned src_stride
,
753 unsigned width
, unsigned height
)
757 for (y
= 0; y
< height
; y
+= 1) {
758 uint8_t *dst
= dst_row
;
759 const uint32_t *src
= (const uint32_t *)src_row
;
761 uint8_t y0
, y1
, u
, v
;
763 for (x
= 0; x
+ 1 < width
; x
+= 2) {
764 value
= util_cpu_to_le32(*src
++);
766 y0
= (value
>> 0) & 0xff;
767 u
= (value
>> 8) & 0xff;
768 y1
= (value
>> 16) & 0xff;
769 v
= (value
>> 24) & 0xff;
771 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
772 dst
[3] = 0xff; /* a */
775 util_format_yuv_to_rgb_8unorm(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
776 dst
[3] = 0xff; /* a */
781 value
= util_cpu_to_le32(*src
);
783 y0
= (value
>> 0) & 0xff;
784 u
= (value
>> 8) & 0xff;
785 y1
= (value
>> 16) & 0xff;
786 v
= (value
>> 24) & 0xff;
788 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
789 dst
[3] = 0xff; /* a */
792 src_row
+= src_stride
/sizeof(*src_row
);
793 dst_row
+= dst_stride
/sizeof(*dst_row
);
799 util_format_yuyv_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
800 const float *src_row
, unsigned src_stride
,
801 unsigned width
, unsigned height
)
805 for (y
= 0; y
< height
; y
+= 1) {
806 const float *src
= src_row
;
807 uint32_t *dst
= (uint32_t *)dst_row
;
808 uint8_t y0
, y1
, u
, v
;
811 for (x
= 0; x
+ 1 < width
; x
+= 2) {
812 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
814 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
816 util_format_rgb_float_to_yuv(src
[4], src
[5], src
[6],
819 u
= (u0
+ u1
+ 1) >> 1;
820 v
= (v0
+ v1
+ 1) >> 1;
823 value
|= (uint32_t)u
<< 8;
824 value
|= (uint32_t)y1
<< 16;
825 value
|= (uint32_t)v
<< 24;
827 *dst
++ = util_le32_to_cpu(value
);
833 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
838 value
|= (uint32_t)u
<< 8;
839 value
|= (uint32_t)y1
<< 16;
840 value
|= (uint32_t)v
<< 24;
842 *dst
= util_le32_to_cpu(value
);
845 dst_row
+= dst_stride
/sizeof(*dst_row
);
846 src_row
+= src_stride
/sizeof(*src_row
);
852 util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
853 const uint8_t *src_row
, unsigned src_stride
,
854 unsigned width
, unsigned height
)
858 for (y
= 0; y
< height
; y
+= 1) {
859 const uint8_t *src
= src_row
;
860 uint32_t *dst
= (uint32_t *)dst_row
;
861 uint8_t y0
, y1
, u
, v
;
864 for (x
= 0; x
+ 1 < width
; x
+= 2) {
865 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
867 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
869 util_format_rgb_8unorm_to_yuv(src
[4], src
[5], src
[6],
872 u
= (u0
+ u1
+ 1) >> 1;
873 v
= (v0
+ v1
+ 1) >> 1;
876 value
|= (uint32_t)u
<< 8;
877 value
|= (uint32_t)y1
<< 16;
878 value
|= (uint32_t)v
<< 24;
880 *dst
++ = util_le32_to_cpu(value
);
886 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
891 value
|= (uint32_t)u
<< 8;
892 value
|= (uint32_t)y1
<< 16;
893 value
|= (uint32_t)v
<< 24;
895 *dst
= util_le32_to_cpu(value
);
898 dst_row
+= dst_stride
/sizeof(*dst_row
);
899 src_row
+= src_stride
/sizeof(*src_row
);
905 util_format_yuyv_fetch_rgba_float(float *dst
, const uint8_t *src
,
906 unsigned i
, ASSERTED
unsigned j
)
917 util_format_yuv_to_rgb_float(y
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);