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(void *in_dst
, const uint8_t *src
,
249 unsigned i
, ASSERTED
unsigned j
)
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 */
264 util_format_g8r8_g8b8_unorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
265 const uint8_t *src_row
, unsigned src_stride
,
266 unsigned width
, unsigned height
)
270 for (y
= 0; y
< height
; y
+= 1) {
271 float *dst
= dst_row
;
272 const uint32_t *src
= (const uint32_t *)src_row
;
276 for (x
= 0; x
+ 1 < width
; x
+= 2) {
277 value
= util_cpu_to_le32(*src
++);
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);
287 dst
[3] = 1.0f
; /* a */
293 dst
[3] = 1.0f
; /* a */
298 value
= util_cpu_to_le32(*src
);
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);
308 dst
[3] = 1.0f
; /* a */
311 src_row
= (uint8_t *)src_row
+ src_stride
;
312 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
318 util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
319 const uint8_t *src_row
, unsigned src_stride
,
320 unsigned width
, unsigned height
)
324 for (y
= 0; y
< height
; y
+= 1) {
325 uint8_t *dst
= dst_row
;
326 const uint32_t *src
= (const uint32_t *)src_row
;
328 uint8_t r
, g0
, g1
, b
;
330 for (x
= 0; x
+ 1 < width
; x
+= 2) {
331 value
= util_cpu_to_le32(*src
++);
333 g0
= (value
>> 0) & 0xff;
334 r
= (value
>> 8) & 0xff;
335 g1
= (value
>> 16) & 0xff;
336 b
= (value
>> 24) & 0xff;
341 dst
[3] = 0xff; /* a */
347 dst
[3] = 0xff; /* a */
352 value
= util_cpu_to_le32(*src
);
354 g0
= (value
>> 0) & 0xff;
355 r
= (value
>> 8) & 0xff;
356 g1
= (value
>> 16) & 0xff;
357 b
= (value
>> 24) & 0xff;
362 dst
[3] = 0xff; /* a */
365 src_row
+= src_stride
/sizeof(*src_row
);
366 dst_row
+= dst_stride
/sizeof(*dst_row
);
372 util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
373 const float *src_row
, unsigned src_stride
,
374 unsigned width
, unsigned height
)
378 for (y
= 0; y
< height
; y
+= 1) {
379 const float *src
= src_row
;
380 uint32_t *dst
= (uint32_t *)dst_row
;
384 for (x
= 0; x
+ 1 < width
; x
+= 2) {
385 r
= 0.5f
*(src
[0] + src
[4]);
388 b
= 0.5f
*(src
[2] + src
[6]);
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;
395 *dst
++ = util_le32_to_cpu(value
);
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;
411 *dst
= util_le32_to_cpu(value
);
414 dst_row
+= dst_stride
/sizeof(*dst_row
);
415 src_row
+= src_stride
/sizeof(*src_row
);
421 util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
422 const uint8_t *src_row
, unsigned src_stride
,
423 unsigned width
, unsigned height
)
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
;
433 for (x
= 0; x
+ 1 < width
; x
+= 2) {
434 r
= (src
[0] + src
[4] + 1) >> 1;
437 b
= (src
[2] + src
[6] + 1) >> 1;
440 value
|= (uint32_t)r
<< 8;
441 value
|= (uint32_t)g1
<< 16;
442 value
|= (uint32_t)b
<< 24;
444 *dst
++ = util_le32_to_cpu(value
);
456 value
|= (uint32_t)r
<< 8;
457 value
|= (uint32_t)g1
<< 16;
458 value
|= (uint32_t)b
<< 24;
460 *dst
= util_le32_to_cpu(value
);
463 dst_row
+= dst_stride
/sizeof(*dst_row
);
464 src_row
+= src_stride
/sizeof(*src_row
);
470 util_format_g8r8_g8b8_unorm_fetch_rgba(void *in_dst
, const uint8_t *src
,
471 unsigned i
, ASSERTED
unsigned j
)
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 */
486 util_format_uyvy_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
487 const uint8_t *src_row
, unsigned src_stride
,
488 unsigned width
, unsigned height
)
492 for (y
= 0; y
< height
; y
+= 1) {
493 float *dst
= dst_row
;
494 const uint32_t *src
= (const uint32_t *)src_row
;
496 uint8_t y0
, y1
, u
, v
;
498 for (x
= 0; x
+ 1 < width
; x
+= 2) {
499 value
= util_cpu_to_le32(*src
++);
501 u
= (value
>> 0) & 0xff;
502 y0
= (value
>> 8) & 0xff;
503 v
= (value
>> 16) & 0xff;
504 y1
= (value
>> 24) & 0xff;
506 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
507 dst
[3] = 1.0f
; /* a */
510 util_format_yuv_to_rgb_float(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
511 dst
[3] = 1.0f
; /* a */
516 value
= util_cpu_to_le32(*src
);
518 u
= (value
>> 0) & 0xff;
519 y0
= (value
>> 8) & 0xff;
520 v
= (value
>> 16) & 0xff;
521 y1
= (value
>> 24) & 0xff;
523 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
524 dst
[3] = 1.0f
; /* a */
527 src_row
= (uint8_t *)src_row
+ src_stride
;
528 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
534 util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
535 const uint8_t *src_row
, unsigned src_stride
,
536 unsigned width
, unsigned height
)
540 for (y
= 0; y
< height
; y
+= 1) {
541 uint8_t *dst
= dst_row
;
542 const uint32_t *src
= (const uint32_t *)src_row
;
544 uint8_t y0
, y1
, u
, v
;
546 for (x
= 0; x
+ 1 < width
; x
+= 2) {
547 value
= util_cpu_to_le32(*src
++);
549 u
= (value
>> 0) & 0xff;
550 y0
= (value
>> 8) & 0xff;
551 v
= (value
>> 16) & 0xff;
552 y1
= (value
>> 24) & 0xff;
554 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
555 dst
[3] = 0xff; /* a */
558 util_format_yuv_to_rgb_8unorm(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
559 dst
[3] = 0xff; /* a */
564 value
= util_cpu_to_le32(*src
);
566 u
= (value
>> 0) & 0xff;
567 y0
= (value
>> 8) & 0xff;
568 v
= (value
>> 16) & 0xff;
569 y1
= (value
>> 24) & 0xff;
571 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
572 dst
[3] = 0xff; /* a */
575 src_row
+= src_stride
/sizeof(*src_row
);
576 dst_row
+= dst_stride
/sizeof(*dst_row
);
582 util_format_uyvy_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
583 const float *src_row
, unsigned src_stride
,
584 unsigned width
, unsigned height
)
588 for (y
= 0; y
< height
; y
+= 1) {
589 const float *src
= src_row
;
590 uint32_t *dst
= (uint32_t *)dst_row
;
591 uint8_t y0
, y1
, u
, v
;
594 for (x
= 0; x
+ 1 < width
; x
+= 2) {
595 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
597 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
599 util_format_rgb_float_to_yuv(src
[4], src
[5], src
[6],
602 u
= (u0
+ u1
+ 1) >> 1;
603 v
= (v0
+ v1
+ 1) >> 1;
606 value
|= (uint32_t)y0
<< 8;
607 value
|= (uint32_t)v
<< 16;
608 value
|= (uint32_t)y1
<< 24;
610 *dst
++ = util_le32_to_cpu(value
);
616 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
621 value
|= (uint32_t)y0
<< 8;
622 value
|= (uint32_t)v
<< 16;
623 value
|= (uint32_t)y1
<< 24;
625 *dst
= util_le32_to_cpu(value
);
628 dst_row
+= dst_stride
/sizeof(*dst_row
);
629 src_row
+= src_stride
/sizeof(*src_row
);
635 util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
636 const uint8_t *src_row
, unsigned src_stride
,
637 unsigned width
, unsigned height
)
641 for (y
= 0; y
< height
; y
+= 1) {
642 const uint8_t *src
= src_row
;
643 uint32_t *dst
= (uint32_t *)dst_row
;
644 uint8_t y0
, y1
, u
, v
;
647 for (x
= 0; x
+ 1 < width
; x
+= 2) {
648 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
650 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
652 util_format_rgb_8unorm_to_yuv(src
[4], src
[5], src
[6],
655 u
= (u0
+ u1
+ 1) >> 1;
656 v
= (v0
+ v1
+ 1) >> 1;
659 value
|= (uint32_t)y0
<< 8;
660 value
|= (uint32_t)v
<< 16;
661 value
|= (uint32_t)y1
<< 24;
663 *dst
++ = util_le32_to_cpu(value
);
669 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
674 value
|= (uint32_t)y0
<< 8;
675 value
|= (uint32_t)v
<< 16;
676 value
|= (uint32_t)y1
<< 24;
678 *dst
= util_le32_to_cpu(value
);
681 dst_row
+= dst_stride
/sizeof(*dst_row
);
682 src_row
+= src_stride
/sizeof(*src_row
);
688 util_format_uyvy_fetch_rgba(void *in_dst
, const uint8_t *src
,
689 unsigned i
, ASSERTED
unsigned j
)
701 util_format_yuv_to_rgb_float(y
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
708 util_format_yuyv_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
709 const uint8_t *src_row
, unsigned src_stride
,
710 unsigned width
, unsigned height
)
714 for (y
= 0; y
< height
; y
+= 1) {
715 float *dst
= dst_row
;
716 const uint32_t *src
= (const uint32_t *)src_row
;
718 uint8_t y0
, y1
, u
, v
;
720 for (x
= 0; x
+ 1 < width
; x
+= 2) {
721 value
= util_cpu_to_le32(*src
++);
723 y0
= (value
>> 0) & 0xff;
724 u
= (value
>> 8) & 0xff;
725 y1
= (value
>> 16) & 0xff;
726 v
= (value
>> 24) & 0xff;
728 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
729 dst
[3] = 1.0f
; /* a */
732 util_format_yuv_to_rgb_float(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
733 dst
[3] = 1.0f
; /* a */
738 value
= util_cpu_to_le32(*src
);
740 y0
= (value
>> 0) & 0xff;
741 u
= (value
>> 8) & 0xff;
742 y1
= (value
>> 16) & 0xff;
743 v
= (value
>> 24) & 0xff;
745 util_format_yuv_to_rgb_float(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
746 dst
[3] = 1.0f
; /* a */
749 src_row
= (uint8_t *)src_row
+ src_stride
;
750 dst_row
= (uint8_t *)dst_row
+ dst_stride
;
756 util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
757 const uint8_t *src_row
, unsigned src_stride
,
758 unsigned width
, unsigned height
)
762 for (y
= 0; y
< height
; y
+= 1) {
763 uint8_t *dst
= dst_row
;
764 const uint32_t *src
= (const uint32_t *)src_row
;
766 uint8_t y0
, y1
, u
, v
;
768 for (x
= 0; x
+ 1 < width
; x
+= 2) {
769 value
= util_cpu_to_le32(*src
++);
771 y0
= (value
>> 0) & 0xff;
772 u
= (value
>> 8) & 0xff;
773 y1
= (value
>> 16) & 0xff;
774 v
= (value
>> 24) & 0xff;
776 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
777 dst
[3] = 0xff; /* a */
780 util_format_yuv_to_rgb_8unorm(y1
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
781 dst
[3] = 0xff; /* a */
786 value
= util_cpu_to_le32(*src
);
788 y0
= (value
>> 0) & 0xff;
789 u
= (value
>> 8) & 0xff;
790 y1
= (value
>> 16) & 0xff;
791 v
= (value
>> 24) & 0xff;
793 util_format_yuv_to_rgb_8unorm(y0
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);
794 dst
[3] = 0xff; /* a */
797 src_row
+= src_stride
/sizeof(*src_row
);
798 dst_row
+= dst_stride
/sizeof(*dst_row
);
804 util_format_yuyv_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
805 const float *src_row
, unsigned src_stride
,
806 unsigned width
, unsigned height
)
810 for (y
= 0; y
< height
; y
+= 1) {
811 const float *src
= src_row
;
812 uint32_t *dst
= (uint32_t *)dst_row
;
813 uint8_t y0
, y1
, u
, v
;
816 for (x
= 0; x
+ 1 < width
; x
+= 2) {
817 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
819 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
821 util_format_rgb_float_to_yuv(src
[4], src
[5], src
[6],
824 u
= (u0
+ u1
+ 1) >> 1;
825 v
= (v0
+ v1
+ 1) >> 1;
828 value
|= (uint32_t)u
<< 8;
829 value
|= (uint32_t)y1
<< 16;
830 value
|= (uint32_t)v
<< 24;
832 *dst
++ = util_le32_to_cpu(value
);
838 util_format_rgb_float_to_yuv(src
[0], src
[1], src
[2],
843 value
|= (uint32_t)u
<< 8;
844 value
|= (uint32_t)y1
<< 16;
845 value
|= (uint32_t)v
<< 24;
847 *dst
= util_le32_to_cpu(value
);
850 dst_row
+= dst_stride
/sizeof(*dst_row
);
851 src_row
+= src_stride
/sizeof(*src_row
);
857 util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
858 const uint8_t *src_row
, unsigned src_stride
,
859 unsigned width
, unsigned height
)
863 for (y
= 0; y
< height
; y
+= 1) {
864 const uint8_t *src
= src_row
;
865 uint32_t *dst
= (uint32_t *)dst_row
;
866 uint8_t y0
, y1
, u
, v
;
869 for (x
= 0; x
+ 1 < width
; x
+= 2) {
870 uint8_t y0
, y1
, u0
, u1
, v0
, v1
, u
, v
;
872 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
874 util_format_rgb_8unorm_to_yuv(src
[4], src
[5], src
[6],
877 u
= (u0
+ u1
+ 1) >> 1;
878 v
= (v0
+ v1
+ 1) >> 1;
881 value
|= (uint32_t)u
<< 8;
882 value
|= (uint32_t)y1
<< 16;
883 value
|= (uint32_t)v
<< 24;
885 *dst
++ = util_le32_to_cpu(value
);
891 util_format_rgb_8unorm_to_yuv(src
[0], src
[1], src
[2],
896 value
|= (uint32_t)u
<< 8;
897 value
|= (uint32_t)y1
<< 16;
898 value
|= (uint32_t)v
<< 24;
900 *dst
= util_le32_to_cpu(value
);
903 dst_row
+= dst_stride
/sizeof(*dst_row
);
904 src_row
+= src_stride
/sizeof(*src_row
);
910 util_format_yuyv_fetch_rgba(void *in_dst
, const uint8_t *src
,
911 unsigned i
, ASSERTED
unsigned j
)
923 util_format_yuv_to_rgb_float(y
, u
, v
, &dst
[0], &dst
[1], &dst
[2]);