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 above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Pixel format accessor functions.
32 * @author Jose Fonseca <jfonseca@vmware.com>
38 #include "u_format_s3tc.h"
39 #include "u_surface.h"
41 #include "pipe/p_defines.h"
45 util_format_is_float(enum pipe_format format
)
47 const struct util_format_description
*desc
= util_format_description(format
);
55 i
= util_format_get_first_non_void_channel(format
);
60 return desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FLOAT
? TRUE
: FALSE
;
64 /** Test if the format contains RGB, but not alpha */
66 util_format_has_alpha(enum pipe_format format
)
68 const struct util_format_description
*desc
=
69 util_format_description(format
);
71 return (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
||
72 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) &&
73 desc
->swizzle
[3] != PIPE_SWIZZLE_1
;
78 util_format_is_luminance(enum pipe_format format
)
80 const struct util_format_description
*desc
=
81 util_format_description(format
);
83 if ((desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
||
84 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) &&
85 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
86 desc
->swizzle
[1] == PIPE_SWIZZLE_X
&&
87 desc
->swizzle
[2] == PIPE_SWIZZLE_X
&&
88 desc
->swizzle
[3] == PIPE_SWIZZLE_1
) {
95 util_format_is_alpha(enum pipe_format format
)
97 const struct util_format_description
*desc
=
98 util_format_description(format
);
100 if ((desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
||
101 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) &&
102 desc
->swizzle
[0] == PIPE_SWIZZLE_0
&&
103 desc
->swizzle
[1] == PIPE_SWIZZLE_0
&&
104 desc
->swizzle
[2] == PIPE_SWIZZLE_0
&&
105 desc
->swizzle
[3] == PIPE_SWIZZLE_X
) {
112 util_format_is_pure_integer(enum pipe_format format
)
114 const struct util_format_description
*desc
= util_format_description(format
);
117 /* Find the first non-void channel. */
118 i
= util_format_get_first_non_void_channel(format
);
122 return desc
->channel
[i
].pure_integer
? TRUE
: FALSE
;
126 util_format_is_pure_sint(enum pipe_format format
)
128 const struct util_format_description
*desc
= util_format_description(format
);
131 i
= util_format_get_first_non_void_channel(format
);
135 return (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
&& desc
->channel
[i
].pure_integer
) ? TRUE
: FALSE
;
139 util_format_is_pure_uint(enum pipe_format format
)
141 const struct util_format_description
*desc
= util_format_description(format
);
144 i
= util_format_get_first_non_void_channel(format
);
148 return (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
&& desc
->channel
[i
].pure_integer
) ? TRUE
: FALSE
;
152 * Returns true if all non-void channels are normalized signed.
155 util_format_is_snorm(enum pipe_format format
)
157 const struct util_format_description
*desc
= util_format_description(format
);
163 i
= util_format_get_first_non_void_channel(format
);
167 return desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
&&
168 !desc
->channel
[i
].pure_integer
&&
169 desc
->channel
[i
].normalized
;
173 util_format_is_snorm8(enum pipe_format format
)
175 const struct util_format_description
*desc
= util_format_description(format
);
181 i
= util_format_get_first_non_void_channel(format
);
185 return desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
&&
186 !desc
->channel
[i
].pure_integer
&&
187 desc
->channel
[i
].normalized
&&
188 desc
->channel
[i
].size
== 8;
192 util_format_is_luminance_alpha(enum pipe_format format
)
194 const struct util_format_description
*desc
=
195 util_format_description(format
);
197 if ((desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
||
198 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) &&
199 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
200 desc
->swizzle
[1] == PIPE_SWIZZLE_X
&&
201 desc
->swizzle
[2] == PIPE_SWIZZLE_X
&&
202 desc
->swizzle
[3] == PIPE_SWIZZLE_Y
) {
210 util_format_is_intensity(enum pipe_format format
)
212 const struct util_format_description
*desc
=
213 util_format_description(format
);
215 if ((desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
||
216 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) &&
217 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
218 desc
->swizzle
[1] == PIPE_SWIZZLE_X
&&
219 desc
->swizzle
[2] == PIPE_SWIZZLE_X
&&
220 desc
->swizzle
[3] == PIPE_SWIZZLE_X
) {
227 util_format_is_subsampled_422(enum pipe_format format
)
229 const struct util_format_description
*desc
=
230 util_format_description(format
);
232 return desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
&&
233 desc
->block
.width
== 2 &&
234 desc
->block
.height
== 1 &&
235 desc
->block
.bits
== 32;
239 util_format_is_supported(enum pipe_format format
, unsigned bind
)
241 if (format
>= PIPE_FORMAT_COUNT
) {
245 if (util_format_is_s3tc(format
) && !util_format_s3tc_enabled
) {
249 #ifndef TEXTURE_FLOAT_ENABLED
250 if ((bind
& PIPE_BIND_RENDER_TARGET
) &&
251 format
!= PIPE_FORMAT_R9G9B9E5_FLOAT
&&
252 format
!= PIPE_FORMAT_R11G11B10_FLOAT
&&
253 util_format_is_float(format
)) {
263 * Calculates the MRD for the depth format. MRD is used in depth bias
264 * for UNORM and unbound depth buffers. When the depth buffer is floating
265 * point, the depth bias calculation does not use the MRD. However, the
266 * default MRD will be 1.0 / ((1 << 24) - 1).
269 util_get_depth_format_mrd(const struct util_format_description
*desc
)
272 * Depth buffer formats without a depth component OR scenarios
273 * without a bound depth buffer default to D24.
275 double mrd
= 1.0 / ((1 << 24) - 1);
276 unsigned depth_channel
;
281 * Some depth formats do not store the depth component in the first
282 * channel, detect the format and adjust the depth channel. Get the
283 * swizzled depth component channel.
285 depth_channel
= desc
->swizzle
[0];
287 if (desc
->channel
[depth_channel
].type
== UTIL_FORMAT_TYPE_UNSIGNED
&&
288 desc
->channel
[depth_channel
].normalized
) {
291 depth_bits
= desc
->channel
[depth_channel
].size
;
292 mrd
= 1.0 / ((1ULL << depth_bits
) - 1);
300 util_format_read_4f(enum pipe_format format
,
301 float *dst
, unsigned dst_stride
,
302 const void *src
, unsigned src_stride
,
303 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
305 const struct util_format_description
*format_desc
;
306 const uint8_t *src_row
;
309 format_desc
= util_format_description(format
);
311 assert(x
% format_desc
->block
.width
== 0);
312 assert(y
% format_desc
->block
.height
== 0);
314 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
317 format_desc
->unpack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
322 util_format_write_4f(enum pipe_format format
,
323 const float *src
, unsigned src_stride
,
324 void *dst
, unsigned dst_stride
,
325 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
327 const struct util_format_description
*format_desc
;
329 const float *src_row
;
331 format_desc
= util_format_description(format
);
333 assert(x
% format_desc
->block
.width
== 0);
334 assert(y
% format_desc
->block
.height
== 0);
336 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
339 format_desc
->pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
344 util_format_read_4ub(enum pipe_format format
, uint8_t *dst
, unsigned dst_stride
, const void *src
, unsigned src_stride
, unsigned x
, unsigned y
, unsigned w
, unsigned h
)
346 const struct util_format_description
*format_desc
;
347 const uint8_t *src_row
;
350 format_desc
= util_format_description(format
);
352 assert(x
% format_desc
->block
.width
== 0);
353 assert(y
% format_desc
->block
.height
== 0);
355 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
358 format_desc
->unpack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
363 util_format_write_4ub(enum pipe_format format
, const uint8_t *src
, unsigned src_stride
, void *dst
, unsigned dst_stride
, unsigned x
, unsigned y
, unsigned w
, unsigned h
)
365 const struct util_format_description
*format_desc
;
367 const uint8_t *src_row
;
369 format_desc
= util_format_description(format
);
371 assert(x
% format_desc
->block
.width
== 0);
372 assert(y
% format_desc
->block
.height
== 0);
374 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
377 format_desc
->pack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
381 util_format_read_4ui(enum pipe_format format
,
382 unsigned *dst
, unsigned dst_stride
,
383 const void *src
, unsigned src_stride
,
384 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
386 const struct util_format_description
*format_desc
;
387 const uint8_t *src_row
;
390 format_desc
= util_format_description(format
);
392 assert(x
% format_desc
->block
.width
== 0);
393 assert(y
% format_desc
->block
.height
== 0);
395 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
398 format_desc
->unpack_rgba_uint(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
402 util_format_write_4ui(enum pipe_format format
,
403 const unsigned int *src
, unsigned src_stride
,
404 void *dst
, unsigned dst_stride
,
405 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
407 const struct util_format_description
*format_desc
;
409 const uint32_t *src_row
;
411 format_desc
= util_format_description(format
);
413 assert(x
% format_desc
->block
.width
== 0);
414 assert(y
% format_desc
->block
.height
== 0);
416 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
419 format_desc
->pack_rgba_uint(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
423 util_format_read_4i(enum pipe_format format
,
424 int *dst
, unsigned dst_stride
,
425 const void *src
, unsigned src_stride
,
426 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
428 const struct util_format_description
*format_desc
;
429 const uint8_t *src_row
;
432 format_desc
= util_format_description(format
);
434 assert(x
% format_desc
->block
.width
== 0);
435 assert(y
% format_desc
->block
.height
== 0);
437 src_row
= (const uint8_t *)src
+ y
*src_stride
+ x
*(format_desc
->block
.bits
/8);
440 format_desc
->unpack_rgba_sint(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
444 util_format_write_4i(enum pipe_format format
,
445 const int *src
, unsigned src_stride
,
446 void *dst
, unsigned dst_stride
,
447 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
449 const struct util_format_description
*format_desc
;
451 const int32_t *src_row
;
453 format_desc
= util_format_description(format
);
455 assert(x
% format_desc
->block
.width
== 0);
456 assert(y
% format_desc
->block
.height
== 0);
458 dst_row
= (uint8_t *)dst
+ y
*dst_stride
+ x
*(format_desc
->block
.bits
/8);
461 format_desc
->pack_rgba_sint(dst_row
, dst_stride
, src_row
, src_stride
, w
, h
);
465 * Check if we can safely memcopy from the source format to the dest format.
466 * This basically covers the cases of a "used" channel copied to a typeless
467 * channel, plus some 1-channel cases.
468 * Examples of compatible copy formats include:
469 * b8g8r8a8_unorm -> b8g8r8x8_unorm
470 * a8r8g8b8_unorm -> x8r8g8b8_unorm
471 * b5g5r5a1_unorm -> b5g5r5x1_unorm
472 * b4g4r4a4_unorm -> b4g4r4x4_unorm
473 * l8_unorm -> r8_unorm
474 * i8_unorm -> l8_unorm
475 * i8_unorm -> a8_unorm
476 * i8_unorm -> r8_unorm
477 * l16_unorm -> r16_unorm
478 * z24_unorm_s8_uint -> z24x8_unorm
479 * s8_uint_z24_unorm -> x8z24_unorm
480 * r8g8b8a8_unorm -> r8g8b8x8_unorm
481 * a8b8g8r8_srgb -> x8b8g8r8_srgb
482 * b8g8r8a8_srgb -> b8g8r8x8_srgb
483 * a8r8g8b8_srgb -> x8r8g8b8_srgb
484 * a8b8g8r8_unorm -> x8b8g8r8_unorm
485 * r10g10b10a2_uscaled -> r10g10b10x2_uscaled
486 * r10sg10sb10sa2u_norm -> r10g10b10x2_snorm
489 util_is_format_compatible(const struct util_format_description
*src_desc
,
490 const struct util_format_description
*dst_desc
)
494 if (src_desc
->format
== dst_desc
->format
) {
498 if (src_desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
||
499 dst_desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
503 if (src_desc
->block
.bits
!= dst_desc
->block
.bits
||
504 src_desc
->nr_channels
!= dst_desc
->nr_channels
||
505 src_desc
->colorspace
!= dst_desc
->colorspace
) {
509 for (chan
= 0; chan
< 4; ++chan
) {
510 if (src_desc
->channel
[chan
].size
!=
511 dst_desc
->channel
[chan
].size
) {
516 for (chan
= 0; chan
< 4; ++chan
) {
517 enum pipe_swizzle swizzle
= dst_desc
->swizzle
[chan
];
520 if (src_desc
->swizzle
[chan
] != swizzle
) {
523 if ((src_desc
->channel
[swizzle
].type
!=
524 dst_desc
->channel
[swizzle
].type
) ||
525 (src_desc
->channel
[swizzle
].normalized
!=
526 dst_desc
->channel
[swizzle
].normalized
)) {
537 util_format_fits_8unorm(const struct util_format_description
*format_desc
)
542 * After linearized sRGB values require more than 8bits.
545 if (format_desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) {
549 switch (format_desc
->layout
) {
551 case UTIL_FORMAT_LAYOUT_S3TC
:
553 * These are straight forward.
556 case UTIL_FORMAT_LAYOUT_RGTC
:
557 if (format_desc
->format
== PIPE_FORMAT_RGTC1_SNORM
||
558 format_desc
->format
== PIPE_FORMAT_RGTC2_SNORM
||
559 format_desc
->format
== PIPE_FORMAT_LATC1_SNORM
||
560 format_desc
->format
== PIPE_FORMAT_LATC2_SNORM
)
563 case UTIL_FORMAT_LAYOUT_BPTC
:
564 if (format_desc
->format
== PIPE_FORMAT_BPTC_RGBA_UNORM
)
568 case UTIL_FORMAT_LAYOUT_ETC
:
569 if (format_desc
->format
== PIPE_FORMAT_ETC1_RGB8
)
573 case UTIL_FORMAT_LAYOUT_PLAIN
:
575 * For these we can find a generic rule.
578 for (chan
= 0; chan
< format_desc
->nr_channels
; ++chan
) {
579 switch (format_desc
->channel
[chan
].type
) {
580 case UTIL_FORMAT_TYPE_VOID
:
582 case UTIL_FORMAT_TYPE_UNSIGNED
:
583 if (!format_desc
->channel
[chan
].normalized
||
584 format_desc
->channel
[chan
].size
> 8) {
596 * Handle all others on a case by case basis.
599 switch (format_desc
->format
) {
600 case PIPE_FORMAT_R1_UNORM
:
601 case PIPE_FORMAT_UYVY
:
602 case PIPE_FORMAT_YUYV
:
603 case PIPE_FORMAT_R8G8_B8G8_UNORM
:
604 case PIPE_FORMAT_G8R8_G8B8_UNORM
:
615 util_format_translate(enum pipe_format dst_format
,
616 void *dst
, unsigned dst_stride
,
617 unsigned dst_x
, unsigned dst_y
,
618 enum pipe_format src_format
,
619 const void *src
, unsigned src_stride
,
620 unsigned src_x
, unsigned src_y
,
621 unsigned width
, unsigned height
)
623 const struct util_format_description
*dst_format_desc
;
624 const struct util_format_description
*src_format_desc
;
626 const uint8_t *src_row
;
627 unsigned x_step
, y_step
;
631 dst_format_desc
= util_format_description(dst_format
);
632 src_format_desc
= util_format_description(src_format
);
634 if (util_is_format_compatible(src_format_desc
, dst_format_desc
)) {
639 util_copy_rect(dst
, dst_format
, dst_stride
, dst_x
, dst_y
,
640 width
, height
, src
, (int)src_stride
,
645 assert(dst_x
% dst_format_desc
->block
.width
== 0);
646 assert(dst_y
% dst_format_desc
->block
.height
== 0);
647 assert(src_x
% src_format_desc
->block
.width
== 0);
648 assert(src_y
% src_format_desc
->block
.height
== 0);
650 dst_row
= (uint8_t *)dst
+ dst_y
*dst_stride
+ dst_x
*(dst_format_desc
->block
.bits
/8);
651 src_row
= (const uint8_t *)src
+ src_y
*src_stride
+ src_x
*(src_format_desc
->block
.bits
/8);
654 * This works because all pixel formats have pixel blocks with power of two
658 y_step
= MAX2(dst_format_desc
->block
.height
, src_format_desc
->block
.height
);
659 x_step
= MAX2(dst_format_desc
->block
.width
, src_format_desc
->block
.width
);
660 assert(y_step
% dst_format_desc
->block
.height
== 0);
661 assert(y_step
% src_format_desc
->block
.height
== 0);
663 dst_step
= y_step
/ dst_format_desc
->block
.height
* dst_stride
;
664 src_step
= y_step
/ src_format_desc
->block
.height
* src_stride
;
667 * TODO: double formats will loose precision
668 * TODO: Add a special case for formats that are mere swizzles of each other
671 if (src_format_desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
||
672 dst_format_desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
) {
674 uint8_t *tmp_s
= NULL
;
679 if (src_format_desc
->unpack_z_float
&&
680 dst_format_desc
->pack_z_float
) {
681 tmp_z
= MALLOC(width
* sizeof *tmp_z
);
684 if (src_format_desc
->unpack_s_8uint
&&
685 dst_format_desc
->pack_s_8uint
) {
686 tmp_s
= MALLOC(width
* sizeof *tmp_s
);
691 src_format_desc
->unpack_z_float(tmp_z
, 0, src_row
, src_stride
, width
, 1);
692 dst_format_desc
->pack_z_float(dst_row
, dst_stride
, tmp_z
, 0, width
, 1);
696 src_format_desc
->unpack_s_8uint(tmp_s
, 0, src_row
, src_stride
, width
, 1);
697 dst_format_desc
->pack_s_8uint(dst_row
, dst_stride
, tmp_s
, 0, width
, 1);
711 if (util_format_fits_8unorm(src_format_desc
) ||
712 util_format_fits_8unorm(dst_format_desc
)) {
716 if (!src_format_desc
->unpack_rgba_8unorm
||
717 !dst_format_desc
->pack_rgba_8unorm
) {
721 tmp_stride
= MAX2(width
, x_step
) * 4 * sizeof *tmp_row
;
722 tmp_row
= MALLOC(y_step
* tmp_stride
);
726 while (height
>= y_step
) {
727 src_format_desc
->unpack_rgba_8unorm(tmp_row
, tmp_stride
, src_row
, src_stride
, width
, y_step
);
728 dst_format_desc
->pack_rgba_8unorm(dst_row
, dst_stride
, tmp_row
, tmp_stride
, width
, y_step
);
736 src_format_desc
->unpack_rgba_8unorm(tmp_row
, tmp_stride
, src_row
, src_stride
, width
, height
);
737 dst_format_desc
->pack_rgba_8unorm(dst_row
, dst_stride
, tmp_row
, tmp_stride
, width
, height
);
746 if (!src_format_desc
->unpack_rgba_float
||
747 !dst_format_desc
->pack_rgba_float
) {
751 tmp_stride
= MAX2(width
, x_step
) * 4 * sizeof *tmp_row
;
752 tmp_row
= MALLOC(y_step
* tmp_stride
);
756 while (height
>= y_step
) {
757 src_format_desc
->unpack_rgba_float(tmp_row
, tmp_stride
, src_row
, src_stride
, width
, y_step
);
758 dst_format_desc
->pack_rgba_float(dst_row
, dst_stride
, tmp_row
, tmp_stride
, width
, y_step
);
766 src_format_desc
->unpack_rgba_float(tmp_row
, tmp_stride
, src_row
, src_stride
, width
, height
);
767 dst_format_desc
->pack_rgba_float(dst_row
, dst_stride
, tmp_row
, tmp_stride
, width
, height
);
776 util_format_translate_3d(enum pipe_format dst_format
,
777 void *dst
, unsigned dst_stride
,
778 unsigned dst_slice_stride
,
779 unsigned dst_x
, unsigned dst_y
,
781 enum pipe_format src_format
,
782 const void *src
, unsigned src_stride
,
783 unsigned src_slice_stride
,
784 unsigned src_x
, unsigned src_y
,
785 unsigned src_z
, unsigned width
,
786 unsigned height
, unsigned depth
)
789 const uint8_t *src_layer
;
793 dst_layer
+= dst_z
* dst_slice_stride
;
794 src_layer
+= src_z
* src_slice_stride
;
795 for (z
= 0; z
< depth
; ++z
) {
796 if (!util_format_translate(dst_format
, dst_layer
, dst_stride
,
798 src_format
, src_layer
, src_stride
,
803 dst_layer
+= dst_slice_stride
;
804 src_layer
+= src_slice_stride
;
809 void util_format_compose_swizzles(const unsigned char swz1
[4],
810 const unsigned char swz2
[4],
811 unsigned char dst
[4])
815 for (i
= 0; i
< 4; i
++) {
816 dst
[i
] = swz2
[i
] <= PIPE_SWIZZLE_W
?
817 swz1
[swz2
[i
]] : swz2
[i
];
821 void util_format_apply_color_swizzle(union pipe_color_union
*dst
,
822 const union pipe_color_union
*src
,
823 const unsigned char swz
[4],
824 const boolean is_integer
)
829 for (c
= 0; c
< 4; ++c
) {
831 case PIPE_SWIZZLE_X
: dst
->ui
[c
] = src
->ui
[0]; break;
832 case PIPE_SWIZZLE_Y
: dst
->ui
[c
] = src
->ui
[1]; break;
833 case PIPE_SWIZZLE_Z
: dst
->ui
[c
] = src
->ui
[2]; break;
834 case PIPE_SWIZZLE_W
: dst
->ui
[c
] = src
->ui
[3]; break;
836 dst
->ui
[c
] = (swz
[c
] == PIPE_SWIZZLE_1
) ? 1 : 0;
841 for (c
= 0; c
< 4; ++c
) {
843 case PIPE_SWIZZLE_X
: dst
->f
[c
] = src
->f
[0]; break;
844 case PIPE_SWIZZLE_Y
: dst
->f
[c
] = src
->f
[1]; break;
845 case PIPE_SWIZZLE_Z
: dst
->f
[c
] = src
->f
[2]; break;
846 case PIPE_SWIZZLE_W
: dst
->f
[c
] = src
->f
[3]; break;
848 dst
->f
[c
] = (swz
[c
] == PIPE_SWIZZLE_1
) ? 1.0f
: 0.0f
;
855 void pipe_swizzle_4f(float *dst
, const float *src
,
856 const unsigned char swz
[4])
860 for (i
= 0; i
< 4; i
++) {
861 if (swz
[i
] <= PIPE_SWIZZLE_W
)
862 dst
[i
] = src
[swz
[i
]];
863 else if (swz
[i
] == PIPE_SWIZZLE_0
)
865 else if (swz
[i
] == PIPE_SWIZZLE_1
)
870 void util_format_unswizzle_4f(float *dst
, const float *src
,
871 const unsigned char swz
[4])
875 for (i
= 0; i
< 4; i
++) {